UNPKG

5.28 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 */
7/// <reference types="node" />
8import type * as Global from './Global';
9declare type Process = NodeJS.Process;
10export declare type DoneFn = Global.DoneFn;
11export declare type BlockFn = Global.BlockFn;
12export declare type BlockName = Global.BlockName;
13export declare type BlockMode = void | 'skip' | 'only' | 'todo';
14export declare type TestMode = BlockMode;
15export declare type TestName = Global.TestName;
16export declare type TestFn = Global.TestFn;
17export declare type HookFn = Global.HookFn;
18export declare type AsyncFn = TestFn | HookFn;
19export declare type SharedHookType = 'afterAll' | 'beforeAll';
20export declare type HookType = SharedHookType | 'afterEach' | 'beforeEach';
21export declare type TestContext = Global.TestContext;
22export declare type Exception = any;
23export declare type FormattedError = string;
24export declare type Hook = {
25 asyncError: Error;
26 fn: HookFn;
27 type: HookType;
28 parent: DescribeBlock;
29 seenDone: boolean;
30 timeout: number | undefined | null;
31};
32export interface EventHandler {
33 (event: AsyncEvent, state: State): void | Promise<void>;
34 (event: SyncEvent, state: State): void;
35}
36export declare type Event = SyncEvent | AsyncEvent;
37interface JestGlobals extends Global.TestFrameworkGlobals {
38 expect: unknown;
39}
40export declare type SyncEvent = {
41 asyncError: Error;
42 mode: BlockMode;
43 name: 'start_describe_definition';
44 blockName: BlockName;
45} | {
46 mode: BlockMode;
47 name: 'finish_describe_definition';
48 blockName: BlockName;
49} | {
50 asyncError: Error;
51 name: 'add_hook';
52 hookType: HookType;
53 fn: HookFn;
54 timeout: number | undefined;
55} | {
56 asyncError: Error;
57 name: 'add_test';
58 testName: TestName;
59 fn: TestFn;
60 mode?: TestMode;
61 timeout: number | undefined;
62} | {
63 name: 'error';
64 error: Exception;
65};
66export declare type AsyncEvent = {
67 name: 'setup';
68 testNamePattern?: string;
69 runtimeGlobals: JestGlobals;
70 parentProcess: Process;
71} | {
72 name: 'include_test_location_in_result';
73} | {
74 name: 'hook_start';
75 hook: Hook;
76} | {
77 name: 'hook_success';
78 describeBlock?: DescribeBlock;
79 test?: TestEntry;
80 hook: Hook;
81} | {
82 name: 'hook_failure';
83 error: string | Exception;
84 describeBlock?: DescribeBlock;
85 test?: TestEntry;
86 hook: Hook;
87} | {
88 name: 'test_fn_start';
89 test: TestEntry;
90} | {
91 name: 'test_fn_success';
92 test: TestEntry;
93} | {
94 name: 'test_fn_failure';
95 error: Exception;
96 test: TestEntry;
97} | {
98 name: 'test_retry';
99 test: TestEntry;
100} | {
101 name: 'test_start';
102 test: TestEntry;
103} | {
104 name: 'test_skip';
105 test: TestEntry;
106} | {
107 name: 'test_todo';
108 test: TestEntry;
109} | {
110 name: 'test_done';
111 test: TestEntry;
112} | {
113 name: 'run_describe_start';
114 describeBlock: DescribeBlock;
115} | {
116 name: 'run_describe_finish';
117 describeBlock: DescribeBlock;
118} | {
119 name: 'run_start';
120} | {
121 name: 'run_finish';
122} | {
123 name: 'teardown';
124};
125export declare type MatcherResults = {
126 actual: unknown;
127 expected: unknown;
128 name: string;
129 pass: boolean;
130};
131export declare type TestStatus = 'skip' | 'done' | 'todo';
132export declare type TestResult = {
133 duration?: number | null;
134 errors: Array<FormattedError>;
135 errorsDetailed: Array<MatcherResults | unknown>;
136 invocations: number;
137 status: TestStatus;
138 location?: {
139 column: number;
140 line: number;
141 } | null;
142 testPath: Array<TestName | BlockName>;
143};
144export declare type RunResult = {
145 unhandledErrors: Array<FormattedError>;
146 testResults: TestResults;
147};
148export declare type TestResults = Array<TestResult>;
149export declare type GlobalErrorHandlers = {
150 uncaughtException: Array<(exception: Exception) => void>;
151 unhandledRejection: Array<(exception: Exception, promise: Promise<unknown>) => void>;
152};
153export declare type State = {
154 currentDescribeBlock: DescribeBlock;
155 currentlyRunningTest?: TestEntry | null;
156 expand?: boolean;
157 hasFocusedTests: boolean;
158 hasStarted: boolean;
159 originalGlobalErrorHandlers?: GlobalErrorHandlers;
160 parentProcess: Process | null;
161 rootDescribeBlock: DescribeBlock;
162 testNamePattern?: RegExp | null;
163 testTimeout: number;
164 unhandledErrors: Array<Exception>;
165 includeTestLocationInResult: boolean;
166};
167export declare type DescribeBlock = {
168 type: 'describeBlock';
169 children: Array<DescribeBlock | TestEntry>;
170 hooks: Array<Hook>;
171 mode: BlockMode;
172 name: BlockName;
173 parent?: DescribeBlock;
174 /** @deprecated Please get from `children` array instead */
175 tests: Array<TestEntry>;
176};
177export declare type TestError = Exception | [Exception | undefined, Exception];
178export declare type TestEntry = {
179 type: 'test';
180 asyncError: Exception;
181 errors: Array<TestError>;
182 fn: TestFn;
183 invocations: number;
184 mode: TestMode;
185 name: TestName;
186 parent: DescribeBlock;
187 startedAt?: number | null;
188 duration?: number | null;
189 seenDone: boolean;
190 status?: TestStatus | null;
191 timeout?: number;
192};
193export {};