Skip to content

Commit 56825d8

Browse files
committed
remove enableWorkerThreads
1 parent d49089c commit 56825d8

File tree

5 files changed

+8
-10
lines changed

5 files changed

+8
-10
lines changed

packages/jest-worker/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function hello(param) {
4343

4444
Node 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 feature can significantly improve the communication time between parent and child processes in `jest-worker`.
4545

46-
To use `worker_threads` instead of default `child_process` you have to pass `enableWorkerThreads: true` when instantiating the worker.
46+
To disable the default `worker_threads` and instead use `child_process` you have to pass `enableWorkerThreads: false` when instantiating the worker.
4747

4848
## API
4949

packages/jest-worker/src/WorkerPool.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import type {
1515
WorkerOptions,
1616
WorkerPoolInterface,
1717
} from './types';
18+
import ChildProcessWorker from './workers/ChildProcessWorker';
19+
import NodeThreadsWorker from './workers/NodeThreadsWorker';
1820

1921
class WorkerPool extends BaseWorkerPool implements WorkerPoolInterface {
2022
send(
@@ -30,9 +32,9 @@ class WorkerPool extends BaseWorkerPool implements WorkerPoolInterface {
3032
override createWorker(workerOptions: WorkerOptions): WorkerInterface {
3133
let Worker;
3234
if (this._options.enableWorkerThreads) {
33-
Worker = require('./workers/NodeThreadsWorker').default;
35+
Worker = NodeThreadsWorker;
3436
} else {
35-
Worker = require('./workers/ChildProcessWorker').default;
37+
Worker = ChildProcessWorker;
3638
}
3739

3840
return new Worker(workerOptions);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ describe('WorkerPool', () => {
7878
it('should create a NodeThreadWorker and send to it', () => {
7979
jest.mock('worker_threads', () => 'Defined');
8080
const workerPool = new WorkerPool('/path', {
81-
enableWorkerThreads: true,
8281
forkOptions: {},
8382
maxRetries: 1,
8483
numWorkers: 1,
@@ -107,9 +106,10 @@ describe('WorkerPool', () => {
107106
);
108107
});
109108

110-
it('should avoid NodeThreadWorker if not passed enableWorkerThreads', () => {
109+
it('should use ChildProcessWorker if passed enableWorkerThreads: false', () => {
111110
jest.mock('worker_threads', () => 'Defined');
112111
const workerPool = new WorkerPool('/path', {
112+
enableWorkerThreads: false,
113113
forkOptions: {},
114114
maxRetries: 1,
115115
numWorkers: 1,

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

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

6868
it('calls a single method from the worker', async () => {
6969
const farm = new WorkerFarm('/tmp/baz.js', {
70-
enableWorkerThreads: true,
7170
exposedMethods: ['foo', 'bar'],
7271
numWorkers: 4,
7372
}) as JestWorkerFarm<{foo(): void}>;
@@ -81,7 +80,6 @@ describe('Jest Worker Process Integration', () => {
8180

8281
it('distributes sequential calls across child processes', async () => {
8382
const farm = new WorkerFarm('/tmp/baz.js', {
84-
enableWorkerThreads: true,
8583
exposedMethods: ['foo', 'bar'],
8684
numWorkers: 4,
8785
}) as JestWorkerFarm<{foo(a: unknown): void}>;
@@ -152,7 +150,6 @@ describe('Jest Worker Process Integration', () => {
152150

153151
it('distributes concurrent calls across child processes', async () => {
154152
const farm = new WorkerFarm('/tmp/baz.js', {
155-
enableWorkerThreads: true,
156153
exposedMethods: ['foo', 'bar'],
157154
numWorkers: 4,
158155
}) as JestWorkerFarm<{foo(a: unknown): void}>;
@@ -181,7 +178,6 @@ describe('Jest Worker Process Integration', () => {
181178
it('sticks parallel calls to children', async () => {
182179
const farm = new WorkerFarm('/tmp/baz.js', {
183180
computeWorkerKey: () => '1234567890abcdef',
184-
enableWorkerThreads: true,
185181
exposedMethods: ['foo', 'bar'],
186182
numWorkers: 4,
187183
}) as JestWorkerFarm<{foo(a: unknown): void}>;

packages/jest-worker/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class Worker {
104104
}
105105

106106
const workerPoolOptions: WorkerPoolOptions = {
107-
enableWorkerThreads: this._options.enableWorkerThreads ?? false,
107+
enableWorkerThreads: this._options.enableWorkerThreads ?? true,
108108
forkOptions: this._options.forkOptions ?? {},
109109
idleMemoryLimit: this._options.idleMemoryLimit,
110110
maxRetries: this._options.maxRetries ?? 3,

0 commit comments

Comments
 (0)