Skip to content

Commit

Permalink
jestPlaywright debug improvements (#243)
Browse files Browse the repository at this point in the history
* jestPlaywright debug improvements

* jestPlaywright debug pass options

* Remove unnecessary args length check
  • Loading branch information
mmarkelov authored Jul 23, 2020
1 parent 75fcebb commit ee03a95
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 15 deletions.
30 changes: 22 additions & 8 deletions extends.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,30 @@ const DEBUG_OPTIONS = {
}

it.jestPlaywrightDebug = (...args) => {
// TODO: Check out passing config to jestPlaywright._configSeparateEnv
it(args[0], async () => {
const isConfigProvided = typeof args[0] === 'object'
// TODO Looks wierd - need to be rewritten
let options = DEBUG_OPTIONS
if (isConfigProvided) {
const {
contextOptions,
launchOptions = {},
launchType = DEBUG_OPTIONS.launchType,
} = args[0]
options = {
...DEBUG_OPTIONS,
launchType,
launchOptions: { ...DEBUG_OPTIONS.launchOptions, ...launchOptions },
contextOptions,
}
}

it(args[isConfigProvided ? 1 : 0], async () => {
const { browser, context, page } = await jestPlaywright._configSeparateEnv(
DEBUG_OPTIONS,
options,
true,
)
try {
await args[1]({ browser, context, page })
await args[isConfigProvided ? 2 : 1]({ browser, context, page })
} finally {
await browser.close()
}
Expand All @@ -32,10 +49,7 @@ it.jestPlaywrightConfig = (playwrightOptions, ...args) => {
browser,
context,
page,
} = await jestPlaywright._configSeparateEnv({
...DEBUG_OPTIONS,
playwrightOptions,
})
} = await jestPlaywright._configSeparateEnv(playwrightOptions)
try {
await args[1]({ browser, context, page })
} finally {
Expand Down
36 changes: 29 additions & 7 deletions src/PlaywrightEnvironment.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
/* eslint-disable no-console */
import type { Event, State } from 'jest-circus'
import type { Browser, Page, BrowserContext } from 'playwright-core'
import type {
Browser,
Page,
BrowserContext,
BrowserContextOptions,
} from 'playwright-core'
import type {
JestPlaywrightConfig,
GenericBrowser,
Expand Down Expand Up @@ -167,20 +172,37 @@ export const getPlaywrightEnv = (basicEnv = 'node'): unknown => {
this.global.jestPlaywright = {
_configSeparateEnv: async (
config: JestPlaywrightConfig,
isDebug?: boolean,
): Promise<ConfigParams> => {
const { contextOptions, launchType } = config
const { contextOptions, launchOptions, launchType } = config
let resultBrowserConfig: JestPlaywrightConfig
let resultContextOptions: BrowserContextOptions | undefined
if (isDebug) {
resultBrowserConfig = config
resultContextOptions = contextOptions
} else {
resultBrowserConfig = {
...this._jestPlaywrightConfig,
launchType,
launchOptions: {
...this._jestPlaywrightConfig.launchOptions,
...launchOptions,
},
}
resultContextOptions = {
...this._jestPlaywrightConfig.contextOptions,
...contextOptions,
}
}
const browserOrContext = await getBrowserPerProcess(
playwrightInstance,
browserType,
{
...this._jestPlaywrightConfig,
...config,
},
resultBrowserConfig,
)
const browser = launchType === PERSISTENT ? null : browserOrContext
const newContextOptions = getBrowserOptions(
browserName,
contextOptions,
resultContextOptions,
)
const context =
launchType === PERSISTENT
Expand Down

0 comments on commit ee03a95

Please sign in to comment.