Skip to content

Commit ee03a95

Browse files
authored
jestPlaywright debug improvements (#243)
* jestPlaywright debug improvements * jestPlaywright debug pass options * Remove unnecessary args length check
1 parent 75fcebb commit ee03a95

File tree

2 files changed

+51
-15
lines changed

2 files changed

+51
-15
lines changed

extends.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,30 @@ const DEBUG_OPTIONS = {
1010
}
1111

1212
it.jestPlaywrightDebug = (...args) => {
13-
// TODO: Check out passing config to jestPlaywright._configSeparateEnv
14-
it(args[0], async () => {
13+
const isConfigProvided = typeof args[0] === 'object'
14+
// TODO Looks wierd - need to be rewritten
15+
let options = DEBUG_OPTIONS
16+
if (isConfigProvided) {
17+
const {
18+
contextOptions,
19+
launchOptions = {},
20+
launchType = DEBUG_OPTIONS.launchType,
21+
} = args[0]
22+
options = {
23+
...DEBUG_OPTIONS,
24+
launchType,
25+
launchOptions: { ...DEBUG_OPTIONS.launchOptions, ...launchOptions },
26+
contextOptions,
27+
}
28+
}
29+
30+
it(args[isConfigProvided ? 1 : 0], async () => {
1531
const { browser, context, page } = await jestPlaywright._configSeparateEnv(
16-
DEBUG_OPTIONS,
32+
options,
33+
true,
1734
)
1835
try {
19-
await args[1]({ browser, context, page })
36+
await args[isConfigProvided ? 2 : 1]({ browser, context, page })
2037
} finally {
2138
await browser.close()
2239
}
@@ -32,10 +49,7 @@ it.jestPlaywrightConfig = (playwrightOptions, ...args) => {
3249
browser,
3350
context,
3451
page,
35-
} = await jestPlaywright._configSeparateEnv({
36-
...DEBUG_OPTIONS,
37-
playwrightOptions,
38-
})
52+
} = await jestPlaywright._configSeparateEnv(playwrightOptions)
3953
try {
4054
await args[1]({ browser, context, page })
4155
} finally {

src/PlaywrightEnvironment.ts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
/* eslint-disable no-console */
22
import type { Event, State } from 'jest-circus'
3-
import type { Browser, Page, BrowserContext } from 'playwright-core'
3+
import type {
4+
Browser,
5+
Page,
6+
BrowserContext,
7+
BrowserContextOptions,
8+
} from 'playwright-core'
49
import type {
510
JestPlaywrightConfig,
611
GenericBrowser,
@@ -167,20 +172,37 @@ export const getPlaywrightEnv = (basicEnv = 'node'): unknown => {
167172
this.global.jestPlaywright = {
168173
_configSeparateEnv: async (
169174
config: JestPlaywrightConfig,
175+
isDebug?: boolean,
170176
): Promise<ConfigParams> => {
171-
const { contextOptions, launchType } = config
177+
const { contextOptions, launchOptions, launchType } = config
178+
let resultBrowserConfig: JestPlaywrightConfig
179+
let resultContextOptions: BrowserContextOptions | undefined
180+
if (isDebug) {
181+
resultBrowserConfig = config
182+
resultContextOptions = contextOptions
183+
} else {
184+
resultBrowserConfig = {
185+
...this._jestPlaywrightConfig,
186+
launchType,
187+
launchOptions: {
188+
...this._jestPlaywrightConfig.launchOptions,
189+
...launchOptions,
190+
},
191+
}
192+
resultContextOptions = {
193+
...this._jestPlaywrightConfig.contextOptions,
194+
...contextOptions,
195+
}
196+
}
172197
const browserOrContext = await getBrowserPerProcess(
173198
playwrightInstance,
174199
browserType,
175-
{
176-
...this._jestPlaywrightConfig,
177-
...config,
178-
},
200+
resultBrowserConfig,
179201
)
180202
const browser = launchType === PERSISTENT ? null : browserOrContext
181203
const newContextOptions = getBrowserOptions(
182204
browserName,
183-
contextOptions,
205+
resultContextOptions,
184206
)
185207
const context =
186208
launchType === PERSISTENT

0 commit comments

Comments
 (0)