jest-worker

  • Version 27.2.5
  • Published
  • 82 kB
  • 3 dependencies
  • MIT license

Install

npm i jest-worker
yarn add jest-worker
pnpm add jest-worker

Overview

Module for executing heavy tasks under forked processes in parallel, by providing a `Promise` based interface, minimum overhead, and bound workers.

Index

Functions

function messageParent

messageParent: (message: unknown, parentProcess?: any) => void;
  • Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

    This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree.

Classes

class FifoQueue

class FifoQueue implements TaskQueue {}
  • First-in, First-out task queue that manages a dedicated pool for each worker as well as a shared queue. The FIFO ordering is guaranteed across the worker specific and shared queue.

method dequeue

dequeue: (workerId: number) => QueueChildMessage | null;

    method enqueue

    enqueue: (task: QueueChildMessage, workerId?: number) => void;

      class PriorityQueue

      class PriorityQueue implements TaskQueue {}
      • Priority queue that processes tasks in natural ordering (lower priority first) accoridng to the priority computed by the function passed in the constructor.

        FIFO ordering isn't guaranteed for tasks with the same priority.

        Worker specific tasks with the same priority as a non-worker specific task are always processed first.

      constructor

      constructor(_computePriority: ComputeTaskPriorityCallback);

        method dequeue

        dequeue: (workerId: number) => QueueChildMessage | null;

          method enqueue

          enqueue: (task: QueueChildMessage, workerId?: number) => void;

            class Worker

            class Worker {}
            • The Jest farm (publicly called "Worker") is a class that allows you to queue methods across multiple child processes, in order to parallelize work. This is done by providing an absolute path to a module that will be loaded on each of the child processes, and bridged to the main process.

              Bridged methods are specified by using the "exposedMethods" property of the "options" object. This is an array of strings, where each of them corresponds to the exported name in the loaded module.

              You can also control the amount of workers by using the "numWorkers" property of the "options" object, and the settings passed to fork the process through the "forkOptions" property. The amount of workers defaults to the amount of CPUS minus one.

              Queueing calls can be done in two ways: - Standard method: calls will be redirected to the first available worker, so they will get executed as soon as they can.

              - Sticky method: if a "computeWorkerKey" method is provided within the config, the resulting string of this method will be used as a key. Every time this key is returned, it is guaranteed that your job will be processed by the same worker. This is specially useful if your workers are caching results.

            constructor

            constructor(workerPath: string, options?: FarmOptions);

              method end

              end: () => Promise<PoolExitResult>;

                method getStderr

                getStderr: () => any;

                  method getStdout

                  getStdout: () => any;

                    Interfaces

                    interface PromiseWithCustomMessage

                    interface PromiseWithCustomMessage<T> extends Promise<T> {}

                      property UNSTABLE_onCustomMessage

                      UNSTABLE_onCustomMessage?: (listener: OnCustomMessage) => () => void;

                        interface TaskQueue

                        interface TaskQueue {}

                          method dequeue

                          dequeue: (workerId: number) => QueueChildMessage | null;
                          • Dequeues the next item from the queue for the speified worker

                            Parameter workerId

                            the id of the worker for which the next task should be retrieved

                          method enqueue

                          enqueue: (task: QueueChildMessage, workerId?: number) => void;
                          • Enqueues the task in the queue for the specified worker or adds it to the queue shared by all workers

                            Parameter task

                            the task to queue

                            Parameter workerId

                            the id of the worker that should process this task or undefined if there's no preference.

                          Package Files (5)

                          Dependencies (3)

                          Dev Dependencies (5)

                          Peer Dependencies (0)

                          No peer dependencies.

                          Badge

                          To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                          You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/jest-worker.

                          • Markdown
                            [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/jest-worker)
                          • HTML
                            <a href="https://www.jsdocs.io/package/jest-worker"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>