Skip to content
Merged
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
74 changes: 74 additions & 0 deletions packages/cli/src/constructs/__tests__/playwright-check.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,80 @@ describe('PlaywrightCheck', () => {
}),
]))
})

it('should warn when installCommand contains playwright install', async () => {
Session.basePath = path.resolve(__dirname, './fixtures/playwright-check')
Session.project = new Project('project-id', {
name: 'Test Project',
repoUrl: 'https://github.com/checkly/checkly-cli',
})

const check = new PlaywrightCheck('foo', {
name: 'Test Check',
playwrightConfigPath: path.resolve(__dirname, './fixtures/playwright-check/playwright.config.ts'),
installCommand: 'npm ci && npx playwright install chromium',
})

const diags = new Diagnostics()
await check.validate(diags)

expect(diags.isFatal()).toEqual(false)
expect(diags.observations).toEqual(expect.arrayContaining([
expect.objectContaining({
title: 'Unnecessary browser installation detected',
message: expect.stringContaining('installCommand contains "playwright install"'),
}),
]))
})

it('should warn when testCommand contains playwright install', async () => {
Session.basePath = path.resolve(__dirname, './fixtures/playwright-check')
Session.project = new Project('project-id', {
name: 'Test Project',
repoUrl: 'https://github.com/checkly/checkly-cli',
})

const check = new PlaywrightCheck('foo', {
name: 'Test Check',
playwrightConfigPath: path.resolve(__dirname, './fixtures/playwright-check/playwright.config.ts'),
testCommand: 'npx playwright install && npx playwright test',
})

const diags = new Diagnostics()
await check.validate(diags)

expect(diags.isFatal()).toEqual(false)
expect(diags.observations).toEqual(expect.arrayContaining([
expect.objectContaining({
title: 'Unnecessary browser installation detected',
message: expect.stringContaining('testCommand contains "playwright install"'),
}),
]))
})

it('should not warn when commands do not contain playwright install', async () => {
Session.basePath = path.resolve(__dirname, './fixtures/playwright-check')
Session.project = new Project('project-id', {
name: 'Test Project',
repoUrl: 'https://github.com/checkly/checkly-cli',
})

const check = new PlaywrightCheck('foo', {
name: 'Test Check',
playwrightConfigPath: path.resolve(__dirname, './fixtures/playwright-check/playwright.config.ts'),
installCommand: 'npm ci',
testCommand: 'npx playwright test',
})

const diags = new Diagnostics()
await check.validate(diags)

expect(diags.observations).not.toEqual(expect.arrayContaining([
expect.objectContaining({
title: 'Unnecessary browser installation detected',
}),
]))
})
})

describe('defaults', () => {
Expand Down
23 changes: 23 additions & 0 deletions packages/cli/src/constructs/playwright-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,28 @@ export class PlaywrightCheck extends RuntimeCheck {
}
}

protected validateBrowserInstallCommand (diagnostics: Diagnostics): void {
const playwrightInstallPattern = /playwright\s+install/i

const commands = [
{ name: 'installCommand', value: this.installCommand },
{ name: 'testCommand', value: this.testCommand },
]

for (const { name, value } of commands) {
if (value && playwrightInstallPattern.test(value)) {
diagnostics.add(new WarningDiagnostic({
title: 'Unnecessary browser installation detected',
message:
`The ${name} contains "playwright install" which is not needed. `
+ `Checkly automatically installs browsers based on your pwProjects configuration. `
+ `Consider removing the browser installation from ${name}.`,
}))
break
}
}
}

async validate (diagnostics: Diagnostics): Promise<void> {
await super.validate(diagnostics)
await this.validateRetryStrategy(diagnostics)
Expand All @@ -328,6 +350,7 @@ export class PlaywrightCheck extends RuntimeCheck {
}

await this.validateHeadlessMode(diagnostics)
this.validateBrowserInstallCommand(diagnostics)

this.#validateGroupReferences(diagnostics)
}
Expand Down
Loading