diff --git a/jest.config.ci.mjs b/jest.config.ci.mjs index 3d33ffaec912..70e074e50a29 100644 --- a/jest.config.ci.mjs +++ b/jest.config.ci.mjs @@ -17,10 +17,7 @@ export default { 'jest-junit', {outputDirectory: 'reports/junit', outputName: 'js-test-results.xml'}, ], - [ - 'jest-silent-reporter', - {showPaths: true, showWarnings: true, useDots: true}, - ], + 'default', 'summary', ], }; diff --git a/packages/jest-worker/README.md b/packages/jest-worker/README.md index f796d27889b5..d74ae3cbb72a 100644 --- a/packages/jest-worker/README.md +++ b/packages/jest-worker/README.md @@ -43,7 +43,7 @@ export function hello(param) { 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`. -To use `worker_threads` instead of default `child_process` you have to pass `enableWorkerThreads: true` when instantiating the worker. +To disable the default `worker_threads` and instead use `child_process` you have to pass `enableWorkerThreads: false` when instantiating the worker. ## API diff --git a/packages/jest-worker/src/WorkerPool.ts b/packages/jest-worker/src/WorkerPool.ts index 4ac1da31c7a1..2037af89095e 100644 --- a/packages/jest-worker/src/WorkerPool.ts +++ b/packages/jest-worker/src/WorkerPool.ts @@ -15,6 +15,8 @@ import type { WorkerOptions, WorkerPoolInterface, } from './types'; +import ChildProcessWorker from './workers/ChildProcessWorker'; +import NodeThreadsWorker from './workers/NodeThreadsWorker'; class WorkerPool extends BaseWorkerPool implements WorkerPoolInterface { send( @@ -30,9 +32,9 @@ class WorkerPool extends BaseWorkerPool implements WorkerPoolInterface { override createWorker(workerOptions: WorkerOptions): WorkerInterface { let Worker; if (this._options.enableWorkerThreads) { - Worker = require('./workers/NodeThreadsWorker').default; + Worker = NodeThreadsWorker; } else { - Worker = require('./workers/ChildProcessWorker').default; + Worker = ChildProcessWorker; } return new Worker(workerOptions); diff --git a/packages/jest-worker/src/__tests__/WorkerPool.test.ts b/packages/jest-worker/src/__tests__/WorkerPool.test.ts index 72bf9334442f..c1fff8086835 100644 --- a/packages/jest-worker/src/__tests__/WorkerPool.test.ts +++ b/packages/jest-worker/src/__tests__/WorkerPool.test.ts @@ -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, @@ -107,9 +106,10 @@ describe('WorkerPool', () => { ); }); - it('should avoid NodeThreadWorker if not passed enableWorkerThreads', () => { + it('should use ChildProcessWorker if passed enableWorkerThreads: false', () => { jest.mock('worker_threads', () => 'Defined'); const workerPool = new WorkerPool('/path', { + enableWorkerThreads: false, forkOptions: {}, maxRetries: 1, numWorkers: 1, diff --git a/packages/jest-worker/src/__tests__/thread-integration.test.ts b/packages/jest-worker/src/__tests__/thread-integration.test.ts index bfffc2d3c96c..09918c3380a6 100644 --- a/packages/jest-worker/src/__tests__/thread-integration.test.ts +++ b/packages/jest-worker/src/__tests__/thread-integration.test.ts @@ -67,7 +67,6 @@ describe('Jest Worker Process Integration', () => { it('calls a single method from the worker', async () => { const farm = new WorkerFarm('/tmp/baz.js', { - enableWorkerThreads: true, exposedMethods: ['foo', 'bar'], numWorkers: 4, }) as JestWorkerFarm<{foo(): void}>; @@ -81,7 +80,6 @@ describe('Jest Worker Process Integration', () => { it('distributes sequential calls across child processes', async () => { const farm = new WorkerFarm('/tmp/baz.js', { - enableWorkerThreads: true, exposedMethods: ['foo', 'bar'], numWorkers: 4, }) as JestWorkerFarm<{foo(a: unknown): void}>; @@ -152,7 +150,6 @@ describe('Jest Worker Process Integration', () => { it('distributes concurrent calls across child processes', async () => { const farm = new WorkerFarm('/tmp/baz.js', { - enableWorkerThreads: true, exposedMethods: ['foo', 'bar'], numWorkers: 4, }) as JestWorkerFarm<{foo(a: unknown): void}>; @@ -181,7 +178,6 @@ describe('Jest Worker Process Integration', () => { it('sticks parallel calls to children', async () => { const farm = new WorkerFarm('/tmp/baz.js', { computeWorkerKey: () => '1234567890abcdef', - enableWorkerThreads: true, exposedMethods: ['foo', 'bar'], numWorkers: 4, }) as JestWorkerFarm<{foo(a: unknown): void}>; diff --git a/packages/jest-worker/src/index.ts b/packages/jest-worker/src/index.ts index c5f5b46bf524..0bb5c0e7f953 100644 --- a/packages/jest-worker/src/index.ts +++ b/packages/jest-worker/src/index.ts @@ -104,7 +104,7 @@ export class Worker { } const workerPoolOptions: WorkerPoolOptions = { - enableWorkerThreads: this._options.enableWorkerThreads ?? false, + enableWorkerThreads: this._options.enableWorkerThreads ?? true, forkOptions: this._options.forkOptions ?? {}, idleMemoryLimit: this._options.idleMemoryLimit, maxRetries: this._options.maxRetries ?? 3,