Socket
Socket
Sign inDemoInstall

jest-worker

Package Overview
Dependencies
Maintainers
6
Versions
171
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-worker - npm Package Compare versions

Comparing version 25.0.0 to 25.1.0

4

build/base/BaseWorkerPool.d.ts

@@ -8,3 +8,3 @@ /**

/// <reference types="node" />
import { WorkerInterface, WorkerOptions, WorkerPoolOptions } from '../types';
import { PoolExitResult, WorkerInterface, WorkerOptions, WorkerPoolOptions } from '../types';
export default class BaseWorkerPool {

@@ -21,4 +21,4 @@ private readonly _stderr;

createWorker(_workerOptions: WorkerOptions): WorkerInterface;
end(): void;
end(): Promise<PoolExitResult>;
}
//# sourceMappingURL=BaseWorkerPool.d.ts.map

@@ -28,4 +28,12 @@ 'use strict';

var _types = require('../types');
function _types() {
const data = require('../types');
_types = function() {
return data;
};
return data;
}
function _interopRequireDefault(obj) {

@@ -35,25 +43,42 @@ return obj && obj.__esModule ? obj : {default: obj};

function _getRequireWildcardCache() {
if (typeof WeakMap !== 'function') return null;
var cache = new WeakMap();
_getRequireWildcardCache = function() {
return cache;
};
return cache;
}
function _interopRequireWildcard(obj) {
if (obj && obj.__esModule) {
return obj;
} else {
var newObj = {};
if (obj != null) {
for (var key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
var desc =
Object.defineProperty && Object.getOwnPropertyDescriptor
? Object.getOwnPropertyDescriptor(obj, key)
: {};
if (desc.get || desc.set) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
}
if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) {
return {default: obj};
}
var cache = _getRequireWildcardCache();
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {};
var hasPropertyDescriptor =
Object.defineProperty && Object.getOwnPropertyDescriptor;
for (var key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor
? Object.getOwnPropertyDescriptor(obj, key)
: null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
newObj.default = obj;
return newObj;
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}

@@ -75,3 +100,7 @@

// How long to wait for the child process to terminate
// after CHILD_MESSAGE_END before sending force exiting.
const FORCE_EXIT_DELAY = 500;
/* istanbul ignore next */
const emptyMethod = () => {};

@@ -147,12 +176,33 @@

end() {
async end() {
// We do not cache the request object here. If so, it would only be only
// processed by one of the workers, and we want them all to close.
for (let i = 0; i < this._workers.length; i++) {
this._workers[i].send(
[_types.CHILD_MESSAGE_END, false],
const workerExitPromises = this._workers.map(async worker => {
worker.send(
[_types().CHILD_MESSAGE_END, false],
emptyMethod,
emptyMethod
);
}
); // Schedule a force exit in case worker fails to exit gracefully so
// await worker.waitForExit() never takes longer than FORCE_EXIT_DELAY
let forceExited = false;
const forceExitTimeout = setTimeout(() => {
worker.forceExit();
forceExited = true;
}, FORCE_EXIT_DELAY);
await worker.waitForExit(); // Worker ideally exited gracefully, don't send force exit then
clearTimeout(forceExitTimeout);
return forceExited;
});
const workerExits = await Promise.all(workerExitPromises);
return workerExits.reduce(
(result, forceExited) => ({
forceExited: result.forceExited || forceExited
}),
{
forceExited: false
}
);
}

@@ -159,0 +209,0 @@ }

