diff --git a/packages/playwright-test/src/reporters/github.ts b/packages/playwright-test/src/reporters/github.ts index 11453bee64..757589a6a7 100644 --- a/packages/playwright-test/src/reporters/github.ts +++ b/packages/playwright-test/src/reporters/github.ts @@ -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); diff --git a/tests/playwright-test/reporter-github.spec.ts b/tests/playwright-test/reporter-github.spec.ts index e4bcef8387..a7f242c6b9 100644 --- a/tests/playwright-test/reporter-github.spec.ts +++ b/tests/playwright-test/reporter-github.spec.ts @@ -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); -}); \ No newline at end of file +}); + +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); +});