From 85cb3c9713dd124911cc5ae0ae5b9f029788e0c3 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Tue, 15 Feb 2022 18:05:20 -0800 Subject: [PATCH] test: add a test that fixture error after timeout is not a fatal error (#12141) --- tests/playwright-test/fixture-errors.spec.ts | 24 ++++++++++++++++++++ tests/playwright-test/reporter-html.spec.ts | 4 ++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/tests/playwright-test/fixture-errors.spec.ts b/tests/playwright-test/fixture-errors.spec.ts index 4b108d4ce1..03ba3d5ea4 100644 --- a/tests/playwright-test/fixture-errors.spec.ts +++ b/tests/playwright-test/fixture-errors.spec.ts @@ -455,3 +455,27 @@ test('should not report fixture teardown error twice', async ({ runInlineTest }) expect(stripAnsi(result.output)).toContain(`throw new Error('Oh my error')`); expect(countTimes(result.output, 'Oh my error')).toBe(2); }); + +test('should handle fixture teardown error after test timeout and continue', async ({ runInlineTest }) => { + const result = await runInlineTest({ + 'a.spec.ts': ` + const test = pwt.test.extend({ + fixture: async ({ }, use) => { + await use(); + throw new Error('Oh my error'); + }, + }); + test('bad', async ({ fixture }) => { + test.setTimeout(100); + await new Promise(f => setTimeout(f, 500)); + }); + test('good', async ({}) => { + }); + `, + }, { reporter: 'list', workers: '1' }); + expect(result.exitCode).toBe(1); + expect(result.failed).toBe(1); + expect(result.passed).toBe(1); + expect(result.output).toContain('Timeout of 100ms exceeded'); + expect(result.output).toContain('Error: Oh my error'); +}); diff --git a/tests/playwright-test/reporter-html.spec.ts b/tests/playwright-test/reporter-html.spec.ts index 64ac0dbffe..d56bd15b79 100644 --- a/tests/playwright-test/reporter-html.spec.ts +++ b/tests/playwright-test/reporter-html.spec.ts @@ -20,14 +20,14 @@ import { startHtmlReportServer } from '../../packages/playwright-test/lib/report const test = baseTest.extend<{ showReport: () => Promise }>({ showReport: async ({ page }, use, testInfo) => { - let server: HttpServer; + let server: HttpServer | undefined; await use(async () => { const reportFolder = testInfo.outputPath('playwright-report'); server = startHtmlReportServer(reportFolder); const location = await server.start(); await page.goto(location); }); - await server.stop(); + await server?.stop(); } });