Skip to content

Commit 1afe39f

Browse files
committed
fix(workers): use advanced serialization by default in child process workers
1 parent 15feaca commit 1afe39f

5 files changed

Lines changed: 8 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
- `[jest-runtime]` [**BREAKING**] `Runtime.createHasteMap` now returns a promise ([#12008](https://github.com/facebook/jest/pull/12008))
3333
- `[@jest/schemas]` New module for JSON schemas for Jest's config ([#12384](https://github.com/facebook/jest/pull/12384))
3434
- `[jest-worker]` [**BREAKING**] Allow only absolute `workerPath` ([#12343](https://github.com/facebook/jest/pull/12343))
35+
- `[jest-worker]` [**BREAKING**] Default to advanced serialization when using child process workers ([#10983] (https://github.com/facebook/jest/pull/10983))
3536
- `[pretty-format]` New `maxWidth` parameter ([#12402](https://github.com/facebook/jest/pull/12402))
3637

3738
### Fixes

packages/jest-runner/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ export default class TestRunner {
165165

166166
const worker = new Worker(TEST_WORKER_PATH, {
167167
exposedMethods: ['worker'],
168-
forkOptions: {stdio: 'pipe'},
168+
// @ts-expect-error: option does not exist on the node 12 types
169+
forkOptions: {serialization: 'json', stdio: 'pipe'},
169170
maxRetries: 3,
170171
numWorkers: this._globalConfig.maxWorkers,
171172
setupArgs: [

packages/jest-worker/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ List of method names that can be called on the child processes from the parent p
7373

7474
#### `forkOptions: ForkOptions` (optional)
7575

76-
Allow customizing all options passed to `child_process.fork`. By default, some values are set (`cwd`, `env` and `execArgv`), but you can override them and customize the rest. For a list of valid values, check [the Node documentation](https://nodejs.org/api/child_process.html#child_processforkmodulepath-args-options).
76+
Allow customizing all options passed to `child_process.fork`. By default, some values are set (`cwd`, `env`, `execArgv` and `serialization`), but you can override them and customize the rest. For a list of valid values, check [the Node documentation](https://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options).
7777

7878
#### `maxRetries: number` (optional)
7979

packages/jest-worker/src/workers/ChildProcessWorker.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ export default class ChildProcessWorker implements WorkerInterface {
9292
},
9393
// Suppress --debug / --inspect flags while preserving others (like --harmony).
9494
execArgv: process.execArgv.filter(v => !/^--(debug|inspect)/.test(v)),
95+
// default to advanced serialization in order to match worker threads
96+
// @ts-expect-error: option does not exist on the node 12 types
97+
serialization: 'advanced',
9598
silent: true,
9699
...this._options.forkOptions,
97100
});

packages/jest-worker/src/workers/__tests__/ChildProcessWorker.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ it('passes fork options down to child_process.fork, adding the defaults', () =>
7070
env: {...process.env, FORCE_COLOR: supportsColor.stdout ? '1' : undefined}, // Default option.
7171
execArgv: ['-p'], // Filtered option.
7272
execPath: 'hello', // Added option.
73+
serialization: 'advanced', // Default option.
7374
silent: true, // Default option.
7475
});
7576
});

0 commit comments

Comments
 (0)