@@ -8,3 +8,3 @@ /**

/// <reference types="node" />
import { FarmOptions } from './types';
import { FarmOptions, PoolExitResult } from './types';
/**

@@ -45,4 +45,4 @@ * The Jest farm (publicly called "Worker") is a class that allows you to queue

getStdout(): NodeJS.ReadableStream;
end(): void;
end(): Promise<PoolExitResult>;
}
//# sourceMappingURL=index.d.ts.map

@@ -43,3 +43,3 @@ 'use strict';

if (i % 2) {
ownKeys(source, true).forEach(function(key) {
ownKeys(Object(source), true).forEach(function(key) {
_defineProperty(target, key, source[key]);

@@ -50,3 +50,3 @@ });

} else {
ownKeys(source).forEach(function(key) {
ownKeys(Object(source)).forEach(function(key) {
Object.defineProperty(

@@ -191,3 +191,3 @@ target,

end() {
async end() {
if (this._ending) {

@@ -197,5 +197,4 @@ throw new Error('Farm is ended, no more calls can be done to it');

this._workerPool.end();
this._ending = true;
return this._workerPool.end();
}

@@ -202,0 +201,0 @@ }

@@ -17,3 +17,2 @@ /**

export declare type PARENT_MESSAGE_ERROR = typeof PARENT_MESSAGE_CLIENT_ERROR | typeof PARENT_MESSAGE_SETUP_ERROR;
export { ForkOptions };
export interface WorkerPoolInterface {

@@ -25,12 +24,16 @@ getStderr(): NodeJS.ReadableStream;

send(workerId: number, request: ChildMessage, onStart: OnStart, onEnd: OnEnd): void;
end(): void;
end(): Promise<PoolExitResult>;
}
export interface WorkerInterface {
send(request: ChildMessage, onProcessStart: OnStart, onProcessEnd: OnEnd): void;
waitForExit(): Promise<void>;
forceExit(): void;
getWorkerId(): number;
getStderr(): NodeJS.ReadableStream | null;
getStdout(): NodeJS.ReadableStream | null;
onExit(exitCode: number): void;
onMessage(message: ParentMessage): void;
}
export declare type PoolExitResult = {
forceExited: boolean;
};
export { ForkOptions };
export declare type FarmOptions = {

@@ -37,0 +40,0 @@ computeWorkerKey?: (method: string, ...args: Array<unknown>) => string | null;

@@ -8,3 +8,3 @@ /**

/// <reference types="node" />
import { ChildMessage, OnEnd, OnStart, ParentMessage, WorkerInterface, WorkerOptions } from '../types';
import { ChildMessage, OnEnd, OnStart, WorkerInterface, WorkerOptions } from '../types';
/**

@@ -31,14 +31,18 @@ * This class wraps the child process and provides a nice interface to

private _options;
private _request;
private _retries;
private _onProcessEnd;
private _fakeStream;
private _request;
private _retries;
private _stdout;
private _stderr;
private _stdout;
private _exitPromise;
private _resolveExitPromise;
constructor(options: WorkerOptions);
initialize(): void;
private _shutdown;
onMessage(response: ParentMessage): void;
onExit(exitCode: number): void;
private _onMessage;
private _onExit;
send(request: ChildMessage, onProcessStart: OnStart, onProcessEnd: OnEnd): void;
waitForExit(): Promise<void>;
forceExit(): void;
getWorkerId(): number;

@@ -45,0 +49,0 @@ getStdout(): NodeJS.ReadableStream | null;

@@ -48,4 +48,12 @@ 'use strict';

var _types = require('../types');
function _types() {
const data = require('../types');
_types = function() {
return data;
};
return data;
}
function _interopRequireDefault(obj) {

@@ -72,3 +80,3 @@ return obj && obj.__esModule ? obj : {default: obj};

if (i % 2) {
ownKeys(source, true).forEach(function(key) {
ownKeys(Object(source), true).forEach(function(key) {
_defineProperty(target, key, source[key]);

@@ -79,3 +87,3 @@ });

} else {
ownKeys(source).forEach(function(key) {
ownKeys(Object(source)).forEach(function(key) {
Object.defineProperty(

@@ -106,2 +114,7 @@ target,

const SIGNAL_BASE_EXIT_CODE = 128;
const SIGKILL_EXIT_CODE = SIGNAL_BASE_EXIT_CODE + 9;
const SIGTERM_EXIT_CODE = SIGNAL_BASE_EXIT_CODE + 15; // How long to wait after SIGTERM before sending SIGKILL
const SIGKILL_DELAY = 500;
/**

@@ -125,2 +138,3 @@ * This class wraps the child process and provides a nice interface to

*/
class ChildProcessWorker {

@@ -132,2 +146,6 @@ constructor(options) {

_defineProperty(this, '_request', void 0);
_defineProperty(this, '_retries', void 0);
_defineProperty(this, '_onProcessEnd', void 0);

@@ -137,15 +155,18 @@

_defineProperty(this, '_request', void 0);
_defineProperty(this, '_stdout', void 0);
_defineProperty(this, '_retries', void 0);
_defineProperty(this, '_stderr', void 0);
_defineProperty(this, '_stdout', void 0);
_defineProperty(this, '_exitPromise', void 0);
_defineProperty(this, '_resolveExitPromise', void 0);
this._options = options;
this._request = null;
this._fakeStream = null;
this._request = null;
this._stdout = null;
this._stderr = null;
this._stdout = null;
this._exitPromise = new Promise(resolve => {
this._resolveExitPromise = resolve;
});
this.initialize();

@@ -202,6 +223,6 @@ }

child.on('message', this.onMessage.bind(this));
child.on('exit', this.onExit.bind(this));
child.on('message', this._onMessage.bind(this));
child.on('exit', this._onExit.bind(this));
child.send([
_types.CHILD_MESSAGE_INITIALIZE,
_types().CHILD_MESSAGE_INITIALIZE,
false,

@@ -218,4 +239,5 @@ this._options.workerPath,

const error = new Error('Call retries were exceeded');
this.onMessage([
_types.PARENT_MESSAGE_CLIENT_ERROR,
this._onMessage([
_types().PARENT_MESSAGE_CLIENT_ERROR,
error.name,

@@ -238,9 +260,11 @@ error.message,

}
this._resolveExitPromise();
}
onMessage(response) {
_onMessage(response) {
let error;
switch (response[0]) {
case _types.PARENT_MESSAGE_OK:
case _types().PARENT_MESSAGE_OK:
this._onProcessEnd(null, response[1]);

@@ -250,3 +274,3 @@

case _types.PARENT_MESSAGE_CLIENT_ERROR:
case _types().PARENT_MESSAGE_CLIENT_ERROR:
error = response[4];

@@ -273,3 +297,3 @@

case _types.PARENT_MESSAGE_SETUP_ERROR:
case _types().PARENT_MESSAGE_SETUP_ERROR:
error = new Error('Error when calling setup: ' + response[2]); // @ts-ignore: adding custom properties to errors.

@@ -289,4 +313,8 @@

onExit(exitCode) {
if (exitCode !== 0) {
_onExit(exitCode) {
if (
exitCode !== 0 &&
exitCode !== SIGTERM_EXIT_CODE &&
exitCode !== SIGKILL_EXIT_CODE
) {
this.initialize();

@@ -318,2 +346,17 @@

waitForExit() {
return this._exitPromise;
}
forceExit() {
this._child.kill('SIGTERM');
const sigkillTimeout = setTimeout(
() => this._child.kill('SIGKILL'),
SIGKILL_DELAY
);
this._exitPromise.then(() => clearTimeout(sigkillTimeout));
}
getWorkerId() {

@@ -333,3 +376,3 @@ return this._options.workerId;

if (!this._fakeStream) {
this._fakeStream = new (_stream()).PassThrough();
this._fakeStream = new (_stream().PassThrough)();
}

@@ -336,0 +379,0 @@

@@ -8,17 +8,22 @@ /**

/// <reference types="node" />
import { ChildMessage, OnEnd, OnStart, ParentMessage, WorkerInterface, WorkerOptions } from '../types';
import { ChildMessage, OnEnd, OnStart, WorkerInterface, WorkerOptions } from '../types';
export default class ExperimentalWorker implements WorkerInterface {
private _worker;
private _options;
private _onProcessEnd;
private _request;
private _retries;
private _onProcessEnd;
private _fakeStream;
private _stdout;
private _stderr;
private _stdout;
private _fakeStream;
private _exitPromise;
private _resolveExitPromise;
private _forceExited;
constructor(options: WorkerOptions);
initialize(): void;
private _shutdown;
onMessage(response: ParentMessage): void;
onExit(exitCode: number): void;
private _onMessage;
private _onExit;
waitForExit(): Promise<void>;
forceExit(): void;
send(request: ChildMessage, onProcessStart: OnStart, onProcessEnd: OnEnd): void;

@@ -25,0 +30,0 @@ getWorkerId(): number;

@@ -48,4 +48,12 @@ 'use strict';

var _types = require('../types');
function _types() {
const data = require('../types');
_types = function() {
return data;
};
return data;
}
function _interopRequireDefault(obj) {

@@ -55,25 +63,42 @@ return obj && obj.__esModule ? obj : {default: obj};

function _getRequireWildcardCache() {
if (typeof WeakMap !== 'function') return null;
var cache = new WeakMap();
_getRequireWildcardCache = function() {
return cache;
};
return cache;
}
function _interopRequireWildcard(obj) {
if (obj && obj.__esModule) {
return obj;
} else {
var newObj = {};
if (obj != null) {
for (var key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
var desc =
Object.defineProperty && Object.getOwnPropertyDescriptor
? Object.getOwnPropertyDescriptor(obj, key)
: {};
if (desc.get || desc.set) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
}
if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) {
return {default: obj};
}
var cache = _getRequireWildcardCache();
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {};
var hasPropertyDescriptor =
Object.defineProperty && Object.getOwnPropertyDescriptor;
for (var key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor
? Object.getOwnPropertyDescriptor(obj, key)
: null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
newObj.default = obj;
return newObj;
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}

@@ -98,3 +123,3 @@

if (i % 2) {
ownKeys(source, true).forEach(function(key) {
ownKeys(Object(source), true).forEach(function(key) {
_defineProperty(target, key, source[key]);

@@ -105,3 +130,3 @@ });

} else {
ownKeys(source).forEach(function(key) {
ownKeys(Object(source)).forEach(function(key) {
Object.defineProperty(

@@ -138,4 +163,2 @@ target,

_defineProperty(this, '_onProcessEnd', void 0);
_defineProperty(this, '_request', void 0);

@@ -145,13 +168,25 @@

_defineProperty(this, '_stderr', void 0);
_defineProperty(this, '_onProcessEnd', void 0);
_defineProperty(this, '_fakeStream', void 0);
_defineProperty(this, '_stdout', void 0);
_defineProperty(this, '_fakeStream', void 0);
_defineProperty(this, '_stderr', void 0);
_defineProperty(this, '_exitPromise', void 0);
_defineProperty(this, '_resolveExitPromise', void 0);
_defineProperty(this, '_forceExited', void 0);
this._options = options;
this._request = null;
this._fakeStream = null;
this._stdout = null;
this._stderr = null;
this._stdout = null;
this._fakeStream = null;
this._exitPromise = new Promise(resolve => {
this._resolveExitPromise = resolve;
});
this._forceExited = false;
this.initialize();

@@ -161,3 +196,3 @@ }

initialize() {
this._worker = new (_worker_threads()).Worker(
this._worker = new (_worker_threads().Worker)(
path().resolve(__dirname, './threadChild.js'),

@@ -205,8 +240,8 @@ {

this._worker.on('message', this.onMessage.bind(this));
this._worker.on('message', this._onMessage.bind(this));
this._worker.on('exit', this.onExit.bind(this));
this._worker.on('exit', this._onExit.bind(this));
this._worker.postMessage([
_types.CHILD_MESSAGE_INITIALIZE,
_types().CHILD_MESSAGE_INITIALIZE,
false,

@@ -223,4 +258,5 @@ this._options.workerPath,

const error = new Error('Call retries were exceeded');
this.onMessage([
_types.PARENT_MESSAGE_CLIENT_ERROR,
this._onMessage([
_types().PARENT_MESSAGE_CLIENT_ERROR,
error.name,

@@ -243,9 +279,11 @@ error.message,

}
this._resolveExitPromise();
}
onMessage(response) {
_onMessage(response) {
let error;
switch (response[0]) {
case _types.PARENT_MESSAGE_OK:
case _types().PARENT_MESSAGE_OK:
this._onProcessEnd(null, response[1]);

@@ -255,3 +293,3 @@

case _types.PARENT_MESSAGE_CLIENT_ERROR:
case _types().PARENT_MESSAGE_CLIENT_ERROR:
error = response[4];

@@ -278,3 +316,3 @@

case _types.PARENT_MESSAGE_SETUP_ERROR:
case _types().PARENT_MESSAGE_SETUP_ERROR:
error = new Error('Error when calling setup: ' + response[2]); // @ts-ignore: adding custom properties to errors.

@@ -294,4 +332,4 @@

onExit(exitCode) {
if (exitCode !== 0) {
_onExit(exitCode) {
if (exitCode !== 0 && !this._forceExited) {
this.initialize();

@@ -307,2 +345,12 @@

waitForExit() {
return this._exitPromise;
}
forceExit() {
this._forceExited = true;
this._worker.terminate();
}
send(request, onProcessStart, onProcessEnd) {

@@ -338,3 +386,3 @@ onProcessStart(this);

if (!this._fakeStream) {
this._fakeStream = new (_stream()).PassThrough();
this._fakeStream = new (_stream().PassThrough)();
}

@@ -341,0 +389,0 @@

'use strict';
var _types = require('../types');
function _types() {
const data = require('../types');
_types = function() {
return data;
};
return data;
}
function ownKeys(object, enumerableOnly) {

@@ -22,3 +30,3 @@ var keys = Object.keys(object);

if (i % 2) {
ownKeys(source, true).forEach(function(key) {
ownKeys(Object(source), true).forEach(function(key) {
_defineProperty(target, key, source[key]);

@@ -29,3 +37,3 @@ });

} else {
ownKeys(source).forEach(function(key) {
ownKeys(Object(source)).forEach(function(key) {
Object.defineProperty(

@@ -73,5 +81,5 @@ target,

process.on('message', request => {
const messageListener = request => {
switch (request[0]) {
case _types.CHILD_MESSAGE_INITIALIZE:
case _types().CHILD_MESSAGE_INITIALIZE:
const init = request;

@@ -82,3 +90,3 @@ file = init[2];

case _types.CHILD_MESSAGE_CALL:
case _types().CHILD_MESSAGE_CALL:
const call = request;

@@ -88,3 +96,3 @@ execMethod(call[2], call[3]);

case _types.CHILD_MESSAGE_END:
case _types().CHILD_MESSAGE_END:
end();

@@ -98,4 +106,6 @@ break;

}
});
};
process.on('message', messageListener);
function reportSuccess(result) {

@@ -106,11 +116,11 @@ if (!process || !process.send) {

process.send([_types.PARENT_MESSAGE_OK, result]);
process.send([_types().PARENT_MESSAGE_OK, result]);
}
function reportClientError(error) {
return reportError(error, _types.PARENT_MESSAGE_CLIENT_ERROR);
return reportError(error, _types().PARENT_MESSAGE_CLIENT_ERROR);
}
function reportInitializeError(error) {
return reportError(error, _types.PARENT_MESSAGE_SETUP_ERROR);
return reportError(error, _types().PARENT_MESSAGE_SETUP_ERROR);
}

@@ -148,3 +158,4 @@

function exitProcess() {
process.exit(0);
// Clean up open handles so the process ideally exits gracefully
process.removeListener('message', messageListener);
}

@@ -151,0 +162,0 @@

@@ -13,4 +13,12 @@ 'use strict';

var _types = require('../types');
function _types() {
const data = require('../types');
_types = function() {
return data;
};
return data;
}
function ownKeys(object, enumerableOnly) {

@@ -33,3 +41,3 @@ var keys = Object.keys(object);

if (i % 2) {
ownKeys(source, true).forEach(function(key) {
ownKeys(Object(source), true).forEach(function(key) {
_defineProperty(target, key, source[key]);

@@ -40,3 +48,3 @@ });

} else {
ownKeys(source).forEach(function(key) {
ownKeys(Object(source)).forEach(function(key) {
Object.defineProperty(

@@ -84,5 +92,5 @@ target,

_worker_threads().parentPort.on('message', request => {
const messageListener = request => {
switch (request[0]) {
case _types.CHILD_MESSAGE_INITIALIZE:
case _types().CHILD_MESSAGE_INITIALIZE:
const init = request;

@@ -93,3 +101,3 @@ file = init[2];

case _types.CHILD_MESSAGE_CALL:
case _types().CHILD_MESSAGE_CALL:
const call = request;

@@ -99,3 +107,3 @@ execMethod(call[2], call[3]);

case _types.CHILD_MESSAGE_END:
case _types().CHILD_MESSAGE_END:
end();

@@ -109,4 +117,6 @@ break;

}
});
};
_worker_threads().parentPort.on('message', messageListener);
function reportSuccess(result) {

@@ -117,11 +127,14 @@ if (_worker_threads().isMainThread) {

_worker_threads().parentPort.postMessage([_types.PARENT_MESSAGE_OK, result]);
_worker_threads().parentPort.postMessage([
_types().PARENT_MESSAGE_OK,
result
]);
}
function reportClientError(error) {
return reportError(error, _types.PARENT_MESSAGE_CLIENT_ERROR);
return reportError(error, _types().PARENT_MESSAGE_CLIENT_ERROR);
}
function reportInitializeError(error) {
return reportError(error, _types.PARENT_MESSAGE_SETUP_ERROR);
return reportError(error, _types().PARENT_MESSAGE_SETUP_ERROR);
}

@@ -159,3 +172,4 @@

function exitProcess() {
process.exit(0);
// Clean up open handles so the worker ideally exits gracefully
_worker_threads().parentPort.removeListener('message', messageListener);
}

@@ -162,0 +176,0 @@

{
"name": "jest-worker",
"version": "25.0.0",
"version": "25.1.0",
"repository": {

@@ -23,3 +23,3 @@ "type": "git",

"engines": {
"node": ">= 8"
"node": ">= 8.3"
},

@@ -29,3 +29,3 @@ "publishConfig": {

},
"gitHead": "ff9269be05fd8316e95232198fce3463bf2f270e"
"gitHead": "170eee11d03b0ed5c60077982fdbc3bafd403638"
}

@@ -86,3 +86,3 @@ # jest-worker

#### `workerPool: (workerPath: string, options?: WorkerPoolOptions) => WorkerPoolInterface` (optional)
#### `WorkerPool: (workerPath: string, options?: WorkerPoolOptions) => WorkerPoolInterface` (optional)

@@ -99,18 +99,30 @@ Provide a custom worker pool to be used for spawning child processes. By default, Jest will use a node thread pool if available and fall back to child process threads.

### Methods
The returned `Worker` instance has all the exposed methods, plus some additional ones to interact with the workers itself:
### `getStdout(): Readable`
#### `getStdout(): Readable`
Returns a `ReadableStream` where the standard output of all workers is piped. Note that the `silent` option of the child workers must be set to `true` to make it work. This is the default set by `jest-worker`, but keep it in mind when overriding options through `forkOptions`.
### `getStderr(): Readable`
#### `getStderr(): Readable`
Returns a `ReadableStream` where the standard error of all workers is piped. Note that the `silent` option of the child workers must be set to `true` to make it work. This is the default set by `jest-worker`, but keep it in mind when overriding options through `forkOptions`.
### `end()`
#### `end()`
Finishes the workers by killing all workers. No further calls can be done to the `Worker` instance.
**Note:** Each worker has a unique id (index that starts with `1`) which is available on `process.env.JEST_WORKER_ID`
Returns a Promise that resolves with `{ forceExited: boolean }` once all workers are dead. If `forceExited` is `true`, at least one of the workers did not exit gracefully, which likely happened because it executed a leaky task that left handles open. This should be avoided, force exiting workers is a last resort to prevent creating lots of orphans.
**Note:**
`await`ing the `end()` Promise immediately after the workers are no longer needed before proceeding to do other useful things in your program may not be a good idea. If workers have to be force exited, `jest-worker` may go through multiple stages of force exiting (e.g. SIGTERM, later SIGKILL) and give the worker overall around 1 second time to exit on its own. During this time, your program will wait, even though it may not be necessary that all workers are dead before continuing execution.
Consider deliberately leaving this Promise floating (unhandled resolution). After your program has done the rest of its work and is about to exit, the Node process will wait for the Promise to resolve after all workers are dead as the last event loop task. That way you parallelized computation time of your program and waiting time and you didn't delay the outputs of your program unnecessarily.
### Worker IDs
Each worker has a unique id (index that starts with `1`), which is available inside the worker as `process.env.JEST_WORKER_ID`.
## Setting up and tearing down the child process

@@ -144,3 +156,6 @@

myWorker.end();
const {forceExited} = await myWorker.end();
if (forceExited) {
console.error('Workers failed to exit gracefully');
}
}

@@ -192,3 +207,6 @@

myWorker.end();
const {forceExited} = await myWorker.end();
if (forceExited) {
console.error('Workers failed to exit gracefully');
}
}

@@ -195,0 +213,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc