0

我有一个开玩笑的配置,例如:

module.exports = {
    "projects": [
        {
            name: "project1",
            displayName: "Project 1",
            bail: false,
            clearMocks: false,
            collectCoverage: false,
            .................
        },
        {
            name: "project2",
            displayName: "Project 2",
            preset: 'ts-jest',
            testEnvironment: 'node',
            globals: {
                'ts-jest': {
                    tsConfig: 'sub_directory/tsconfig.jest.json'
                }
            },
            testMatch: ["<rootDir>/sub_directory/**/?(*.)spec.ts"],
            transform: { '^.+\\.ts?$':'ts-jest' },
            moduleFileExtensions: ['ts', 'js'],
            collectCoverageFrom: [
                'lib/**/*.ts',
                'public/**/*.ts',
                'index.ts'
            ]
        }
    ]
};

子目录/tsconfig.jest.json :

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "inlineSourceMap": true,
    "typeRoots": [
      "../types/ts/static",
      "../node_modules/@types",
      "../node_modules/jest-jasmine2/build"
    ],
    "types": [
      "node", "lodash", "gen", "jest", "jest-jasmine2"
    ]
  },
  "include": [
    "**/*.ts",
    "**/*.js",
    "**/*.test.ts"
  ],
  "exclude": [
    "node_modules", "build", "coverage"
  ]
}

现在,当我并行运行 jest 测试时(默认情况下),我只在项目 2 个测试文件中遇到故障。故障总是相同的,但发生故障的文件是随机的。

Summary of all failing tests
 FAIL  sub_directory/some_path1/a.spec.ts
  ● Test suite failed to run

    Cannot find module './testPathPatternToRegExp' from 'index.js'

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:259:17)

 FAIL  sub_directory/some_path2/b.spec.ts
  ● Test suite failed to run

    Cannot find module './testPathPatternToRegExp' from 'index.js'

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:259:17)

 FAIL  sub_directory/some_path3/c.spec.ts
  ● Test suite failed to run

    Cannot find module './testPathPatternToRegExp' from 'index.js'

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:259:17)

相关的软件包版本是:

 "@types/jest": "24.0.18",
....
 "jest": "24.8.0",
 "jest-junit": "5.1.0",
....
 "ts-jest": "24.1.0",

中的测试project1永远不会失败。
此外,当
- 仅project2运行测试

-project1并且project2一个接一个地运行(以任何顺序)时,
一切正常。

为什么会发生这种情况?

4

0 回答 0