Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.
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
6 changes: 5 additions & 1 deletion src/PlaywrightEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type {
Browser,
BrowserContext,
BrowserContextOptions,
ConnectOptions,
ConnectOverCDPOptions,
Page,
} from 'playwright-core'
import { Event } from 'jest-circus'
Expand Down Expand Up @@ -68,7 +70,9 @@ const getBrowserPerProcess = async (
}

const options = getBrowserOptions(browserType, connectOptions)
return playwrightInstance.connect(options)
return options && 'endpointURL' in options
? playwrightInstance.connectOverCDP(options)
: playwrightInstance.connect(options)
}

const getDeviceConfig = (
Expand Down
3 changes: 2 additions & 1 deletion src/PlaywrightRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,10 @@ class PlaywrightRunner extends JestRunner {
typeof browser === 'string'
? browser
: generateKey(browser.name, browserConfig)
const browserOptions = getBrowserOptions(browserType, connectOptions)
const wsEndpoint: WsEndpointType = await this.launchServer(
browserConfig,
getBrowserOptions(browserType, connectOptions)?.wsEndpoint || null,
'wsEndpoint' in browserOptions ? browserOptions.wsEndpoint : null,
browserType,
key,
instance as GenericBrowser,
Expand Down
4 changes: 2 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { JestPlaywrightConfig, ConnectOptions } from '../types/global'
import type { JestPlaywrightConfig } from '../types/global'

export const IMPORT_KIND_PLAYWRIGHT = 'playwright'

Expand All @@ -15,7 +15,7 @@ export const SERVER = 'SERVER'
export const DEFAULT_CONFIG: JestPlaywrightConfig = {
launchType: SERVER,
launchOptions: {},
connectOptions: {} as ConnectOptions,
connectOptions: {} as JestPlaywrightConfig['connectOptions'],
contextOptions: {},
browsers: [CHROMIUM],
exitOnPageError: true,
Expand Down
6 changes: 3 additions & 3 deletions types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
Page,
BrowserContextOptions,
LaunchOptions,
ConnectOptions,
ConnectOverCDPOptions,
BrowserType as PlaywrightBrowserType,
ViewportSize,
ChromiumBrowser,
Expand Down Expand Up @@ -191,8 +193,6 @@ type LaunchType = typeof LAUNCH | typeof SERVER | typeof PERSISTENT

type Options<T> = T & Partial<Record<BrowserType, T>>

export type ConnectOptions = Parameters<GenericBrowser['connect']>[0]

export type ServerOptions = JestProcessManagerOptions & {
teardown?: string
}
Expand All @@ -203,7 +203,7 @@ export interface JestPlaywrightConfig {
debugOptions?: JestPlaywrightConfig
launchType?: LaunchType
launchOptions?: Options<LaunchOptions>
connectOptions?: Options<ConnectOptions>
connectOptions?: Options<ConnectOptions | ConnectOverCDPOptions>
contextOptions?: Options<BrowserContextOptions>
userDataDir?: string
exitOnPageError?: boolean
Expand Down