Skip to content

Commit a391a0b

Browse files
committed
fix(workers): use advanced serialization by default in child process workers
1 parent d4b36be commit a391a0b

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
@@ -57,6 +57,7 @@
5757
- `[jest-test-result]` Add duration property to JSON test output ([#12518](https://github.com/facebook/jest/pull/12518))
5858
- `[jest-watcher]` [**BREAKING**] Make `PatternPrompt` class to take `entityName` as third constructor parameter instead of `this._entityName` ([#12591](https://github.com/facebook/jest/pull/12591))
5959
- `[jest-worker]` [**BREAKING**] Allow only absolute `workerPath` ([#12343](https://github.com/facebook/jest/pull/12343))
60+
- `[jest-worker]` [**BREAKING**] Default to advanced serialization when using child process workers ([#10983] (https://github.com/facebook/jest/pull/10983))
6061
- `[pretty-format]` New `maxWidth` parameter ([#12402](https://github.com/facebook/jest/pull/12402))
6162

6263
### Fixes

packages/jest-runner/src/index.ts

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

106106
const worker = new Worker(TEST_WORKER_PATH, {
107107
exposedMethods: ['worker'],
108-
forkOptions: {stdio: 'pipe'},
108+
// @ts-expect-error: option does not exist on the node 12 types
109+
forkOptions: {serialization: 'json', stdio: 'pipe'},
109110
maxRetries: 3,
110111
numWorkers: this._globalConfig.maxWorkers,
111112
setupArgs: [{serializableResolvers: Array.from(resolvers.values())}],

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)