Skip to content

Commit 5e570b9

Browse files
authored
fix(workers): use advanced serialization by default in child process workers (#10983)
1 parent 0e41755 commit 5e570b9

8 files changed

Lines changed: 14 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-haste-map/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,8 @@ export default class HasteMap extends EventEmitter {
747747
// @ts-expect-error: assignment of a worker with custom properties.
748748
this._worker = new Worker(require.resolve('./worker'), {
749749
exposedMethods: ['getSha1', 'worker'],
750+
// @ts-expect-error: option does not exist on the node 12 types
751+
forkOptions: {serialization: 'json'},
750752
maxRetries: 3,
751753
numWorkers: this._options.maxWorkers,
752754
}) as WorkerInterface;

packages/jest-reporters/src/CoverageReporter.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ export default class CoverageReporter extends BaseReporter {
144144
} else {
145145
worker = new Worker(require.resolve('./CoverageWorker'), {
146146
exposedMethods: ['worker'],
147+
// @ts-expect-error: option does not exist on the node 12 types
148+
forkOptions: {serialization: 'json'},
147149
maxRetries: 2,
148150
numWorkers: this._globalConfig.maxWorkers,
149151
});

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/__tests__/leak-integration.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ describe('Worker leaks', () => {
5353
worker = new Worker(workerFile, {
5454
enableWorkerThreads: false,
5555
exposedMethods: ['fn'],
56+
// @ts-expect-error: option does not exist on the node 12 types
57+
forkOptions: {serialization: 'json'},
5658
});
5759
});
5860
afterEach(async () => {

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)