chore: update "X fatal errors" message (#16325)

Also, exlude certain errors from triggering this message:
- `no tests found`
- `duplicate test titles are not allowed`
- `--forbid-only found a focused test`
- `Timed out waiting 3600s for the entire test run`
This commit is contained in:
Dmitry Gozman 2022-08-05 21:21:43 -07:00 коммит произвёл GitHub
Родитель 8ed238843b
Коммит f6d94f0ac9
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 6 добавлений и 5 удалений

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

@ -98,7 +98,8 @@ export class BaseReporter implements ReporterInternal {
}
onError(error: TestError) {
this._fatalErrors.push(error);
if (!(error as any).__isNotAFatalError)
this._fatalErrors.push(error);
}
async onEnd(result: FullResult) {
@ -136,8 +137,6 @@ export class BaseReporter implements ReporterInternal {
protected generateSummaryMessage({ skipped, expected, interrupted, unexpected, flaky, fatalErrors }: TestSummary) {
const tokens: string[] = [];
if (fatalErrors.length)
tokens.push(colors.red(` ${fatalErrors.length} fatal ${fatalErrors.length === 1 ? 'error' : 'errors'}`));
if (unexpected.length) {
tokens.push(colors.red(` ${unexpected.length} failed`));
for (const test of unexpected)
@ -159,6 +158,8 @@ export class BaseReporter implements ReporterInternal {
tokens.push(colors.green(` ${expected} passed`) + colors.dim(` (${milliseconds(this.duration)})`));
if (this.result.status === 'timedout')
tokens.push(colors.red(` Timed out waiting ${this.config.globalTimeout / 1000}s for the entire test run`));
if (fatalErrors.length)
tokens.push(colors.red(` ${fatalErrors.length === 1 ? '1 error was not a part of any test' : fatalErrors.length + ' errors were not a part of any test'}, see above for details`));
return tokens.join('\n');
}

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

@ -971,7 +971,7 @@ function createNoTestsError(): TestError {
}
function createStacklessError(message: string): TestError {
return { message };
return { message, __isNotAFatalError: true } as any;
}
export const builtInReporters = ['list', 'line', 'dot', 'json', 'junit', 'null', 'github', 'html'] as const;

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

@ -316,5 +316,5 @@ test('should report fatal errors at the end', async ({ runInlineTest }) => {
}, { reporter: 'list' });
expect(result.exitCode).toBe(1);
expect(result.passed).toBe(2);
expect(stripAnsi(result.output)).toContain('2 fatal errors');
expect(stripAnsi(result.output)).toContain('2 errors were not a part of any test, see above for details');
});