index.d.ts 2.1 KB

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