Skip to content

Commit b5e0252

Browse files
authored
Merge branch 'main' into fix/issue-14308
2 parents 7367d65 + a5cdc86 commit b5e0252

File tree

9 files changed

+40
-26
lines changed

9 files changed

+40
-26
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- `[expect, @jest/expect-utils]` `ObjectContaining` support `sumbol` as key ([#14414](https://github.com/jestjs/jest/pull/14414))
88
- `[expect]` Remove `@types/node` from dependencies ([#14385](https://github.com/jestjs/jest/pull/14385))
9+
- `[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)).
910
- `[jest-reporters]` Update `istanbul-lib-instrument` dependency to v6. ([#14401](https://github.com/jestjs/jest/pull/14401))
1011

1112
### Chore & Maintenance

packages/jest-config/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ const groupOptions = (
121121
replname: options.replname,
122122
reporters: options.reporters,
123123
rootDir: options.rootDir,
124+
runInBand: options.runInBand,
124125
runTestsByPath: options.runTestsByPath,
125126
seed: options.seed,
126127
shard: options.shard,

packages/jest-core/src/__tests__/testSchedulerHelper.test.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,34 @@ const getTestMock = () => ({
2323
const getTestsMock = () => [getTestMock(), getTestMock()];
2424

2525
test.each`
26-
tests | timings | detectOpenHandles | maxWorkers | watch | workerIdleMemoryLimit | expectedResult
27-
${[getTestMock()]} | ${[500, 500]} | ${false} | ${undefined} | ${true} | ${undefined} | ${false}
28-
${getTestsMock()} | ${[2000, 500]} | ${false} | ${1} | ${true} | ${undefined} | ${false}
29-
${getTestsMock()} | ${[2000, 500]} | ${false} | ${2} | ${true} | ${undefined} | ${false}
30-
${[getTestMock()]} | ${[2000, 500]} | ${false} | ${undefined} | ${true} | ${undefined} | ${false}
31-
${getTestMock()} | ${[500, 500]} | ${false} | ${undefined} | ${true} | ${undefined} | ${false}
32-
${getTestsMock()} | ${[2000, 500]} | ${false} | ${1} | ${false} | ${undefined} | ${true}
33-
${getTestMock()} | ${[2000, 500]} | ${false} | ${2} | ${false} | ${undefined} | ${false}
34-
${[getTestMock()]} | ${[2000]} | ${false} | ${undefined} | ${false} | ${undefined} | ${true}
35-
${getTestsMock()} | ${[500, 500]} | ${false} | ${undefined} | ${false} | ${undefined} | ${true}
36-
${new Array(45)} | ${[500]} | ${false} | ${undefined} | ${false} | ${undefined} | ${false}
37-
${getTestsMock()} | ${[2000, 500]} | ${false} | ${undefined} | ${false} | ${undefined} | ${false}
38-
${getTestsMock()} | ${[2000, 500]} | ${true} | ${undefined} | ${false} | ${undefined} | ${true}
39-
${[getTestMock()]} | ${[500, 500]} | ${false} | ${undefined} | ${true} | ${'500MB'} | ${false}
40-
${getTestsMock()} | ${[2000, 500]} | ${false} | ${1} | ${true} | ${'500MB'} | ${false}
41-
${getTestsMock()} | ${[2000, 500]} | ${false} | ${1} | ${false} | ${'500MB'} | ${false}
42-
${[getTestMock()]} | ${[2000]} | ${false} | ${undefined} | ${false} | ${'500MB'} | ${false}
43-
${getTestsMock()} | ${[500, 500]} | ${false} | ${undefined} | ${false} | ${'500MB'} | ${false}
44-
${getTestsMock()} | ${[2000, 500]} | ${true} | ${undefined} | ${false} | ${'500MB'} | ${true}
26+
tests | timings | detectOpenHandles | runInBand | maxWorkers | watch | workerIdleMemoryLimit | expectedResult
27+
${[getTestMock()]} | ${[500, 500]} | ${false} | ${false} | ${undefined} | ${true} | ${undefined} | ${false}
28+
${getTestsMock()} | ${[2000, 500]} | ${false} | ${false} | ${1} | ${true} | ${undefined} | ${false}
29+
${getTestsMock()} | ${[2000, 500]} | ${false} | ${false} | ${2} | ${true} | ${undefined} | ${false}
30+
${getTestsMock()} | ${[2000, 500]} | ${false} | ${true} | ${1} | ${true} | ${undefined} | ${true}
31+
${[getTestMock()]} | ${[2000, 500]} | ${false} | ${false} | ${undefined} | ${true} | ${undefined} | ${false}
32+
${getTestMock()} | ${[500, 500]} | ${false} | ${false} | ${undefined} | ${true} | ${undefined} | ${false}
33+
${getTestsMock()} | ${[2000, 500]} | ${false} | ${false} | ${1} | ${false} | ${undefined} | ${true}
34+
${getTestMock()} | ${[2000, 500]} | ${false} | ${false} | ${2} | ${false} | ${undefined} | ${false}
35+
${[getTestMock()]} | ${[2000]} | ${false} | ${false} | ${undefined} | ${false} | ${undefined} | ${true}
36+
${getTestsMock()} | ${[500, 500]} | ${false} | ${false} | ${undefined} | ${false} | ${undefined} | ${true}
37+
${new Array(45)} | ${[500]} | ${false} | ${false} | ${undefined} | ${false} | ${undefined} | ${false}
38+
${getTestsMock()} | ${[2000, 500]} | ${false} | ${false} | ${undefined} | ${false} | ${undefined} | ${false}
39+
${getTestsMock()} | ${[2000, 500]} | ${true} | ${false} | ${undefined} | ${false} | ${undefined} | ${true}
40+
${[getTestMock()]} | ${[500, 500]} | ${false} | ${false} | ${undefined} | ${true} | ${'500MB'} | ${false}
41+
${getTestsMock()} | ${[2000, 500]} | ${false} | ${false} | ${1} | ${true} | ${'500MB'} | ${false}
42+
${getTestsMock()} | ${[2000, 500]} | ${false} | ${false} | ${1} | ${false} | ${'500MB'} | ${false}
43+
${[getTestMock()]} | ${[2000]} | ${false} | ${false} | ${undefined} | ${false} | ${'500MB'} | ${false}
44+
${getTestsMock()} | ${[500, 500]} | ${false} | ${false} | ${undefined} | ${false} | ${'500MB'} | ${false}
45+
${getTestsMock()} | ${[2000, 500]} | ${true} | ${false} | ${undefined} | ${false} | ${'500MB'} | ${true}
4546
`(
4647
'shouldRunInBand() - should return $expectedResult for runInBand mode',
4748
({
4849
tests,
4950
timings,
5051
detectOpenHandles,
5152
maxWorkers,
53+
runInBand,
5254
watch,
5355
workerIdleMemoryLimit,
5456
expectedResult,
@@ -57,6 +59,7 @@ test.each`
5759
shouldRunInBand(tests, timings, {
5860
detectOpenHandles,
5961
maxWorkers,
62+
runInBand,
6063
watch,
6164
workerIdleMemoryLimit,
6265
}),

packages/jest-core/src/lib/__tests__/__snapshots__/logDebugMessages.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ exports[`prints the config object 1`] = `
101101
"projects": [],
102102
"reporters": [],
103103
"rootDir": "/test_root_dir/",
104+
"runInBand": false,
104105
"runTestsByPath": false,
105106
"seed": 1234,
106107
"silent": false,

packages/jest-core/src/testSchedulerHelper.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ export function shouldRunInBand(
1616
{
1717
detectOpenHandles,
1818
maxWorkers,
19+
runInBand,
1920
watch,
2021
watchAll,
2122
workerIdleMemoryLimit,
2223
}: Config.GlobalConfig,
2324
): boolean {
25+
// If user asked for run in band, respect that.
2426
// detectOpenHandles makes no sense without runInBand, because it cannot detect leaks in workers
25-
if (detectOpenHandles) {
27+
if (runInBand || detectOpenHandles) {
2628
return true;
2729
}
2830

@@ -39,9 +41,6 @@ export function shouldRunInBand(
3941
* Otherwise, run in band if we only have one test or one worker available.
4042
* Also, if we are confident from previous runs that the tests will finish
4143
* quickly we also run in band to reduce the overhead of spawning workers.
42-
* Finally, the user can provide the runInBand argument in the CLI to
43-
* force running in band, which sets maxWorkers to 1 here:
44-
* https://github.com/jestjs/jest/blob/d106643a8ee0ffa9c2f11c6bb2d12094e99135aa/packages/jest-config/src/getMaxWorkers.ts#L27-L28
4544
*/
4645
const areFastTests = timings.every(timing => timing < SLOW_TEST_TIME);
4746
const oneWorkerOrLess = maxWorkers <= 1;

packages/jest-types/src/Config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ export type GlobalConfig = {
400400
randomize?: boolean;
401401
replname?: string;
402402
reporters?: Array<ReporterConfig>;
403+
runInBand: boolean;
403404
runTestsByPath: boolean;
404405
rootDir: string;
405406
seed: number;

packages/test-utils/src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const DEFAULT_GLOBAL_CONFIG: Config.GlobalConfig = {
4747
replname: undefined,
4848
reporters: [],
4949
rootDir: '/test_root_dir/',
50+
runInBand: false,
5051
runTestsByPath: false,
5152
seed: 1234,
5253
silent: false,

website/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"@docusaurus/plugin-pwa": "^2.0.0",
3838
"@docusaurus/preset-classic": "^2.0.0",
3939
"@docusaurus/remark-plugin-npm2yarn": "^2.0.0",
40-
"clsx": "^1.1.1",
40+
"clsx": "^2.0.0",
4141
"docusaurus-remark-plugin-tab-blocks": "^1.2.0",
4242
"react": "^17.0.2",
4343
"react-dom": "^17.0.2",

yarn.lock

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7399,13 +7399,20 @@ __metadata:
73997399
languageName: node
74007400
linkType: hard
74017401

7402-
"clsx@npm:^1.1.1, clsx@npm:^1.2.1":
7402+
"clsx@npm:^1.2.1":
74037403
version: 1.2.1
74047404
resolution: "clsx@npm:1.2.1"
74057405
checksum: 30befca8019b2eb7dbad38cff6266cf543091dae2825c856a62a8ccf2c3ab9c2907c4d12b288b73101196767f66812365400a227581484a05f968b0307cfaf12
74067406
languageName: node
74077407
linkType: hard
74087408

7409+
"clsx@npm:^2.0.0":
7410+
version: 2.0.0
7411+
resolution: "clsx@npm:2.0.0"
7412+
checksum: a2cfb2351b254611acf92faa0daf15220f4cd648bdf96ce369d729813b85336993871a4bf6978ddea2b81b5a130478339c20d9d0b5c6fc287e5147f0c059276e
7413+
languageName: node
7414+
linkType: hard
7415+
74097416
"cmd-shim@npm:^6.0.0":
74107417
version: 6.0.1
74117418
resolution: "cmd-shim@npm:6.0.1"
@@ -12982,7 +12989,7 @@ __metadata:
1298212989
"@docusaurus/remark-plugin-npm2yarn": ^2.0.0
1298312990
"@tsconfig/docusaurus": ^1.0.5
1298412991
"@types/react": ^17.0.3
12985-
clsx: ^1.1.1
12992+
clsx: ^2.0.0
1298612993
docusaurus-remark-plugin-tab-blocks: ^1.2.0
1298712994
graphql: ^16.3.0
1298812995
graphql-request: ^6.0.0

0 commit comments

Comments
 (0)