diff --git a/docs/src/test-api/class-testinfoerror.md b/docs/src/test-api/class-testinfoerror.md index 194990079f..1af877d952 100644 --- a/docs/src/test-api/class-testinfoerror.md +++ b/docs/src/test-api/class-testinfoerror.md @@ -8,7 +8,7 @@ Information about an error thrown during test execution. * since: v1.49 - type: ?<[TestInfoError]> -Error cause. Set when there is a [cause](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause) for the error. Will be null if there is no cause or if the cause is not an instance of [Error] (or its subclass). +Error cause. Set when there is a [cause](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause) for the error. Will be `undefined` if there is no cause or if the cause is not an instance of [Error] ## property: TestInfoError.message * since: v1.10 diff --git a/docs/src/test-reporter-api/class-testerror.md b/docs/src/test-reporter-api/class-testerror.md index f9e695737c..ea3ea1db38 100644 --- a/docs/src/test-reporter-api/class-testerror.md +++ b/docs/src/test-reporter-api/class-testerror.md @@ -8,7 +8,7 @@ Information about an error thrown during test execution. * since: v1.49 - type: ?<[TestError]> -Error cause. Set when there is a [cause](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause) for the error. Will be null if there is no cause or if the cause is not an instance of [Error] (or its subclass). +Error cause. Set when there is a [cause](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause) for the error. Will be `undefined` if there is no cause or if the cause is not an instance of [Error] ## property: TestError.message * since: v1.10 diff --git a/packages/playwright/src/reporters/base.ts b/packages/playwright/src/reporters/base.ts index 5c09e4b704..9bb5da81f6 100644 --- a/packages/playwright/src/reporters/base.ts +++ b/packages/playwright/src/reporters/base.ts @@ -441,10 +441,8 @@ export function formatError(error: TestError, highlightCode: boolean): ErrorDeta if (parsedStack && !location) location = parsedStack.location; - if (error.cause) { - tokens.push(); - tokens.push(indent(colors.dim('[cause]: ') + formatError(error.cause, highlightCode).message, ' ')); - } + if (error.cause) + tokens.push(colors.dim('[cause]: ') + formatError(error.cause, highlightCode).message); return { location, diff --git a/packages/playwright/types/test.d.ts b/packages/playwright/types/test.d.ts index de361c7b89..ba48f00cb9 100644 --- a/packages/playwright/types/test.d.ts +++ b/packages/playwright/types/test.d.ts @@ -9155,7 +9155,7 @@ export interface TestInfoError { /** * Error cause. Set when there is a * [cause](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause) for the - * error. Will be null if there is no cause or if the cause is not an instance of [Error] (or its subclass). + * error. Will be `undefined` if there is no cause or if the cause is not an instance of [Error] */ cause?: TestInfoError; diff --git a/packages/playwright/types/testReporter.d.ts b/packages/playwright/types/testReporter.d.ts index 69d1c0578e..6807c7aec0 100644 --- a/packages/playwright/types/testReporter.d.ts +++ b/packages/playwright/types/testReporter.d.ts @@ -557,7 +557,7 @@ export interface TestError { /** * Error cause. Set when there is a * [cause](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause) for the - * error. Will be null if there is no cause or if the cause is not an instance of [Error] (or its subclass). + * error. Will be `undefined` if there is no cause or if the cause is not an instance of [Error] */ cause?: TestError; diff --git a/tests/playwright-test/reporter-base.spec.ts b/tests/playwright-test/reporter-base.spec.ts index 7eb41f29eb..dabb2bbaa4 100644 --- a/tests/playwright-test/reporter-base.spec.ts +++ b/tests/playwright-test/reporter-base.spec.ts @@ -156,12 +156,12 @@ for (const useIntermediateMergeReport of [false, true] as const) { expect(result.failed).toBe(1); const testFile = path.join(result.report.config.rootDir, result.report.suites[0].specs[0].file); expect(result.output).toContain(` at ${testFile}:18:21`); - expect(result.output).toContain(` [cause]: Error: outer-message`); - expect(result.output).toContain(` at ${testFile}:14:25`); - expect(result.output).toContain(` [cause]: Error: inner-message`); - expect(result.output).toContain(` at ${testFile}:12:25`); - expect(result.output).toContain(` [cause]: SpecialError: my-message`); - expect(result.output).toContain(` at ${testFile}:7:31`); + expect(result.output).toContain(` [cause]: Error: outer-message`); + expect(result.output).toContain(` at ${testFile}:14:25`); + expect(result.output).toContain(` [cause]: Error: inner-message`); + expect(result.output).toContain(` at ${testFile}:12:25`); + expect(result.output).toContain(` [cause]: SpecialError: my-message`); + expect(result.output).toContain(` at ${testFile}:7:31`); expect(result.output).toContain('afterAll executed successfully'); });