UNPKG

3.36 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 {Config} from '@jest/types';
8import type {SerializableError} from '@jest/test-result';
9import {Test} from '@jest/test-result';
10import {TestEvents} from '@jest/test-result';
11import type {TestResult} from '@jest/test-result';
12import {TestWatcher} from 'jest-watcher';
13
14declare abstract class BaseTestRunner {
15 protected readonly _globalConfig: Config.GlobalConfig;
16 protected readonly _context: TestRunnerContext;
17 readonly isSerial?: boolean;
18 abstract readonly supportsEventEmitters: boolean;
19 constructor(_globalConfig: Config.GlobalConfig, _context: TestRunnerContext);
20}
21
22export declare abstract class CallbackTestRunner
23 extends BaseTestRunner
24 implements CallbackTestRunnerInterface
25{
26 readonly supportsEventEmitters = false;
27 abstract runTests(
28 tests: Array<Test>,
29 watcher: TestWatcher,
30 onStart: OnTestStart,
31 onResult: OnTestSuccess,
32 onFailure: OnTestFailure,
33 options: TestRunnerOptions,
34 ): Promise<void>;
35}
36
37export declare interface CallbackTestRunnerInterface {
38 readonly isSerial?: boolean;
39 readonly supportsEventEmitters?: boolean;
40 runTests(
41 tests: Array<Test>,
42 watcher: TestWatcher,
43 onStart: OnTestStart,
44 onResult: OnTestSuccess,
45 onFailure: OnTestFailure,
46 options: TestRunnerOptions,
47 ): Promise<void>;
48}
49
50export {Config};
51
52export declare abstract class EmittingTestRunner
53 extends BaseTestRunner
54 implements EmittingTestRunnerInterface
55{
56 readonly supportsEventEmitters = true;
57 abstract runTests(
58 tests: Array<Test>,
59 watcher: TestWatcher,
60 options: TestRunnerOptions,
61 ): Promise<void>;
62 abstract on<Name extends keyof TestEvents>(
63 eventName: Name,
64 listener: (eventData: TestEvents[Name]) => void | Promise<void>,
65 ): UnsubscribeFn;
66}
67
68export declare interface EmittingTestRunnerInterface {
69 readonly isSerial?: boolean;
70 readonly supportsEventEmitters: true;
71 runTests(
72 tests: Array<Test>,
73 watcher: TestWatcher,
74 options: TestRunnerOptions,
75 ): Promise<void>;
76 on<Name extends keyof TestEvents>(
77 eventName: Name,
78 listener: (eventData: TestEvents[Name]) => void | Promise<void>,
79 ): UnsubscribeFn;
80}
81
82export declare type JestTestRunner = CallbackTestRunner | EmittingTestRunner;
83
84export declare type OnTestFailure = (
85 test: Test,
86 serializableError: SerializableError,
87) => Promise<void>;
88
89export declare type OnTestStart = (test: Test) => Promise<void>;
90
91export declare type OnTestSuccess = (
92 test: Test,
93 testResult: TestResult,
94) => Promise<void>;
95
96export {Test};
97
98export {TestEvents};
99
100declare class TestRunner extends EmittingTestRunner {
101 #private;
102 runTests(
103 tests: Array<Test>,
104 watcher: TestWatcher,
105 options: TestRunnerOptions,
106 ): Promise<void>;
107 on<Name extends keyof TestEvents>(
108 eventName: Name,
109 listener: (eventData: TestEvents[Name]) => void | Promise<void>,
110 ): UnsubscribeFn;
111}
112export default TestRunner;
113
114export declare type TestRunnerContext = {
115 changedFiles?: Set<string>;
116 sourcesRelatedToTestsInChangedFiles?: Set<string>;
117};
118
119export declare type TestRunnerOptions = {
120 serial: boolean;
121};
122
123export {TestWatcher};
124
125export declare type UnsubscribeFn = () => void;
126
127export {};