UNPKG

7.91 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" />
8
9import {AggregatedResult} from '@jest/test-result';
10import type {AssertionResult} from '@jest/test-result';
11import {Config} from '@jest/types';
12import {SnapshotSummary} from '@jest/test-result';
13import type {Suite} from '@jest/test-result';
14import {Test} from '@jest/test-result';
15import {TestCaseResult} from '@jest/test-result';
16import {TestContext} from '@jest/test-result';
17import {TestResult} from '@jest/test-result';
18
19export {AggregatedResult};
20
21export declare class BaseReporter implements Reporter {
22 private _error?;
23 log(message: string): void;
24 onRunStart(
25 _results?: AggregatedResult,
26 _options?: ReporterOnStartOptions,
27 ): void;
28 onTestCaseResult(_test: Test, _testCaseResult: TestCaseResult): void;
29 onTestResult(
30 _test?: Test,
31 _testResult?: TestResult,
32 _results?: AggregatedResult,
33 ): void;
34 onTestStart(_test?: Test): void;
35 onRunComplete(
36 _testContexts?: Set<TestContext>,
37 _aggregatedResults?: AggregatedResult,
38 ): Promise<void> | void;
39 protected _setError(error: Error): void;
40 getLastError(): Error | undefined;
41}
42
43export {Config};
44
45export declare class CoverageReporter extends BaseReporter {
46 private readonly _context;
47 private readonly _coverageMap;
48 private readonly _globalConfig;
49 private readonly _sourceMapStore;
50 private readonly _v8CoverageResults;
51 static readonly filename: string;
52 constructor(globalConfig: Config.GlobalConfig, context: ReporterContext);
53 onTestResult(_test: Test, testResult: TestResult): void;
54 onRunComplete(
55 testContexts: Set<TestContext>,
56 aggregatedResults: AggregatedResult,
57 ): Promise<void>;
58 private _addUntestedFiles;
59 private _checkThreshold;
60 private _getCoverageResult;
61}
62
63export declare class DefaultReporter extends BaseReporter {
64 private _clear;
65 private readonly _err;
66 protected _globalConfig: Config.GlobalConfig;
67 private readonly _out;
68 private readonly _status;
69 private readonly _bufferedOutput;
70 static readonly filename: string;
71 constructor(globalConfig: Config.GlobalConfig);
72 protected __wrapStdio(
73 stream: NodeJS.WritableStream | NodeJS.WriteStream,
74 ): void;
75 forceFlushBufferedOutput(): void;
76 protected __clearStatus(): void;
77 protected __printStatus(): void;
78 onRunStart(
79 aggregatedResults: AggregatedResult,
80 options: ReporterOnStartOptions,
81 ): void;
82 onTestStart(test: Test): void;
83 onTestCaseResult(test: Test, testCaseResult: TestCaseResult): void;
84 onRunComplete(): void;
85 onTestResult(
86 test: Test,
87 testResult: TestResult,
88 aggregatedResults: AggregatedResult,
89 ): void;
90 testFinished(
91 config: Config.ProjectConfig,
92 testResult: TestResult,
93 aggregatedResults: AggregatedResult,
94 ): void;
95 printTestFileHeader(
96 testPath: string,
97 config: Config.ProjectConfig,
98 result: TestResult,
99 ): void;
100 printTestFileFailureMessage(
101 _testPath: string,
102 _config: Config.ProjectConfig,
103 result: TestResult,
104 ): void;
105}
106
107declare function formatTestPath(
108 config: Config.GlobalConfig | Config.ProjectConfig,
109 testPath: string,
110): string;
111
112declare function getResultHeader(
113 result: TestResult,
114 globalConfig: Config.GlobalConfig,
115 projectConfig?: Config.ProjectConfig,
116): string;
117
118declare function getSnapshotStatus(
119 snapshot: TestResult['snapshot'],
120 afterUpdate: boolean,
121): Array<string>;
122
123declare function getSnapshotSummary(
124 snapshots: SnapshotSummary,
125 globalConfig: Config.GlobalConfig,
126 updateCommand: string,
127): Array<string>;
128
129declare function getSummary(
130 aggregatedResults: AggregatedResult,
131 options?: SummaryOptions,
132): string;
133
134export declare class GitHubActionsReporter extends BaseReporter {
135 #private;
136 static readonly filename: string;
137 onTestFileResult({context}: Test, {testResults}: TestResult): void;
138}
139
140export declare class NotifyReporter extends BaseReporter {
141 private readonly _notifier;
142 private readonly _globalConfig;
143 private _context;
144 static readonly filename: string;
145 constructor(globalConfig: Config.GlobalConfig, context: ReporterContext);
146 onRunComplete(testContexts: Set<TestContext>, result: AggregatedResult): void;
147}
148
149declare function printDisplayName(config: Config.ProjectConfig): string;
150
151declare function relativePath(
152 config: Config.GlobalConfig | Config.ProjectConfig,
153 testPath: string,
154): {
155 basename: string;
156 dirname: string;
157};
158
159export declare interface Reporter {
160 readonly onTestResult?: (
161 test: Test,
162 testResult: TestResult,
163 aggregatedResult: AggregatedResult,
164 ) => Promise<void> | void;
165 readonly onTestFileResult?: (
166 test: Test,
167 testResult: TestResult,
168 aggregatedResult: AggregatedResult,
169 ) => Promise<void> | void;
170 readonly onTestCaseResult?: (
171 test: Test,
172 testCaseResult: TestCaseResult,
173 ) => Promise<void> | void;
174 readonly onRunStart: (
175 results: AggregatedResult,
176 options: ReporterOnStartOptions,
177 ) => Promise<void> | void;
178 readonly onTestStart?: (test: Test) => Promise<void> | void;
179 readonly onTestFileStart?: (test: Test) => Promise<void> | void;
180 readonly onRunComplete: (
181 testContexts: Set<TestContext>,
182 results: AggregatedResult,
183 ) => Promise<void> | void;
184 readonly getLastError: () => Error | void;
185}
186
187export declare type ReporterContext = {
188 firstRun: boolean;
189 previousSuccess: boolean;
190 changedFiles?: Set<string>;
191 sourcesRelatedToTestsInChangedFiles?: Set<string>;
192 startRun?: (globalConfig: Config.GlobalConfig) => unknown;
193};
194
195export declare type ReporterOnStartOptions = {
196 estimatedTime: number;
197 showStatus: boolean;
198};
199
200export {SnapshotSummary};
201
202export declare type SummaryOptions = {
203 currentTestCases?: Array<{
204 test: Test;
205 testCaseResult: TestCaseResult;
206 }>;
207 estimatedTime?: number;
208 roundTime?: boolean;
209 width?: number;
210 showSeed?: boolean;
211 seed?: number;
212};
213
214export declare class SummaryReporter extends BaseReporter {
215 private _estimatedTime;
216 private readonly _globalConfig;
217 static readonly filename: string;
218 constructor(globalConfig: Config.GlobalConfig);
219 private _write;
220 onRunStart(
221 aggregatedResults: AggregatedResult,
222 options: ReporterOnStartOptions,
223 ): void;
224 onRunComplete(
225 testContexts: Set<TestContext>,
226 aggregatedResults: AggregatedResult,
227 ): void;
228 private _printSnapshotSummary;
229 private _printSummary;
230 private _getTestSummary;
231}
232
233export {Test};
234
235export {TestCaseResult};
236
237export {TestContext};
238
239export {TestResult};
240
241declare function trimAndFormatPath(
242 pad: number,
243 config: Config.ProjectConfig | Config.GlobalConfig,
244 testPath: string,
245 columns: number,
246): string;
247
248export declare const utils: {
249 formatTestPath: typeof formatTestPath;
250 getResultHeader: typeof getResultHeader;
251 getSnapshotStatus: typeof getSnapshotStatus;
252 getSnapshotSummary: typeof getSnapshotSummary;
253 getSummary: typeof getSummary;
254 printDisplayName: typeof printDisplayName;
255 relativePath: typeof relativePath;
256 trimAndFormatPath: typeof trimAndFormatPath;
257};
258
259export declare class VerboseReporter extends DefaultReporter {
260 protected _globalConfig: Config.GlobalConfig;
261 static readonly filename: string;
262 constructor(globalConfig: Config.GlobalConfig);
263 protected __wrapStdio(
264 stream: NodeJS.WritableStream | NodeJS.WriteStream,
265 ): void;
266 static filterTestResults(
267 testResults: Array<AssertionResult>,
268 ): Array<AssertionResult>;
269 static groupTestsBySuites(testResults: Array<AssertionResult>): Suite;
270 onTestResult(
271 test: Test,
272 result: TestResult,
273 aggregatedResults: AggregatedResult,
274 ): void;
275 private _logTestResults;
276 private _logSuite;
277 private _getIcon;
278 private _logTest;
279 private _logTests;
280 private _logTodoOrPendingTest;
281 private _logLine;
282}
283
284export {};