diff --git a/packages/jest-worker/README.md b/packages/jest-worker/README.md index e6ca3a798d10..6d86ae619309 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 (`Worker`) 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`. - ## Worker The returned `Worker` instance has all the exposed methods, plus some additional ones to interact with the workers itself: diff --git a/packages/jest-worker/src/WorkerPool.js b/packages/jest-worker/src/WorkerPool.js index 0c6828288653..9827c0ff85d7 100644 --- a/packages/jest-worker/src/WorkerPool.js +++ b/packages/jest-worker/src/WorkerPool.js @@ -42,7 +42,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 a5bafa91f0f0..71ec4dc29fd9 100644 --- a/packages/jest-worker/src/__tests__/WorkerPool.test.js +++ b/packages/jest-worker/src/__tests__/WorkerPool.test.js @@ -77,7 +77,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, @@ -102,32 +101,4 @@ describe('WorkerPool', () => { onEnd, ); }); - - 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, - ); - }); }); 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.js b/packages/jest-worker/src/index.js index dcd2c633164f..0b3c4a40b59b 100644 --- a/packages/jest-worker/src/index.js +++ b/packages/jest-worker/src/index.js @@ -77,7 +77,6 @@ export default class JestWorker { this._options = {...options}; const workerPoolOptions: WorkerPoolOptions = { - enableWorkerThreads: this._options.enableWorkerThreads || false, forkOptions: this._options.forkOptions || {}, maxRetries: this._options.maxRetries || 3, numWorkers: this._options.numWorkers || Math.max(os.cpus().length - 1, 1), diff --git a/packages/jest-worker/src/types.js b/packages/jest-worker/src/types.js index bb12434eca1a..b0a80f325c77 100644 --- a/packages/jest-worker/src/types.js +++ b/packages/jest-worker/src/types.js @@ -70,7 +70,6 @@ export type FarmOptions = { workerPath: string, options?: WorkerPoolOptions, ) => WorkerPoolInterface, - enableWorkerThreads?: boolean, }; export type WorkerPoolOptions = {| @@ -78,7 +77,6 @@ export type WorkerPoolOptions = {| forkOptions: ForkOptions, maxRetries: number, numWorkers: number, - enableWorkerThreads: boolean, |}; export type WorkerOptions = {|