From e5ba0d6846e6c811b8de1e5f864ae59d3372c132 Mon Sep 17 00:00:00 2001 From: Ross Wollman Date: Fri, 1 Apr 2022 12:35:25 -0700 Subject: [PATCH] test: ensure tests do not run after globalSetup fail (#13255) Resolves #13244 --- tests/playwright-test/global-setup.spec.ts | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/tests/playwright-test/global-setup.spec.ts b/tests/playwright-test/global-setup.spec.ts index c82fbc7f07..83e73ff258 100644 --- a/tests/playwright-test/global-setup.spec.ts +++ b/tests/playwright-test/global-setup.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { test, expect } from './playwright-test-fixtures'; +import { test, expect, stripAnsi } from './playwright-test-fixtures'; for (const mode of ['legacy', 'default']) { test.describe(`${mode} mode`, () => { @@ -143,6 +143,35 @@ for (const mode of ['legacy', 'default']) { expect(passed).toBe(1); }); + test('globalSetup error should prevent tests from executing', async ({ runInlineTest }) => { + const { passed, output } = await runInlineTest({ + 'playwright.config.ts': ` + import * as path from 'path'; + module.exports = { + globalSetup: './globalSetup.ts', + }; + `, + 'globalSetup.ts': ` + module.exports = () => { + throw new Error('failure in global setup!'); + }; + `, + 'a.test.js': ` + const { test } = pwt; + test('a', async ({}) => { + console.log('this test ran'); + }); + + test('b', async ({}) => { + console.log('this test ran'); + }); + `, + }, { reporter: 'line' }, env); + + expect(stripAnsi(output)).not.toContain('this test ran'); + expect(passed).toBe(0); + }); + test('globalSetup should throw when passed non-function', async ({ runInlineTest }) => { const { output } = await runInlineTest({ 'playwright.config.ts': `