Skip to content

Commit 03e3230

Browse files
feat: add 'connectBrowserApp' option (#90)
Co-authored-by: jochen <[email protected]>
1 parent c5aef25 commit 03e3230

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ describe('Google', () => {
7373
You can specify a `jest-playwright.config.js` at the root of the project or define a custom path using `JEST_PLAYWRIGHT_CONFIG` environment variable. It should export a config object.
7474

7575
- `launchBrowserApp` <[object]> [All Playwright launch options](https://github.com/microsoft/playwright/blob/master/docs/api.md#browsertypelaunchoptions) can be specified in config. Since it is JavaScript, you can use all stuff you need, including environment.
76+
- `connectBrowserApp` <[object]> [All Playwright connect options](https://github.com/microsoft/playwright/blob/master/docs/api.md#browsertypeconnectoptions) can be specified in config.
7677
- `context` <[object]> [All Playwright context options](https://github.com/microsoft/playwright/blob/master/docs/api.md#browsernewcontextoptions) can be specified in config.
7778
- `browser` <[string]>. Define a [browser](https://github.com/microsoft/playwright/blob/master/docs/api.md#class-browsertype) to run tests into.
7879
- `chromium` Each test runs Chromium (default).

src/PlaywrightEnvironment.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,19 @@ const getBrowserPerProcess = async (
6363
if (!browserPerProcess) {
6464
const browserType = getBrowserType(config)
6565
checkBrowserEnv(browserType)
66-
const { launchBrowserApp } = config
66+
const { launchBrowserApp, connectBrowserApp } = config
6767
// https://github.com/mmarkelov/jest-playwright/issues/42#issuecomment-589170220
6868
if (browserType !== CHROMIUM && launchBrowserApp && launchBrowserApp.args) {
6969
launchBrowserApp.args = launchBrowserApp.args.filter(
7070
(item) => item !== '--no-sandbox',
7171
)
7272
}
73-
browserPerProcess = await playwrightInstance.launch(launchBrowserApp)
73+
74+
if (connectBrowserApp) {
75+
browserPerProcess = await playwrightInstance.connect(connectBrowserApp)
76+
} else {
77+
browserPerProcess = await playwrightInstance.launch(launchBrowserApp)
78+
}
7479
}
7580
return browserPerProcess
7681
}

src/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
ChromiumBrowser,
66
FirefoxBrowser,
77
BrowserType as PlaywrighBrowserType,
8+
BrowserTypeConnectOptions,
89
} from 'playwright-core'
910
import { JestDevServerOptions } from 'jest-dev-server'
1011

@@ -37,6 +38,7 @@ export interface Config {
3738
devices?: string[]
3839
server?: JestDevServerOptions
3940
selectors?: SelectorType[]
41+
connectBrowserApp?: BrowserTypeConnectOptions
4042
}
4143

4244
export const DEFAULT_CONFIG: Config = {

0 commit comments

Comments
 (0)