Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

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

Dmitry Gozman5e471a3ecea8
diff --git a/src/test/reporter.ts b/src/test/reporter.ts
index e9b29050b3..6b15b9d46d 100644
--- a/src/test/reporter.ts
+++ b/src/test/reporter.ts
@@ -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;
diff --git a/src/test/util.ts b/src/test/util.ts
index eda9131141..6937179d15 100644
--- a/src/test/util.ts
+++ b/src/test/util.ts
@@ -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 = [
diff --git a/types/test.d.ts b/types/test.d.ts
index db9136862e..c659e54e7c 100644
--- a/types/test.d.ts
+++ b/types/test.d.ts
@@ -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.