Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: find experimental-ct-core cli as a fallback #415

Merged
merged 2 commits into from
Feb 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/playwrightTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,21 @@ export class PlaywrightTest {
}

async getPlaywrightInfo(workspaceFolder: string, configFilePath: string): Promise<{ version: number, cli: string }> {
try {
return await this._getPlaywrightInfoImpl(workspaceFolder, configFilePath, '@playwright/test');
} catch (error) {
// In order to support component testing
return await this._getPlaywrightInfoImpl(workspaceFolder, configFilePath, 'playwright');
}
}

private async _getPlaywrightInfoImpl(workspaceFolder: string, configFilePath: string, cliPackage: string): Promise<{ version: number, cli: string }> {
const pwtInfo = await this._runNode([
'-e',
'try { const pwtIndex = require.resolve("@playwright/test"); const version = require("@playwright/test/package.json").version; console.log(JSON.stringify({ pwtIndex, version})); } catch { console.log("undefined"); }',
`try { const pwtIndex = require.resolve("${cliPackage}"); const version = require("${cliPackage}/package.json").version; console.log(JSON.stringify({ pwtIndex, version})); } catch { console.log("null"); }`,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: The reason for changing undefined -> null was that JSON.parse('undefined') does not work while it does with null. Added a null check afterwards to be on the safe side.

], path.dirname(configFilePath));
if (!pwtInfo)
throw new Error(`Cannot find Playwright Test package`);
const { version } = JSON.parse(pwtInfo);
const v = parseFloat(version.replace(/-(next|beta)$/, ''));

Expand All @@ -77,8 +88,10 @@ export class PlaywrightTest {

const cliInfo = await this._runNode([
'-e',
'try { const cli = require.resolve("@playwright/test/cli"); console.log(JSON.stringify({ cli })); } catch { console.log("undefined"); }',
`try { const path = require('path'); const cli = path.join(path.dirname(require.resolve("${cliPackage}")), 'cli.js'); console.log(JSON.stringify({ cli })); } catch { console.log("null"); }`,
mxschmitt marked this conversation as resolved.
Show resolved Hide resolved
], path.dirname(configFilePath));
if (!cliInfo)
throw new Error(`Cannot find Playwright Test CLI`);
let { cli } = JSON.parse(cliInfo);

// Dogfood for 'ttest'
Expand Down
Loading