diff --git a/packages/playwright-test/src/runner.ts b/packages/playwright-test/src/runner.ts index f5be83b103..335778265b 100644 --- a/packages/playwright-test/src/runner.ts +++ b/packages/playwright-test/src/runner.ts @@ -144,6 +144,8 @@ export class Runner { else this._reporter.onError?.(createStacklessError(`Timed out waiting ${config.globalTimeout / 1000}s for the entire test run`)); return actualResult; + } else if (this._didBegin) { + await this._reporter.onEnd?.(result.result); } return result.result; } catch (e) { @@ -384,13 +386,11 @@ export class Runner { if (sigint) { const result: FullResult = { status: 'interrupted' }; - await this._reporter.onEnd?.(result); return result; } const failed = hasWorkerErrors || rootSuite.allTests().some(test => !test.ok()); const result: FullResult = { status: failed ? 'failed' : 'passed' }; - await this._reporter.onEnd?.(result); return result; } finally { if (globalSetupResult && typeof globalSetupResult === 'function') diff --git a/tests/playwright-test/reporter.spec.ts b/tests/playwright-test/reporter.spec.ts index bffd0e5c62..2425979a2e 100644 --- a/tests/playwright-test/reporter.spec.ts +++ b/tests/playwright-test/reporter.spec.ts @@ -176,6 +176,35 @@ test('should work without a file extension', async ({ runInlineTest }) => { ]); }); +test('should report onEnd after global teardown', async ({ runInlineTest }) => { + const result = await runInlineTest({ + 'reporter.ts': smallReporterJS, + 'globalSetup.ts': ` + module.exports = () => { + return () => console.log('\\n%%global teardown'); + }; + `, + 'playwright.config.ts': ` + module.exports = { + reporter: './reporter', + globalSetup: './globalSetup', + }; + `, + 'a.test.ts': ` + const { test } = pwt; + test('pass', async ({}) => { + }); + ` + }, { reporter: '', workers: 1 }); + + expect(result.exitCode).toBe(0); + expect(result.output.split('\n').filter(line => line.startsWith('%%'))).toEqual([ + '%%begin', + '%%global teardown', + '%%end', + ]); +}); + test('should load reporter from node_modules', async ({ runInlineTest }) => { const result = await runInlineTest({ 'node_modules/my-reporter/index.js': smallReporterJS,