feat(test runner): add type to TestInfo.error (#7207)

It has a very special `TestError` type, but we say it's `any` for some reason.
This commit is contained in:
Dmitry Gozman 2021-06-17 12:14:28 -07:00 committed by GitHub
parent 1a9a5d8e9a
commit 5e471a3ece
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 10 deletions

View File

@ -14,8 +14,8 @@
* limitations under the License.
*/
import type { FullConfig, TestStatus } from './types';
export type { FullConfig, TestStatus } from './types';
import type { FullConfig, TestStatus, TestError } from './types';
export type { FullConfig, TestStatus, TestError } from './types';
export interface Suite {
title: string;
@ -60,11 +60,6 @@ export interface TestResult {
stdout: (string | Buffer)[];
stderr: (string | Buffer)[];
}
export interface TestError {
message?: string;
stack?: string;
value?: string;
}
export interface Reporter {
onBegin(config: FullConfig, suite: Suite): void;
onTestBegin(test: Test): void;

View File

@ -17,8 +17,7 @@
import path from 'path';
import util from 'util';
import StackUtils from 'stack-utils';
import type { Location } from './types';
import type { TestError } from './reporter';
import type { Location, TestError } from './types';
import { default as minimatch } from 'minimatch';
const TEST_RUNNER_DIRS = [

22
types/test.d.ts vendored
View File

@ -237,6 +237,26 @@ export interface FullConfig {
export type TestStatus = 'passed' | 'failed' | 'timedOut' | 'skipped';
/**
* Information about an error caught during test execution.
*/
export interface TestError {
/**
* Error message. Set when Error (or its subclass) has been thrown.
*/
message?: string;
/**
* Error stack. Set when Error (or its subclass) has been thrown.
*/
stack?: string;
/**
* The thrown value. Set when anything except the Error (or its subclass) has been thrown.
*/
value?: string;
}
/**
* Information common for all tests run in the same worker process.
*/
@ -367,7 +387,7 @@ export interface TestInfo extends WorkerInfo {
* The error thrown by the test if any.
* Only available after the test has finished.
*/
error?: any;
error?: TestError;
/**
* Output written to `process.stdout` or `console.log` from the test.