Skip to content

Commit

Permalink
Merge branch 'main' into fix/issue-14308
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Aug 17, 2023
2 parents 7367d65 + a5cdc86 commit b5e0252
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@

- `[expect, @jest/expect-utils]` `ObjectContaining` support `sumbol` as key ([#14414](https://github.com/jestjs/jest/pull/14414))
- `[expect]` Remove `@types/node` from dependencies ([#14385](https://github.com/jestjs/jest/pull/14385))
- `[jest-core]` Use workers in watch mode by default to avoid crashes ([#14059](https://github.com/facebook/jest/pull/14059) & [#14085](https://github.com/facebook/jest/pull/14085)).
- `[jest-reporters]` Update `istanbul-lib-instrument` dependency to v6. ([#14401](https://github.com/jestjs/jest/pull/14401))

### Chore & Maintenance
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/src/index.ts
Expand Up @@ -121,6 +121,7 @@ const groupOptions = (
replname: options.replname,
reporters: options.reporters,
rootDir: options.rootDir,
runInBand: options.runInBand,
runTestsByPath: options.runTestsByPath,
seed: options.seed,
shard: options.shard,
Expand Down
41 changes: 22 additions & 19 deletions packages/jest-core/src/__tests__/testSchedulerHelper.test.js
Expand Up @@ -23,32 +23,34 @@ const getTestMock = () => ({
const getTestsMock = () => [getTestMock(), getTestMock()];

test.each`
tests | timings | detectOpenHandles | maxWorkers | watch | workerIdleMemoryLimit | expectedResult
${[getTestMock()]} | ${[500, 500]} | ${false} | ${undefined} | ${true} | ${undefined} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${false} | ${1} | ${true} | ${undefined} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${false} | ${2} | ${true} | ${undefined} | ${false}
${[getTestMock()]} | ${[2000, 500]} | ${false} | ${undefined} | ${true} | ${undefined} | ${false}
${getTestMock()} | ${[500, 500]} | ${false} | ${undefined} | ${true} | ${undefined} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${false} | ${1} | ${false} | ${undefined} | ${true}
${getTestMock()} | ${[2000, 500]} | ${false} | ${2} | ${false} | ${undefined} | ${false}
${[getTestMock()]} | ${[2000]} | ${false} | ${undefined} | ${false} | ${undefined} | ${true}
${getTestsMock()} | ${[500, 500]} | ${false} | ${undefined} | ${false} | ${undefined} | ${true}
${new Array(45)} | ${[500]} | ${false} | ${undefined} | ${false} | ${undefined} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${false} | ${undefined} | ${false} | ${undefined} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${true} | ${undefined} | ${false} | ${undefined} | ${true}
${[getTestMock()]} | ${[500, 500]} | ${false} | ${undefined} | ${true} | ${'500MB'} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${false} | ${1} | ${true} | ${'500MB'} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${false} | ${1} | ${false} | ${'500MB'} | ${false}
${[getTestMock()]} | ${[2000]} | ${false} | ${undefined} | ${false} | ${'500MB'} | ${false}
${getTestsMock()} | ${[500, 500]} | ${false} | ${undefined} | ${false} | ${'500MB'} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${true} | ${undefined} | ${false} | ${'500MB'} | ${true}
tests | timings | detectOpenHandles | runInBand | maxWorkers | watch | workerIdleMemoryLimit | expectedResult
${[getTestMock()]} | ${[500, 500]} | ${false} | ${false} | ${undefined} | ${true} | ${undefined} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${false} | ${false} | ${1} | ${true} | ${undefined} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${false} | ${false} | ${2} | ${true} | ${undefined} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${false} | ${true} | ${1} | ${true} | ${undefined} | ${true}
${[getTestMock()]} | ${[2000, 500]} | ${false} | ${false} | ${undefined} | ${true} | ${undefined} | ${false}
${getTestMock()} | ${[500, 500]} | ${false} | ${false} | ${undefined} | ${true} | ${undefined} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${false} | ${false} | ${1} | ${false} | ${undefined} | ${true}
${getTestMock()} | ${[2000, 500]} | ${false} | ${false} | ${2} | ${false} | ${undefined} | ${false}
${[getTestMock()]} | ${[2000]} | ${false} | ${false} | ${undefined} | ${false} | ${undefined} | ${true}
${getTestsMock()} | ${[500, 500]} | ${false} | ${false} | ${undefined} | ${false} | ${undefined} | ${true}
${new Array(45)} | ${[500]} | ${false} | ${false} | ${undefined} | ${false} | ${undefined} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${false} | ${false} | ${undefined} | ${false} | ${undefined} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${true} | ${false} | ${undefined} | ${false} | ${undefined} | ${true}
${[getTestMock()]} | ${[500, 500]} | ${false} | ${false} | ${undefined} | ${true} | ${'500MB'} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${false} | ${false} | ${1} | ${true} | ${'500MB'} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${false} | ${false} | ${1} | ${false} | ${'500MB'} | ${false}
${[getTestMock()]} | ${[2000]} | ${false} | ${false} | ${undefined} | ${false} | ${'500MB'} | ${false}
${getTestsMock()} | ${[500, 500]} | ${false} | ${false} | ${undefined} | ${false} | ${'500MB'} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${true} | ${false} | ${undefined} | ${false} | ${'500MB'} | ${true}
`(
'shouldRunInBand() - should return $expectedResult for runInBand mode',
({
tests,
timings,
detectOpenHandles,
maxWorkers,
runInBand,
watch,
workerIdleMemoryLimit,
expectedResult,
Expand All @@ -57,6 +59,7 @@ test.each`
shouldRunInBand(tests, timings, {
detectOpenHandles,
maxWorkers,
runInBand,
watch,
workerIdleMemoryLimit,
}),
Expand Down
Expand Up @@ -101,6 +101,7 @@ exports[`prints the config object 1`] = `
"projects": [],
"reporters": [],
"rootDir": "/test_root_dir/",
"runInBand": false,
"runTestsByPath": false,
"seed": 1234,
"silent": false,
Expand Down
7 changes: 3 additions & 4 deletions packages/jest-core/src/testSchedulerHelper.ts
Expand Up @@ -16,13 +16,15 @@ export function shouldRunInBand(
{
detectOpenHandles,
maxWorkers,
runInBand,
watch,
watchAll,
workerIdleMemoryLimit,
}: Config.GlobalConfig,
): boolean {
// If user asked for run in band, respect that.
// detectOpenHandles makes no sense without runInBand, because it cannot detect leaks in workers
if (detectOpenHandles) {
if (runInBand || detectOpenHandles) {
return true;
}

Expand All @@ -39,9 +41,6 @@ export function shouldRunInBand(
* Otherwise, run in band if we only have one test or one worker available.
* Also, if we are confident from previous runs that the tests will finish
* quickly we also run in band to reduce the overhead of spawning workers.
* Finally, the user can provide the runInBand argument in the CLI to
* force running in band, which sets maxWorkers to 1 here:
* https://github.com/jestjs/jest/blob/d106643a8ee0ffa9c2f11c6bb2d12094e99135aa/packages/jest-config/src/getMaxWorkers.ts#L27-L28
*/
const areFastTests = timings.every(timing => timing < SLOW_TEST_TIME);
const oneWorkerOrLess = maxWorkers <= 1;
Expand Down
1 change: 1 addition & 0 deletions packages/jest-types/src/Config.ts
Expand Up @@ -400,6 +400,7 @@ export type GlobalConfig = {
randomize?: boolean;
replname?: string;
reporters?: Array<ReporterConfig>;
runInBand: boolean;
runTestsByPath: boolean;
rootDir: string;
seed: number;
Expand Down
1 change: 1 addition & 0 deletions packages/test-utils/src/config.ts
Expand Up @@ -47,6 +47,7 @@ const DEFAULT_GLOBAL_CONFIG: Config.GlobalConfig = {
replname: undefined,
reporters: [],
rootDir: '/test_root_dir/',
runInBand: false,
runTestsByPath: false,
seed: 1234,
silent: false,
Expand Down
2 changes: 1 addition & 1 deletion website/package.json
Expand Up @@ -37,7 +37,7 @@
"@docusaurus/plugin-pwa": "^2.0.0",
"@docusaurus/preset-classic": "^2.0.0",
"@docusaurus/remark-plugin-npm2yarn": "^2.0.0",
"clsx": "^1.1.1",
"clsx": "^2.0.0",
"docusaurus-remark-plugin-tab-blocks": "^1.2.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
Expand Down
11 changes: 9 additions & 2 deletions yarn.lock
Expand Up @@ -7399,13 +7399,20 @@ __metadata:
languageName: node
linkType: hard

"clsx@npm:^1.1.1, clsx@npm:^1.2.1":
"clsx@npm:^1.2.1":
version: 1.2.1
resolution: "clsx@npm:1.2.1"
checksum: 30befca8019b2eb7dbad38cff6266cf543091dae2825c856a62a8ccf2c3ab9c2907c4d12b288b73101196767f66812365400a227581484a05f968b0307cfaf12
languageName: node
linkType: hard

"clsx@npm:^2.0.0":
version: 2.0.0
resolution: "clsx@npm:2.0.0"
checksum: a2cfb2351b254611acf92faa0daf15220f4cd648bdf96ce369d729813b85336993871a4bf6978ddea2b81b5a130478339c20d9d0b5c6fc287e5147f0c059276e
languageName: node
linkType: hard

"cmd-shim@npm:^6.0.0":
version: 6.0.1
resolution: "cmd-shim@npm:6.0.1"
Expand Down Expand Up @@ -12982,7 +12989,7 @@ __metadata:
"@docusaurus/remark-plugin-npm2yarn": ^2.0.0
"@tsconfig/docusaurus": ^1.0.5
"@types/react": ^17.0.3
clsx: ^1.1.1
clsx: ^2.0.0
docusaurus-remark-plugin-tab-blocks: ^1.2.0
graphql: ^16.3.0
graphql-request: ^6.0.0
Expand Down

0 comments on commit b5e0252

Please sign in to comment.