1 | ;
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 | exports.shouldRunInBand = shouldRunInBand;
|
7 |
|
8 | /**
|
9 | * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
10 | *
|
11 | * This source code is licensed under the MIT license found in the
|
12 | * LICENSE file in the root directory of this source tree.
|
13 | */
|
14 | const SLOW_TEST_TIME = 1000;
|
15 |
|
16 | function shouldRunInBand(
|
17 | tests,
|
18 | timings,
|
19 | {detectOpenHandles, maxWorkers, watch, watchAll}
|
20 | ) {
|
21 | // detectOpenHandles makes no sense without runInBand, because it cannot detect leaks in workers
|
22 | if (detectOpenHandles) {
|
23 | return true;
|
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 |
|
37 | const isWatchMode = watch || watchAll;
|
38 | const areFastTests = timings.every(timing => timing < SLOW_TEST_TIME);
|
39 | const oneWorkerOrLess = maxWorkers <= 1;
|
40 | const oneTestOrLess = tests.length <= 1;
|
41 |
|
42 | if (isWatchMode) {
|
43 | return oneWorkerOrLess || (oneTestOrLess && areFastTests);
|
44 | }
|
45 |
|
46 | return (
|
47 | oneWorkerOrLess ||
|
48 | oneTestOrLess ||
|
49 | (tests.length <= 20 && timings.length > 0 && areFastTests)
|
50 | );
|
51 | }
|