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

This commit is contained in:
Max Schmitt 2021-07-22 18:27:01 +02:00 committed by GitHub
parent 3c4ef9f11d
commit 9e3ac1f3a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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