feat: print message if maxFailures has reached (#26322)

Fixes https://github.com/microsoft/playwright/issues/24239
This commit is contained in:
Max Schmitt 2023-08-25 19:06:49 +02:00 коммит произвёл GitHub
Родитель 70dcaabdee
Коммит 9ae77a71fd
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 37 добавлений и 0 удалений

Просмотреть файл

@ -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);

Просмотреть файл

@ -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': `