UNPKG

2.62 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];
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 _cache;
35 _getCachePath(testContext: TestContext): string;
36 _getCache(test: Test): Cache_2;
37 /**
38 * Select tests for shard requested via --shard=shardIndex/shardCount
39 * Sharding is applied before sorting
40 *
41 * @param tests All tests
42 * @param options shardIndex and shardIndex to select
43 *
44 * @example
45 * ```typescript
46 * class CustomSequencer extends Sequencer {
47 * shard(tests, { shardIndex, shardCount }) {
48 * const shardSize = Math.ceil(tests.length / options.shardCount);
49 * const shardStart = shardSize * (options.shardIndex - 1);
50 * const shardEnd = shardSize * options.shardIndex;
51 * return [...tests]
52 * .sort((a, b) => (a.path > b.path ? 1 : -1))
53 * .slice(shardStart, shardEnd);
54 * }
55 * }
56 * ```
57 */
58 shard(
59 tests: Array<Test>,
60 options: ShardOptions,
61 ): Array<Test> | Promise<Array<Test>>;
62 /**
63 * Sort test to determine order of execution
64 * Sorting is applied after sharding
65 * @param tests
66 *
67 * ```typescript
68 * class CustomSequencer extends Sequencer {
69 * sort(tests) {
70 * const copyTests = Array.from(tests);
71 * return [...tests].sort((a, b) => (a.path > b.path ? 1 : -1));
72 * }
73 * }
74 * ```
75 */
76 sort(tests: Array<Test>): Array<Test> | Promise<Array<Test>>;
77 allFailedTests(tests: Array<Test>): Array<Test> | Promise<Array<Test>>;
78 cacheResults(tests: Array<Test>, results: AggregatedResult): void;
79}
80export default TestSequencer;
81
82export {};