Skip to content

Commit 14d675c

Browse files
committed
remove enableWorkerThreads
1 parent 7a6dedc commit 14d675c

File tree

6 files changed

+1
-43
lines changed

6 files changed

+1
-43
lines changed

packages/jest-worker/README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ export function hello(param) {
4343

4444
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`.
4545

46-
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.
47-
4846
## API
4947

5048
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
8987

9088
The arguments that will be passed to the `setup` method during initialization.
9189

92-
#### `enableWorkerThreads: boolean` (optional)
93-
94-
`jest-worker` will automatically detect if `worker_threads` are available, but will not use them unless passed `enableWorkerThreads: true`.
95-
9690
## Worker
9791

9892
The returned `Worker` instance has all the exposed methods, plus some additional ones to interact with the workers itself:

packages/jest-worker/src/WorkerPool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class WorkerPool extends BaseWorkerPool implements WorkerPoolInterface {
3737

3838
createWorker(workerOptions: WorkerOptions): WorkerInterface {
3939
let Worker;
40-
if (this._options.enableWorkerThreads && canUseWorkerThreads()) {
40+
if (canUseWorkerThreads()) {
4141
Worker = require('./workers/NodeThreadsWorker').default;
4242
} else {
4343
Worker = require('./workers/ChildProcessWorker').default;

packages/jest-worker/src/__tests__/WorkerPool.test.js

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ describe('WorkerPool', () => {
7777
it('should create a NodeThreadWorker and send to it', () => {
7878
jest.mock('worker_threads', () => 'Defined');
7979
const workerPool = new WorkerPool('/path', {
80-
enableWorkerThreads: true,
8180
forkOptions: {},
8281
maxRetries: 1,
8382
numWorkers: 1,
@@ -102,32 +101,4 @@ describe('WorkerPool', () => {
102101
onEnd,
103102
);
104103
});
105-
106-
it('should avoid NodeThreadWorker if not passed enableWorkerThreads', () => {
107-
jest.mock('worker_threads', () => 'Defined');
108-
const workerPool = new WorkerPool('/path', {
109-
forkOptions: {},
110-
maxRetries: 1,
111-
numWorkers: 1,
112-
workerId: 0,
113-
workerPath: '/path',
114-
});
115-
116-
const onStart = () => {};
117-
const onEnd = () => {};
118-
workerPool.send(0, {foo: 'bar'}, onStart, onEnd);
119-
120-
expect(ChildProcessWorker).toBeCalledWith({
121-
forkOptions: {},
122-
maxRetries: 1,
123-
workerId: 0,
124-
workerPath: '/path',
125-
});
126-
expect(NodeThreadWorker).not.toBeCalled();
127-
expect(workerPool._workers[0].send).toBeCalledWith(
128-
{foo: 'bar'},
129-
onStart,
130-
onEnd,
131-
);
132-
});
133104
});

packages/jest-worker/src/__tests__/thread-integration.test.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ describe('Jest Worker Process Integration', () => {
6666

6767
it('calls a single method from the worker', async () => {
6868
const farm = new Farm('/tmp/baz.js', {
69-
enableWorkerThreads: true,
7069
exposedMethods: ['foo', 'bar'],
7170
numWorkers: 4,
7271
});
@@ -80,7 +79,6 @@ describe('Jest Worker Process Integration', () => {
8079

8180
it('distributes sequential calls across child processes', async () => {
8281
const farm = new Farm('/tmp/baz.js', {
83-
enableWorkerThreads: true,
8482
exposedMethods: ['foo', 'bar'],
8583
numWorkers: 4,
8684
});
@@ -102,7 +100,6 @@ describe('Jest Worker Process Integration', () => {
102100

103101
it('distributes concurrent calls across child processes', async () => {
104102
const farm = new Farm('/tmp/baz.js', {
105-
enableWorkerThreads: true,
106103
exposedMethods: ['foo', 'bar'],
107104
numWorkers: 4,
108105
});
@@ -131,7 +128,6 @@ describe('Jest Worker Process Integration', () => {
131128
it('sticks parallel calls to children', async () => {
132129
const farm = new Farm('/tmp/baz.js', {
133130
computeWorkerKey: () => '1234567890abcdef',
134-
enableWorkerThreads: true,
135131
exposedMethods: ['foo', 'bar'],
136132
numWorkers: 4,
137133
});

packages/jest-worker/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ export default class JestWorker {
7474
this._ending = false;
7575

7676
const workerPoolOptions: WorkerPoolOptions = {
77-
enableWorkerThreads: this._options.enableWorkerThreads || false,
7877
forkOptions: this._options.forkOptions || {},
7978
maxRetries: this._options.maxRetries || 3,
8079
numWorkers: this._options.numWorkers || Math.max(cpus().length - 1, 1),

packages/jest-worker/src/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,13 @@ export type FarmOptions = {
7171
workerPath: string,
7272
options?: WorkerPoolOptions,
7373
) => WorkerPoolInterface;
74-
enableWorkerThreads?: boolean;
7574
};
7675

7776
export type WorkerPoolOptions = {
7877
setupArgs: Array<unknown>;
7978
forkOptions: ForkOptions;
8079
maxRetries: number;
8180
numWorkers: number;
82-
enableWorkerThreads: boolean;
8381
};
8482

8583
export type WorkerOptions = {

0 commit comments

Comments
 (0)