Skip to content
Open
Show file tree
Hide file tree
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
29 changes: 29 additions & 0 deletions packages/cli/e2e/__tests__/pw-test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})
7 changes: 7 additions & 0 deletions packages/cli/src/commands/pw-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand All @@ -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)
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -359,6 +364,7 @@ export default class PwTestCommand extends AuthCommand {
privateRunLocation: string | undefined,
dir: string,
frequency: number = 10,
installCommand?: string,
): Promise<PlaywrightSlimmedProp> {
const parseArgs = args.map(arg => shellQuote(arg))
const input = parseArgs.join(' ') || ''
Expand All @@ -376,6 +382,7 @@ export default class PwTestCommand extends AuthCommand {
testCommand,
...locationConfig,
frequency,
...(installCommand ? { installCommand } : {}),
}
}

Expand Down