Skip to content

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

fix(reporter): print inline failure for non-retriable errors (#41026)

Yury Semikhatsky17c003c41405
diff --git a/packages/playwright/src/reporters/list.ts b/packages/playwright/src/reporters/list.ts
index 1ded22453d..58dff8deec 100644
--- a/packages/playwright/src/reporters/list.ts
+++ b/packages/playwright/src/reporters/list.ts
@@ -194,7 +194,8 @@ class ListReporter extends TerminalReporter {
const wasPaused = this._paused.delete(result);
if (!wasPaused)
this._updateTestLine(test, result);
- if (!wasPaused && this._printFailuresInline && !this.willRetry(test) && (test.outcome() === 'flaky' || test.outcome() === 'unexpected' || result.status === 'interrupted'))
+ const isFailure = result.status !== 'skipped' && result.status !== test.expectedStatus;
+ if (!wasPaused && this._printFailuresInline && isFailure)
this._printFailure(test);
}
diff --git a/tests/page/page-request-fulfill.spec.ts-snapshots/mock-binary-response-webkit-webview.png b/tests/page/page-request-fulfill.spec.ts-snapshots/mock-binary-response-webkit-webview.png
new file mode 100644
index 0000000000..62914006a6
Binary files /dev/null and b/tests/page/page-request-fulfill.spec.ts-snapshots/mock-binary-response-webkit-webview.png differ
diff --git a/tests/playwright-test/reporter-list.spec.ts b/tests/playwright-test/reporter-list.spec.ts
index 8c5c5707a1..fe333c6e12 100644
--- a/tests/playwright-test/reporter-list.spec.ts
+++ b/tests/playwright-test/reporter-list.spec.ts
@@ -288,6 +288,34 @@ for (const useIntermediateMergeReport of [false, true] as const) {
expect(result.exitCode).toBe(1);
});
+ test('print failures inline for a non-retriable error', async ({ runInlineTest }) => {
+ // A missing snapshot fails the test but is not retried. The reporter must
+ // still print the failure inline, even though the retry budget is not exhausted.
+ const result = await runInlineTest({
+ 'playwright.config.ts': `
+ module.exports = {
+ reporter: [['list', { printFailuresInline: true }]],
+ retries: 1,
+ workers: 1,
+ };
+ `,
+ 'a.test.ts': `
+ import { test, expect } from '@playwright/test';
+ test('missing snapshot', async ({}) => {
+ expect('actual').toMatchSnapshot('foo.txt');
+ });
+ `,
+ });
+ const text = result.output;
+ const failureHeader = '1) a.test.ts:3:15 › missing snapshot';
+ const failureIndex = text.indexOf(failureHeader);
+ expect(failureIndex, 'failure should be printed inline').not.toBe(-1);
+ expect(text.indexOf(`A snapshot doesn't exist`, failureIndex)).toBeGreaterThan(failureIndex);
+ // It must not be retried, so there is exactly one failure block.
+ expect(text.indexOf(failureHeader, failureIndex + 1)).toBe(-1);
+ expect(result.exitCode).toBe(1);
+ });
+
test('print stdio', async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.test.ts': `