Jest тесты проваливаются случайно - PullRequest
0 голосов
/ 21 января 2020

У меня есть jest config, например:

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

Теперь, когда я запускаю 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 запускаются один за другим (в любом порядке)
все работает нормально.

Почему это происходит?

...