diff --git a/packages/cli/e2e/__tests__/pw-test.spec.ts b/packages/cli/e2e/__tests__/pw-test.spec.ts index 8cf8f5f09..d70b34e54 100644 --- a/packages/cli/e2e/__tests__/pw-test.spec.ts +++ b/packages/cli/e2e/__tests__/pw-test.spec.ts @@ -69,5 +69,34 @@ describe('pw-test', { timeout: 45000 }, () => { const configContent = fs.readFileSync( path.join(FIXTURE_TEST_PWT_NATIVE, 'checkly.config.ts'), 'utf-8') expect(configContent).toContain('frequency: 5') + const playwrightChecks = checklyConfig.config?.checks?.playwrightChecks + expect(playwrightChecks).toBeDefined() + expect(playwrightChecks!.length).toBe(1) + expect(playwrightChecks![0].name).toBe('Playwright Test: --grep @TAG-B') + expect(playwrightChecks![0].testCommand).toBe('npx playwright test --grep @TAG-B') + }) + + it('Should add a Playwright test with custom install command to the config', async () => { + const result = await runChecklyCli({ + args: ['pw-test', '--install-command', 'pnpm install', '--create-check', '--', `--grep`, '@TAG-A'], + apiKey: config.get('apiKey'), + accountId: config.get('accountId'), + directory: FIXTURE_TEST_PWT_NATIVE, + timeout: 120000, // 2 minutes + }) + if (result.status !== 0) { + // eslint-disable-next-line no-console + console.log(result) + } + const configContent = fs.readFileSync( + path.join(FIXTURE_TEST_PWT_NATIVE, 'checkly.config.ts'), 'utf-8') + expect(result.status).toBe(0) + const checklyConfig = await loadChecklyConfig(FIXTURE_TEST_PWT_NATIVE) + expect(checklyConfig.config?.checks).toBeDefined() + expect(checklyConfig.config?.checks?.playwrightChecks).toBeDefined() + const playwrightChecks = checklyConfig.config?.checks?.playwrightChecks + expect(playwrightChecks).toBeDefined() + expect(playwrightChecks!.length).toBe(1) + expect(configContent).toContain('pnpm install') }) }) diff --git a/packages/cli/src/commands/pw-test.ts b/packages/cli/src/commands/pw-test.ts index 90675a0ee..1539e84ac 100644 --- a/packages/cli/src/commands/pw-test.ts +++ b/packages/cli/src/commands/pw-test.ts @@ -106,6 +106,9 @@ export default class PwTestCommand extends AuthCommand { multiple: true, default: [], }), + 'install-command': Flags.string({ + description: 'Command to install dependencies before running tests.', + }), } async run (): Promise { @@ -129,6 +132,7 @@ export default class PwTestCommand extends AuthCommand { 'stream-logs': streamLogs, 'include': includeFlag, 'frequency': frequency, + 'install-command': installCommand, } = flags const { configDirectory, configFilenames } = splitConfigFilePath(configFilename) const pwPathFlag = this.getConfigPath(playwrightFlags) @@ -156,6 +160,7 @@ export default class PwTestCommand extends AuthCommand { privateRunLocation, dir, frequency, + installCommand, ) if (createCheck) { this.style.actionStart('Adding check with specified options to the Checkly config file') @@ -359,6 +364,7 @@ export default class PwTestCommand extends AuthCommand { privateRunLocation: string | undefined, dir: string, frequency: number = 10, + installCommand?: string, ): Promise { const parseArgs = args.map(arg => shellQuote(arg)) const input = parseArgs.join(' ') || '' @@ -376,6 +382,7 @@ export default class PwTestCommand extends AuthCommand { testCommand, ...locationConfig, frequency, + ...(installCommand ? { installCommand } : {}), } }