diff --git a/CHANGELOG.md b/CHANGELOG.md index b7ef82ef73a3..daca187f6948 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/jest-runner/src/index.ts b/packages/jest-runner/src/index.ts index 88785a096342..36154110bb29 100644 --- a/packages/jest-runner/src/index.ts +++ b/packages/jest-runner/src/index.ts @@ -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: [ diff --git a/packages/jest-worker/README.md b/packages/jest-worker/README.md index debdb3518e21..a75e21abcc4f 100644 --- a/packages/jest-worker/README.md +++ b/packages/jest-worker/README.md @@ -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) diff --git a/packages/jest-worker/src/workers/ChildProcessWorker.ts b/packages/jest-worker/src/workers/ChildProcessWorker.ts index 52d0d42d1d87..02069ef45460 100644 --- a/packages/jest-worker/src/workers/ChildProcessWorker.ts +++ b/packages/jest-worker/src/workers/ChildProcessWorker.ts @@ -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, }); diff --git a/packages/jest-worker/src/workers/__tests__/ChildProcessWorker.test.js b/packages/jest-worker/src/workers/__tests__/ChildProcessWorker.test.js index e5e7e1e99694..1caa8e654380 100644 --- a/packages/jest-worker/src/workers/__tests__/ChildProcessWorker.test.js +++ b/packages/jest-worker/src/workers/__tests__/ChildProcessWorker.test.js @@ -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. }); });