1 | ;
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 | exports.shouldRunInBand = shouldRunInBand;
|
7 | /**
|
8 | * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
9 | *
|
10 | * This source code is licensed under the MIT license found in the
|
11 | * LICENSE file in the root directory of this source tree.
|
12 | */
|
13 |
|
14 | const SLOW_TEST_TIME = 1000;
|
15 | function shouldRunInBand(
|
16 | tests,
|
17 | timings,
|
18 | {detectOpenHandles, maxWorkers, watch, watchAll}
|
19 | ) {
|
20 | // detectOpenHandles makes no sense without runInBand, because it cannot detect leaks in workers
|
21 | if (detectOpenHandles) {
|
22 | return true;
|
23 | }
|
24 |
|
25 | /*
|
26 | * Run in band if we only have one test or one worker available, unless we
|
27 | * are using the watch mode, in which case the TTY has to be responsive and
|
28 | * we cannot schedule anything in the main thread. Same logic applies to
|
29 | * watchAll.
|
30 | * Also, if we are confident from previous runs that the tests will finish
|
31 | * quickly we also run in band to reduce the overhead of spawning workers.
|
32 | * Finally, the user can provide the runInBand argument in the CLI to
|
33 | * force running in band.
|
34 | * https://github.com/facebook/jest/blob/700e0dadb85f5dc8ff5dac6c7e98956690049734/packages/jest-config/src/getMaxWorkers.js#L14-L17
|
35 | */
|
36 | const isWatchMode = watch || watchAll;
|
37 | const areFastTests = timings.every(timing => timing < SLOW_TEST_TIME);
|
38 | const oneWorkerOrLess = maxWorkers <= 1;
|
39 | const oneTestOrLess = tests.length <= 1;
|
40 | if (isWatchMode) {
|
41 | return oneWorkerOrLess || (oneTestOrLess && areFastTests);
|
42 | }
|
43 | return (
|
44 | oneWorkerOrLess ||
|
45 | oneTestOrLess ||
|
46 | (tests.length <= 20 && timings.length > 0 && areFastTests)
|
47 | );
|
48 | }
|