feat: print message if maxFailures has reached (#26322)
Fixes https://github.com/microsoft/playwright/issues/24239
This commit is contained in:
parent
70dcaabdee
commit
9ae77a71fd
|
|
@ -55,6 +55,7 @@ export class BaseReporter implements ReporterV2 {
|
||||||
private _omitFailures: boolean;
|
private _omitFailures: boolean;
|
||||||
private readonly _ttyWidthForTest: number;
|
private readonly _ttyWidthForTest: number;
|
||||||
private _fatalErrors: TestError[] = [];
|
private _fatalErrors: TestError[] = [];
|
||||||
|
private _failureCount: number = 0;
|
||||||
|
|
||||||
constructor(options: { omitFailures?: boolean } = {}) {
|
constructor(options: { omitFailures?: boolean } = {}) {
|
||||||
this._omitFailures = options.omitFailures || false;
|
this._omitFailures = options.omitFailures || false;
|
||||||
|
|
@ -94,6 +95,8 @@ export class BaseReporter implements ReporterV2 {
|
||||||
}
|
}
|
||||||
|
|
||||||
onTestEnd(test: TestCase, result: TestResult) {
|
onTestEnd(test: TestCase, result: TestResult) {
|
||||||
|
if (result.status !== 'skipped' && result.status !== test.expectedStatus)
|
||||||
|
++this._failureCount;
|
||||||
// Ignore any tests that are run in parallel.
|
// Ignore any tests that are run in parallel.
|
||||||
for (let suite: Suite | undefined = test.parent; suite; suite = suite.parent) {
|
for (let suite: Suite | undefined = test.parent; suite; suite = suite.parent) {
|
||||||
if ((suite as SuitePrivate)._parallelMode === 'parallel')
|
if ((suite as SuitePrivate)._parallelMode === 'parallel')
|
||||||
|
|
@ -232,6 +235,7 @@ export class BaseReporter implements ReporterV2 {
|
||||||
if (full && summary.failuresToPrint.length && !this._omitFailures)
|
if (full && summary.failuresToPrint.length && !this._omitFailures)
|
||||||
this._printFailures(summary.failuresToPrint);
|
this._printFailures(summary.failuresToPrint);
|
||||||
this._printSlowTests();
|
this._printSlowTests();
|
||||||
|
this._printMaxFailuresReached();
|
||||||
this._printSummary(summaryMessage);
|
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'));
|
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) {
|
private _printSummary(summary: string) {
|
||||||
if (summary.trim())
|
if (summary.trim())
|
||||||
console.log(summary);
|
console.log(summary);
|
||||||
|
|
|
||||||
|
|
@ -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 (`);
|
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 }) => {
|
test('should not print slow parallel tests', async ({ runInlineTest }) => {
|
||||||
const result = await runInlineTest({
|
const result = await runInlineTest({
|
||||||
'playwright.config.ts': `
|
'playwright.config.ts': `
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue