开玩笑的测试随机失败

时间:2020-01-21 19:03:50

标签: typescript jestjs ts-jest

我有一个有趣的配置,例如:

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'
            ]
        }
    ]
};

sub_directory / 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"
  ]
}

现在,当我并行运行笑话测试时(默认情况下会进行测试), 我仅在Project 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的测试

-project1project2一个接一个地运行(以任何顺序)
一切正常。

为什么会这样?

0 个答案:

没有答案