Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(test-runner): warn users who invoke the test-runner with Jest (#7743)

Max Schmitt9e3ac1f3a283
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([]);