From 9e3ac1f3a283080e71912b52eb25e4b4a4e9a221 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Thu, 22 Jul 2021 18:27:01 +0200 Subject: [PATCH] fix(test-runner): warn users who invoke the test-runner with Jest (#7743) --- src/test/testType.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/testType.ts b/src/test/testType.ts index 2aad99ea0e..d715f2a142 100644 --- a/src/test/testType.ts +++ b/src/test/testType.ts @@ -55,6 +55,7 @@ export class TestTypeImpl { } private _createTest(type: 'default' | 'only', location: Location, title: string, fn: Function) { + throwIfRunningInsideJest(); const suite = currentlyLoadingFileSuite(); if (!suite) throw new Error(`test() can only be called in a test file`); @@ -71,6 +72,7 @@ export class TestTypeImpl { } private _describe(type: 'default' | 'only', location: Location, title: string, fn: Function) { + throwIfRunningInsideJest(); const suite = currentlyLoadingFileSuite(); if (!suite) throw new Error(`describe() can only be called in a test file`); @@ -151,4 +153,14 @@ export class TestTypeImpl { } } +function throwIfRunningInsideJest() { + if (process.env.JEST_WORKER_ID) { + throw new Error( + `Playwright Test needs to be invoked via 'npx playwright test' and excluded from Jest test runs.\n` + + `Creating one directory for Playwright tests and one for Jest is the recommended way of doing it.\n` + + `See https://playwright.dev/docs/intro/ for more information about Playwright Test.`, + ); + } +} + export const rootTestType = new TestTypeImpl([]);