jest-worker
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
@types/node | 20.12.7 | 1.94 MB | MIT | prod | |
merge-stream | 2.0.0 | 2.21 kB | MIT | prod | |
supports-color | 8.1.1 | 3.64 kB | MIT | prod |
"Jest-worker" is an npm module designed to execute heavy tasks under forked processes in parallel. It provides a Promise-based interface with minimum overhead and bound workers, thus ensuring efficiency. It enables the loading of a module in all forked processes by utilizing an absolute path of the module. This makes it possible to await
all the methods exposed on the parent process as promises.
Installation of this module requires running the command yarn add jest-worker
in the terminal. After installation, create the worker file and the parent file. In the worker file, define the functions that the workers will execute. For instance, you can have a hello()
function that takes a string parameter and returns a greeting. In the parent file, import jest-worker
and create a new worker instance, passing the path of the worker file to the constructor. Then, call the hello()
function on the worker instance, passing in a string as an argument. The function will return a promise, so make sure to await
it. A basic usage example can look like this:
File parent.js
import {Worker as JestWorker} from 'jest-worker';
async function main() {
const worker = new JestWorker(require.resolve('./worker'));
const result = await worker.hello('Alice'); // "Hello, Alice"
}
main();
File worker.js
export function hello(param) {
return `Hello, ${param}`;
}
The documentation for "jest-worker" can be found in its GitHub repo README file which is located at git+https://github.com/jestjs/jest.git
. The README file provides comprehensive information on how to install and use the module, including basic and advanced usage examples. You'll find detailed descriptions of the module's API, including all the options you can pass to the JestWorker constructor. It also provides explanations of concepts like bound workers and worker IDs and how to setup and teardown the child process. The README file is detailed and practical, making it an excellent resource for JavaScript developers working with jest-worker
.