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

feat: add support for playwright config on browser checks #907

Merged
merged 2 commits into from
Dec 20, 2023
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
9 changes: 9 additions & 0 deletions packages/cli/src/constructs/browser-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CheckConfigDefaults } from '../services/checkly-config-loader'
import { pathToPosix } from '../services/util'
import { Content, Entrypoint } from './construct'
import { detectSnapshots, Snapshot } from '../services/snapshot-service'
import { PlaywrightConfig } from './browser-defaults'

export interface CheckDependency {
path: string
Expand All @@ -23,6 +24,11 @@ export interface BrowserCheckProps extends CheckProps {
* expiration. For example, 'app.checklyhq.com'.
*/
sslCheckDomain?: string
/**
* A valid playwright config object, same format and keys as you would use on
* playwright.config.ts
*/
playwrightConfig?: PlaywrightConfig,
}

/**
Expand All @@ -42,6 +48,7 @@ export class BrowserCheck extends Check {
// The `snapshots` field is set later (with a `key`) after these are uploaded to storage.
rawSnapshots?: Array<{ absolutePath: string, path: string }>
snapshots?: Array<Snapshot>
playwrightConfig?: PlaywrightConfig

/**
* Constructs the Browser Check instance
Expand All @@ -57,6 +64,7 @@ export class BrowserCheck extends Check {
BrowserCheck.applyDefaultBrowserCheckConfig(props)
super(logicalId, props)
this.sslCheckDomain = props.sslCheckDomain
this.playwrightConfig = props.playwrightConfig
if ('content' in props.code) {
const script = props.code.content
this.script = script
Expand Down Expand Up @@ -144,6 +152,7 @@ export class BrowserCheck extends Check {
dependencies: this.dependencies,
sslCheckDomain: this.sslCheckDomain || null, // empty string is converted to null
snapshots: this.snapshots,
playwrightConfig: this.playwrightConfig,
}
}
}
46 changes: 46 additions & 0 deletions packages/cli/src/constructs/browser-defaults.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { CheckProps } from './check'

export type Use = {
baseURL?: string,
colorScheme?: string,
geolocation?: {
longitude?: number,
latitude?: number
},
locale?: string,
permissions?: string[],
timezoneId?: string,
viewport?: {
width?: number,
height?: number,
},
deviceScaleFactor?: number,
hasTouch?: boolean,
isMobile?: boolean,
javaScriptEnabled?: boolean,
acceptDownloads?: boolean,
extraHTTPHeaders?: object,
httpCredentials?: object,
ignoreHTTPSErrors?: boolean,
offline?: boolean,
actionTimeout?: number,
navigationTimeout?: number,
testIdAttribute?: string,
launchOptions?: object,
contextOptions?: object,
bypassCSP?: boolean,
}

export type Expect = {
timeout?: number
}

export type PlaywrightConfig = {
use?: Use,
expect?: Expect,
timeout?: number
}

export interface BrowserPlaywrightDefaults extends CheckProps {
playwrightConfig?: PlaywrightConfig
}
9 changes: 7 additions & 2 deletions packages/cli/src/services/checkly-config-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ import { Session } from '../constructs'
import { Construct } from '../constructs/construct'
import type { Region } from '..'
import { ReporterType } from '../reporters/reporter'
import { BrowserPlaywrightDefaults } from '../constructs/browser-defaults'

export type CheckConfigDefaults = Pick<CheckProps, 'activated' | 'muted' | 'doubleCheck'
| 'shouldFail' | 'runtimeId' | 'locations' | 'tags' | 'frequency' | 'environmentVariables'
| 'alertChannels' | 'privateLocations' | 'retryStrategy' | 'runParallel'>
| 'alertChannels' | 'privateLocations' | 'retryStrategy'>

export type BrowserCheckDefaults = Pick<BrowserPlaywrightDefaults, 'activated' | 'muted' | 'doubleCheck'
| 'shouldFail' | 'runtimeId' | 'locations' | 'tags' | 'frequency' | 'environmentVariables'
| 'alertChannels' | 'privateLocations' | 'retryStrategy' | 'playwrightConfig' >

export type ChecklyConfig = {
/**
Expand Down Expand Up @@ -39,7 +44,7 @@ export type ChecklyConfig = {
/**
* Browser checks default configuration properties.
*/
browserChecks?: CheckConfigDefaults & {
browserChecks?: BrowserCheckDefaults & {
/**
* Glob pattern where the CLI looks for Playwright test files, i.e. all `.spec.ts` files
*/
Expand Down
Loading