Skip to content

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

chore: validate pw-core version when pwtest CLI gets executed (#16475)

Max Schmitt35a9daa4255f
diff --git a/packages/playwright-core/src/cli/cli.ts b/packages/playwright-core/src/cli/cli.ts
index 9ea363550f..ba9fe78eec 100755
--- a/packages/playwright-core/src/cli/cli.ts
+++ b/packages/playwright-core/src/cli/cli.ts
@@ -309,13 +309,33 @@ Examples:
if (!process.env.PW_LANG_NAME) {
let playwrightTestPackagePath = null;
+ const resolvePwTestPaths = [__dirname, process.cwd()];
try {
playwrightTestPackagePath = require.resolve('@playwright/test/lib/cli', {
- paths: [__dirname, process.cwd()]
+ paths: resolvePwTestPaths,
});
} catch {}
if (playwrightTestPackagePath) {
+ const pwTestVersion = require(require.resolve('@playwright/test/package.json', {
+ paths: resolvePwTestPaths,
+ })).version;
+ const pwCoreVersion = require(path.join(__dirname, '../../package.json')).version;
+ if (pwTestVersion !== pwCoreVersion) {
+ let hasPlaywrightPackage = false;
+ try {
+ require('playwright');
+ hasPlaywrightPackage = true;
+ } catch {}
+ console.error(wrapInASCIIBox([
+ `Playwright Test compatibility check failed:`,
+ `@playwright/test version '${pwTestVersion}' does not match ${hasPlaywrightPackage ? 'playwright' : 'playwright-core'} version '${pwCoreVersion}'!`,
+ `To fix this either align the versions or only keep @playwright/test since it depends on playwright-core.`,
+ `If you still receive this error, execute 'npm ci' or delete 'node_modules' and do 'npm install' again.`,
+ ].join('\n'), 1));
+ process.exit(1);
+ }
+
require(playwrightTestPackagePath).addTestCommands(program);
} else {
{