UNPKG

3.39 kBTypeScriptView Raw
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 */
7import {AggregatedResult} from '@jest/test-result';
8import {BaseReporter} from '@jest/reporters';
9import type {ChangedFiles} from 'jest-changed-files';
10import type {Config} from '@jest/types';
11import {Reporter} from '@jest/reporters';
12import {ReporterContext} from '@jest/reporters';
13import {Test} from '@jest/test-result';
14import type {TestContext} from '@jest/test-result';
15import type {TestRunnerContext} from 'jest-runner';
16import type {TestWatcher} from 'jest-watcher';
17
18export declare function createTestScheduler(
19 globalConfig: Config.GlobalConfig,
20 context: TestSchedulerContext,
21): Promise<TestScheduler>;
22
23declare type Filter = (testPaths: Array<string>) => Promise<{
24 filtered: Array<FilterResult>;
25}>;
26
27declare type FilterResult = {
28 test: string;
29 message: string;
30};
31
32export declare function getVersion(): string;
33
34declare type ReporterConstructor = new (
35 globalConfig: Config.GlobalConfig,
36 reporterConfig: Record<string, unknown>,
37 reporterContext: ReporterContext,
38) => BaseReporter;
39
40export declare function runCLI(
41 argv: Config.Argv,
42 projects: Array<string>,
43): Promise<{
44 results: AggregatedResult;
45 globalConfig: Config.GlobalConfig;
46}>;
47
48declare type SearchResult = {
49 noSCM?: boolean;
50 stats?: Stats;
51 collectCoverageFrom?: Set<string>;
52 tests: Array<Test>;
53 total?: number;
54};
55
56export declare class SearchSource {
57 private readonly _context;
58 private _dependencyResolver;
59 private readonly _testPathCases;
60 constructor(context: TestContext);
61 private _getOrBuildDependencyResolver;
62 private _filterTestPathsWithStats;
63 private _getAllTestPaths;
64 isTestFilePath(path: string): boolean;
65 findMatchingTests(testPathPattern: string): SearchResult;
66 findRelatedTests(
67 allPaths: Set<string>,
68 collectCoverage: boolean,
69 ): Promise<SearchResult>;
70 findTestsByPaths(paths: Array<string>): SearchResult;
71 findRelatedTestsFromPattern(
72 paths: Array<string>,
73 collectCoverage: boolean,
74 ): Promise<SearchResult>;
75 findTestRelatedToChangedFiles(
76 changedFilesInfo: ChangedFiles,
77 collectCoverage: boolean,
78 ): Promise<SearchResult>;
79 private _getTestPaths;
80 filterPathsWin32(paths: Array<string>): Array<string>;
81 getTestPaths(
82 globalConfig: Config.GlobalConfig,
83 changedFiles?: ChangedFiles,
84 filter?: Filter,
85 ): Promise<SearchResult>;
86 findRelatedSourcesFromTestsInChangedFiles(
87 changedFilesInfo: ChangedFiles,
88 ): Promise<Array<string>>;
89}
90
91declare type Stats = {
92 roots: number;
93 testMatch: number;
94 testPathIgnorePatterns: number;
95 testRegex: number;
96 testPathPattern?: number;
97};
98
99declare class TestScheduler {
100 private readonly _context;
101 private readonly _dispatcher;
102 private readonly _globalConfig;
103 constructor(globalConfig: Config.GlobalConfig, context: TestSchedulerContext);
104 addReporter(reporter: Reporter): void;
105 removeReporter(reporterConstructor: ReporterConstructor): void;
106 scheduleTests(
107 tests: Array<Test>,
108 watcher: TestWatcher,
109 ): Promise<AggregatedResult>;
110 private _partitionTests;
111 _setupReporters(): Promise<void>;
112 private _addCustomReporter;
113 private _bailIfNeeded;
114}
115
116declare type TestSchedulerContext = ReporterContext & TestRunnerContext;
117
118export {};