Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
feat: print message if maxFailures has reached (#26322)
Max Schmitt9ae77a71fd68
diff --git a/packages/playwright-test/src/reporters/base.ts b/packages/playwright-test/src/reporters/base.tsindex 12d1d0fe33..33e384f10c 100644--- a/packages/playwright-test/src/reporters/base.ts+++ b/packages/playwright-test/src/reporters/base.ts@@ -55,6 +55,7 @@ export class BaseReporter implements ReporterV2 {private _omitFailures: boolean;private readonly _ttyWidthForTest: number;private _fatalErrors: TestError[] = [];+ private _failureCount: number = 0;constructor(options: { omitFailures?: boolean } = {}) {this._omitFailures = options.omitFailures || false;@@ -94,6 +95,8 @@ export class BaseReporter implements ReporterV2 {}onTestEnd(test: TestCase, result: TestResult) {+ if (result.status !== 'skipped' && result.status !== test.expectedStatus)+ ++this._failureCount;// Ignore any tests that are run in parallel.for (let suite: Suite | undefined = test.parent; suite; suite = suite.parent) {if ((suite as SuitePrivate)._parallelMode === 'parallel')@@ -232,6 +235,7 @@ export class BaseReporter implements ReporterV2 {if (full && summary.failuresToPrint.length && !this._omitFailures)this._printFailures(summary.failuresToPrint);this._printSlowTests();+ this._printMaxFailuresReached();this._printSummary(summaryMessage);}@@ -253,6 +257,12 @@ export class BaseReporter implements ReporterV2 {console.log(colors.yellow(' Consider splitting slow test files to speed up parallel execution'));}+ private _printMaxFailuresReached() {+ if (this.config.maxFailures && this._failureCount < this.config.maxFailures)+ return;+ console.log(colors.yellow(`Testing stopped early after ${this.config.maxFailures} maximum allowed failures.`));+ }+private _printSummary(summary: string) {if (summary.trim())console.log(summary);diff --git a/tests/playwright-test/reporter-base.spec.ts b/tests/playwright-test/reporter-base.spec.tsindex 494180ec53..7b0c5a40a4 100644--- a/tests/playwright-test/reporter-base.spec.ts+++ b/tests/playwright-test/reporter-base.spec.ts@@ -182,6 +182,33 @@ for (const useIntermediateMergeReport of [false, true] as const) {expect(result.output).not.toContain(`Slow test file: [qux] › dir${path.sep}b.test.js (`);});+ test('should print if maxFailures is reached', async ({ runInlineTest }) => {+ const result = await runInlineTest({+ 'playwright.config.ts': `+ module.exports = {+ maxFailures: 1,+ };+ `,+ 'dir/a.test.js': `+ import { test, expect } from '@playwright/test';+ test('failing1', async ({}) => {+ expect(1).toBe(2);+ });+ test('failing2', async ({}) => {+ expect(1).toBe(2);+ });+ test('failing3', async ({}) => {+ expect(1).toBe(2);+ });+ `,+ });+ expect(result.exitCode).toBe(1);+ expect(result.failed).toBe(1);+ expect(result.passed).toBe(0);+ expect(result.skipped).toBe(2);+ expect(result.output).toContain('Testing stopped early after 1 maximum allowed failures.');+ });+test('should not print slow parallel tests', async ({ runInlineTest }) => {const result = await runInlineTest({'playwright.config.ts': `