1 | /**
|
2 | * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
3 | *
|
4 | * This source code is licensed under the MIT license found in the
|
5 | * LICENSE file in the root directory of this source tree.
|
6 | */
|
7 | /// <reference types="node" />
|
8 | import type { FarmOptions, PoolExitResult } from './types';
|
9 | /**
|
10 | * The Jest farm (publicly called "Worker") is a class that allows you to queue
|
11 | * methods across multiple child processes, in order to parallelize work. This
|
12 | * is done by providing an absolute path to a module that will be loaded on each
|
13 | * of the child processes, and bridged to the main process.
|
14 | *
|
15 | * Bridged methods are specified by using the "exposedMethods" property of the
|
16 | * "options" object. This is an array of strings, where each of them corresponds
|
17 | * to the exported name in the loaded module.
|
18 | *
|
19 | * You can also control the amount of workers by using the "numWorkers" property
|
20 | * of the "options" object, and the settings passed to fork the process through
|
21 | * the "forkOptions" property. The amount of workers defaults to the amount of
|
22 | * CPUS minus one.
|
23 | *
|
24 | * Queueing calls can be done in two ways:
|
25 | * - Standard method: calls will be redirected to the first available worker,
|
26 | * so they will get executed as soon as they can.
|
27 | *
|
28 | * - Sticky method: if a "computeWorkerKey" method is provided within the
|
29 | * config, the resulting string of this method will be used as a key.
|
30 | * Every time this key is returned, it is guaranteed that your job will be
|
31 | * processed by the same worker. This is specially useful if your workers
|
32 | * are caching results.
|
33 | */
|
34 | export default class JestWorker {
|
35 | private _ending;
|
36 | private _farm;
|
37 | private _options;
|
38 | private _workerPool;
|
39 | constructor(workerPath: string, options?: FarmOptions);
|
40 | private _bindExposedWorkerMethods;
|
41 | private _callFunctionWithArgs;
|
42 | getStderr(): NodeJS.ReadableStream;
|
43 | getStdout(): NodeJS.ReadableStream;
|
44 | end(): Promise<PoolExitResult>;
|
45 | }
|