diff --git a/packages/jest-worker/README.md b/packages/jest-worker/README.md index efc91bb9a7cb..8e979388d5c2 100644 --- a/packages/jest-worker/README.md +++ b/packages/jest-worker/README.md @@ -43,8 +43,6 @@ export function hello(param) { Node 10 shipped with [worker-threads](https://nodejs.org/api/worker_threads.html), a "threading API" that uses SharedArrayBuffers to communicate between the main process and its child threads. This experimental Node feature can significantly improve the communication time between parent and child processes in `jest-worker`. -Since `worker_threads` are considered experimental in Node, you have to opt-in to this behavior by passing `enableWorkerThreads: true` when instantiating the worker. While the feature was unflagged in Node 11.7.0, you'll need to run the Node process with the `--experimental-worker` flag for Node 10. - ## API The only exposed method is a constructor (`JestWorker`) that is initialized by passing the worker path, plus an options object. @@ -89,10 +87,6 @@ Provide a custom worker pool to be used for spawning child processes. By default The arguments that will be passed to the `setup` method during initialization. -#### `enableWorkerThreads: boolean` (optional) - -`jest-worker` will automatically detect if `worker_threads` are available, but will not use them unless passed `enableWorkerThreads: true`. - ## JestWorker ### Methods diff --git a/packages/jest-worker/src/WorkerPool.ts b/packages/jest-worker/src/WorkerPool.ts index dc3039652cfe..abb091b58d79 100644 --- a/packages/jest-worker/src/WorkerPool.ts +++ b/packages/jest-worker/src/WorkerPool.ts @@ -39,7 +39,7 @@ class WorkerPool extends BaseWorkerPool implements WorkerPoolInterface { createWorker(workerOptions: WorkerOptions): WorkerInterface { let Worker; - if (this._options.enableWorkerThreads && canUseWorkerThreads()) { + if (canUseWorkerThreads()) { Worker = require('./workers/NodeThreadsWorker').default; } else { Worker = require('./workers/ChildProcessWorker').default; diff --git a/packages/jest-worker/src/__tests__/WorkerPool.test.js b/packages/jest-worker/src/__tests__/WorkerPool.test.js index 7c2cbcedbfa1..6d2fc25df1f7 100644 --- a/packages/jest-worker/src/__tests__/WorkerPool.test.js +++ b/packages/jest-worker/src/__tests__/WorkerPool.test.js @@ -78,7 +78,6 @@ describe('WorkerPool', () => { it('should create a NodeThreadWorker and send to it', () => { jest.mock('worker_threads', () => 'Defined'); const workerPool = new WorkerPool('/path', { - enableWorkerThreads: true, forkOptions: {}, maxRetries: 1, numWorkers: 1, @@ -104,33 +103,4 @@ describe('WorkerPool', () => { undefined, ); }); - - it('should avoid NodeThreadWorker if not passed enableWorkerThreads', () => { - jest.mock('worker_threads', () => 'Defined'); - const workerPool = new WorkerPool('/path', { - forkOptions: {}, - maxRetries: 1, - numWorkers: 1, - workerId: 0, - workerPath: '/path', - }); - - const onStart = () => {}; - const onEnd = () => {}; - workerPool.send(0, {foo: 'bar'}, onStart, onEnd); - - expect(ChildProcessWorker).toBeCalledWith({ - forkOptions: {}, - maxRetries: 1, - workerId: 0, - workerPath: '/path', - }); - expect(NodeThreadWorker).not.toBeCalled(); - expect(workerPool._workers[0].send).toBeCalledWith( - {foo: 'bar'}, - onStart, - onEnd, - undefined, - ); - }); }); diff --git a/packages/jest-worker/src/__tests__/thread-integration.test.js b/packages/jest-worker/src/__tests__/thread-integration.test.js index 30f8d6241d04..078568604462 100644 --- a/packages/jest-worker/src/__tests__/thread-integration.test.js +++ b/packages/jest-worker/src/__tests__/thread-integration.test.js @@ -66,7 +66,6 @@ describe('Jest Worker Process Integration', () => { it('calls a single method from the worker', async () => { const farm = new Farm('/tmp/baz.js', { - enableWorkerThreads: true, exposedMethods: ['foo', 'bar'], numWorkers: 4, }); @@ -80,7 +79,6 @@ describe('Jest Worker Process Integration', () => { it('distributes sequential calls across child processes', async () => { const farm = new Farm('/tmp/baz.js', { - enableWorkerThreads: true, exposedMethods: ['foo', 'bar'], numWorkers: 4, }); @@ -102,7 +100,6 @@ describe('Jest Worker Process Integration', () => { it('distributes concurrent calls across child processes', async () => { const farm = new Farm('/tmp/baz.js', { - enableWorkerThreads: true, exposedMethods: ['foo', 'bar'], numWorkers: 4, }); @@ -131,7 +128,6 @@ describe('Jest Worker Process Integration', () => { it('sticks parallel calls to children', async () => { const farm = new Farm('/tmp/baz.js', { computeWorkerKey: () => '1234567890abcdef', - enableWorkerThreads: true, exposedMethods: ['foo', 'bar'], numWorkers: 4, }); diff --git a/packages/jest-worker/src/index.ts b/packages/jest-worker/src/index.ts index f9f9b3bccd8a..ad062bc04c5b 100644 --- a/packages/jest-worker/src/index.ts +++ b/packages/jest-worker/src/index.ts @@ -76,7 +76,6 @@ export default class JestWorker { this._ending = false; const workerPoolOptions: WorkerPoolOptions = { - enableWorkerThreads: this._options.enableWorkerThreads ?? false, forkOptions: this._options.forkOptions ?? {}, maxRetries: this._options.maxRetries ?? 3, numWorkers: this._options.numWorkers ?? Math.max(cpus().length - 1, 1), diff --git a/packages/jest-worker/src/types.ts b/packages/jest-worker/src/types.ts index af59e7fd87ef..5094e76db2a5 100644 --- a/packages/jest-worker/src/types.ts +++ b/packages/jest-worker/src/types.ts @@ -87,7 +87,6 @@ export type FarmOptions = { workerPath: string, options?: WorkerPoolOptions, ) => WorkerPoolInterface; - enableWorkerThreads?: boolean; }; export type WorkerPoolOptions = { @@ -96,7 +95,6 @@ export type WorkerPoolOptions = { resourceLimits: ResourceLimits; maxRetries: number; numWorkers: number; - enableWorkerThreads: boolean; }; export type WorkerOptions = {