I'm using jest (^28.1.3
) for running unit and e2e ts on backend (Apollo Server, TypeORM and PostgreSQL). There aren't problems to run unit tests (one file, two or all), but I have a problem with e2e testing.
On local machine
- If I run one file with e2e tests (e.g.
regression.e2e-spec.ts
), I'll get an error. - If I run two files (e.g.
regression.e2e-spec.ts
+someUnit.test.ts
, orregression.e2e-spec.ts
+otherE2ETest.e2e-spec.ts
), I won't get any error, testing will finished successful.
On GitHub Actions
- I get same error in any cases (run one, two or all files)
May jest execute tests in main process/thread when it finds only one file? And split execution on several process when find several files? The problem might be in an isolation, with one file environment isn't clean.
Files are filtered in jest.config.js, write file name in testMatch.
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
roots: ['<rootDir>/src'],
testEnvironment: 'node',
testMatch: ['**/src/**/*.(test|e2e-spec).ts'], // keep in sync with src/__test__/setup/E2ERegExp.ts
globalSetup: './src/__test__/setup/globalSetup.ts',
globalTeardown: './src/__test__/setup/globalTeardown.js',
setupFilesAfterEnv: ['./src/__test__/setup/setup.ts'],
transform: {
'^.+\\.ts': 'ts-jest',
},
};
In globalSetup
and globalTeardown
I setup and drop databases. In setup.ts
run server and connect to db.
Tests are executed in parallel.
"docker:test": "RUN_DB=true NODE_OPTIONS=--max-old-space-size=4096 jest --colors --maxWorkers=50%",
