1 | /**
|
2 | * Copyright (c) Meta Platforms, Inc. and affiliates.
|
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 | import type {AggregatedResult} from '@jest/test-result';
|
8 | import type {Test} from '@jest/test-result';
|
9 | import type {TestContext} from '@jest/test-result';
|
10 |
|
11 | declare type Cache_2 = {
|
12 | [key: string]:
|
13 | | [testStatus: typeof FAIL | typeof SUCCESS, testDuration: number]
|
14 | | undefined;
|
15 | };
|
16 |
|
17 | declare const FAIL = 0;
|
18 |
|
19 | export declare type ShardOptions = {
|
20 | shardIndex: number;
|
21 | shardCount: number;
|
22 | };
|
23 |
|
24 | declare const SUCCESS = 1;
|
25 |
|
26 | /**
|
27 | * The TestSequencer will ultimately decide which tests should run first.
|
28 | * It is responsible for storing and reading from a local cache
|
29 | * map that stores context information for a given test, such as how long it
|
30 | * took to run during the last run and if it has failed or not.
|
31 | * Such information is used on:
|
32 | * TestSequencer.sort(tests: Array<Test>)
|
33 | * to sort the order of the provided tests.
|
34 | *
|
35 | * After the results are collected,
|
36 | * TestSequencer.cacheResults(tests: Array<Test>, results: AggregatedResult)
|
37 | * is called to store/update this information on the cache map.
|
38 | */
|
39 | declare class TestSequencer {
|
40 | private readonly _cache;
|
41 | _getCachePath(testContext: TestContext): string;
|
42 | _getCache(test: Test): Cache_2;
|
43 | private _shardPosition;
|
44 | /**
|
45 | * Select tests for shard requested via --shard=shardIndex/shardCount
|
46 | * Sharding is applied before sorting
|
47 | *
|
48 | * @param tests All tests
|
49 | * @param options shardIndex and shardIndex to select
|
50 | *
|
51 | * @example
|
52 | * ```typescript
|
53 | * class CustomSequencer extends Sequencer {
|
54 | * shard(tests, { shardIndex, shardCount }) {
|
55 | * const shardSize = Math.ceil(tests.length / options.shardCount);
|
56 | * const shardStart = shardSize * (options.shardIndex - 1);
|
57 | * const shardEnd = shardSize * options.shardIndex;
|
58 | * return [...tests]
|
59 | * .sort((a, b) => (a.path > b.path ? 1 : -1))
|
60 | * .slice(shardStart, shardEnd);
|
61 | * }
|
62 | * }
|
63 | * ```
|
64 | */
|
65 | shard(
|
66 | tests: Array<Test>,
|
67 | options: ShardOptions,
|
68 | ): Array<Test> | Promise<Array<Test>>;
|
69 | /**
|
70 | * Sort test to determine order of execution
|
71 | * Sorting is applied after sharding
|
72 | * @param tests
|
73 | *
|
74 | * ```typescript
|
75 | * class CustomSequencer extends Sequencer {
|
76 | * sort(tests) {
|
77 | * const copyTests = Array.from(tests);
|
78 | * return [...tests].sort((a, b) => (a.path > b.path ? 1 : -1));
|
79 | * }
|
80 | * }
|
81 | * ```
|
82 | */
|
83 | sort(tests: Array<Test>): Array<Test> | Promise<Array<Test>>;
|
84 | allFailedTests(tests: Array<Test>): Array<Test> | Promise<Array<Test>>;
|
85 | cacheResults(tests: Array<Test>, results: AggregatedResult): void;
|
86 | private hasFailed;
|
87 | private time;
|
88 | }
|
89 | export default TestSequencer;
|
90 |
|
91 | export {};
|