fix(github reporter): handle global onError (#10256)

This commit is contained in:
Dmitry Gozman 2021-11-11 13:25:38 -08:00 committed by GitHub
parent 8fe3ea7972
commit 4c93417e8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 3 deletions

View File

@ -16,8 +16,8 @@
import milliseconds from 'ms';
import path from 'path';
import { BaseReporter, formatFailure, stripAnsiEscapes } from './base';
import { TestCase, FullResult } from '../../types/testReporter';
import { BaseReporter, formatError, formatFailure, stripAnsiEscapes } from './base';
import { TestCase, FullResult, TestError } from '../../types/testReporter';
type GitHubLogType = 'debug' | 'notice' | 'warning' | 'error';
@ -68,6 +68,11 @@ export class GitHubReporter extends BaseReporter {
this._printAnnotations();
}
override onError(error: TestError) {
const errorMessage = formatError(error, false).message;
this.githubLogger.error(errorMessage);
}
private _printAnnotations() {
const summary = this.generateSummary();
const summaryMessage = this.generateSummaryMessage(summary);

View File

@ -73,4 +73,22 @@ test('print GitHub annotations for slow tests', async ({ runInlineTest }) => {
expect(text).toContain('::warning title=Slow Test,file=a.test.js::a.test.js took');
expect(text).toContain('::notice title=🎭 Playwright Run Summary:: 1 passed');
expect(result.exitCode).toBe(0);
});
});
test('print GitHub annotations for global error', async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.test.js': `
const test = pwt.test.extend({
w: [async ({}, use) => {
await use();
throw new Error('Oh my!');
}, { scope: 'worker' }],
});
test('passes but...', ({w}) => {
});
`,
}, { reporter: 'github' });
const text = stripAscii(result.output);
expect(text).toContain('::error ::%0AError: Oh my!%0A%0A');
expect(result.exitCode).toBe(1);
});