UNPKG

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