Skip to content

Commit

Permalink
fix(workers): use advanced serialization by default in child process …
Browse files Browse the repository at this point in the history
…workers
  • Loading branch information
SimenB committed Apr 20, 2022
1 parent d4b36be commit a391a0b
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
- `[jest-test-result]` Add duration property to JSON test output ([#12518](https://github.com/facebook/jest/pull/12518))
- `[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))
- `[jest-worker]` [**BREAKING**] Allow only absolute `workerPath` ([#12343](https://github.com/facebook/jest/pull/12343))
- `[jest-worker]` [**BREAKING**] Default to advanced serialization when using child process workers ([#10983] (https://github.com/facebook/jest/pull/10983))
- `[pretty-format]` New `maxWidth` parameter ([#12402](https://github.com/facebook/jest/pull/12402))

### Fixes
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-runner/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ export default class TestRunner extends EmittingTestRunner {

const worker = new Worker(TEST_WORKER_PATH, {
exposedMethods: ['worker'],
forkOptions: {stdio: 'pipe'},
// @ts-expect-error: option does not exist on the node 12 types
forkOptions: {serialization: 'json', stdio: 'pipe'},
maxRetries: 3,
numWorkers: this._globalConfig.maxWorkers,
setupArgs: [{serializableResolvers: Array.from(resolvers.values())}],
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-worker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ List of method names that can be called on the child processes from the parent p

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

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).
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).

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

Expand Down
3 changes: 3 additions & 0 deletions packages/jest-worker/src/workers/ChildProcessWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ export default class ChildProcessWorker implements WorkerInterface {
},
// Suppress --debug / --inspect flags while preserving others (like --harmony).
execArgv: process.execArgv.filter(v => !/^--(debug|inspect)/.test(v)),
// default to advanced serialization in order to match worker threads
// @ts-expect-error: option does not exist on the node 12 types
serialization: 'advanced',
silent: true,
...this._options.forkOptions,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ it('passes fork options down to child_process.fork, adding the defaults', () =>
env: {...process.env, FORCE_COLOR: supportsColor.stdout ? '1' : undefined}, // Default option.
execArgv: ['-p'], // Filtered option.
execPath: 'hello', // Added option.
serialization: 'advanced', // Default option.
silent: true, // Default option.
});
});
Expand Down

0 comments on commit a391a0b

Please sign in to comment.