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 Feb 24, 2022
1 parent af387f0 commit d0594fe
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 @@ -32,6 +32,7 @@
- `[jest-runtime]` [**BREAKING**] `Runtime.createHasteMap` now returns a promise ([#12008](https://github.com/facebook/jest/pull/12008))
- `[@jest/schemas]` New module for JSON schemas for Jest's config ([#12384](https://github.com/facebook/jest/pull/12384))
- `[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 @@ -165,7 +165,8 @@ export default class TestRunner {

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: [
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 d0594fe

Please sign in to comment.