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 (#10983)
  • Loading branch information
SimenB committed Apr 20, 2022
1 parent 0e41755 commit 5e570b9
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
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
2 changes: 2 additions & 0 deletions packages/jest-haste-map/src/index.ts
Expand Up @@ -747,6 +747,8 @@ export default class HasteMap extends EventEmitter {
// @ts-expect-error: assignment of a worker with custom properties.
this._worker = new Worker(require.resolve('./worker'), {
exposedMethods: ['getSha1', 'worker'],
// @ts-expect-error: option does not exist on the node 12 types
forkOptions: {serialization: 'json'},
maxRetries: 3,
numWorkers: this._options.maxWorkers,
}) as WorkerInterface;
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-reporters/src/CoverageReporter.ts
Expand Up @@ -144,6 +144,8 @@ export default class CoverageReporter extends BaseReporter {
} else {
worker = new Worker(require.resolve('./CoverageWorker'), {
exposedMethods: ['worker'],
// @ts-expect-error: option does not exist on the node 12 types
forkOptions: {serialization: 'json'},
maxRetries: 2,
numWorkers: this._globalConfig.maxWorkers,
});
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-runner/src/index.ts
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
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
2 changes: 2 additions & 0 deletions packages/jest-worker/src/__tests__/leak-integration.test.ts
Expand Up @@ -53,6 +53,8 @@ describe('Worker leaks', () => {
worker = new Worker(workerFile, {
enableWorkerThreads: false,
exposedMethods: ['fn'],
// @ts-expect-error: option does not exist on the node 12 types
forkOptions: {serialization: 'json'},
});
});
afterEach(async () => {
Expand Down
3 changes: 3 additions & 0 deletions packages/jest-worker/src/workers/ChildProcessWorker.ts
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
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 5e570b9

Please sign in to comment.