Skip to content

Commit

Permalink
fix: find cli via playwright as a fallback (for CT) (#415)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt authored Feb 8, 2024
1 parent 206b8a6 commit f1e0a58
Showing 1 changed file with 15 additions and 2 deletions.
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"); }`,
], 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"); }`,
], path.dirname(configFilePath));
if (!cliInfo)
throw new Error(`Cannot find Playwright Test CLI`);
let { cli } = JSON.parse(cliInfo);

// Dogfood for 'ttest'
Expand Down

0 comments on commit f1e0a58

Please sign in to comment.