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

This commit is contained in:
Max Schmitt 2022-08-20 12:20:31 +02:00 committed by GitHub
parent 2142fde460
commit 35a9daa425
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 {
{