Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

Commit 8eac367

Browse files
authored
Make collectCoverage optional (#565)
1 parent 20251d0 commit 8eac367

File tree

5 files changed

+36
-29
lines changed

5 files changed

+36
-29
lines changed

CODE_OF_CONDUCT.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ appearance, race, religion, or sexual identity and orientation.
1414
Examples of behavior that contributes to creating a positive environment
1515
include:
1616

17-
* Using welcoming and inclusive language
18-
* Being respectful of differing viewpoints and experiences
19-
* Gracefully accepting constructive criticism
20-
* Focusing on what is best for the community
21-
* Showing empathy towards other community members
17+
- Using welcoming and inclusive language
18+
- Being respectful of differing viewpoints and experiences
19+
- Gracefully accepting constructive criticism
20+
- Focusing on what is best for the community
21+
- Showing empathy towards other community members
2222

2323
Examples of unacceptable behavior by participants include:
2424

25-
* The use of sexualized language or imagery and unwelcome sexual attention or
26-
advances
27-
* Trolling, insulting/derogatory comments, and personal or political attacks
28-
* Public or private harassment
29-
* Publishing others' private information, such as a physical or electronic
30-
address, without explicit permission
31-
* Other conduct which could reasonably be considered inappropriate in a
32-
professional setting
25+
- The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
- Trolling, insulting/derogatory comments, and personal or political attacks
28+
- Public or private harassment
29+
- Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
- Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
3333

3434
## Our Responsibilities
3535

src/PlaywrightEnvironment.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,22 @@ export const getPlaywrightEnv = (basicEnv = 'node'): unknown => {
122122
this._config = config
123123
}
124124

125+
_getContextOptions(devices: Playwright['devices']): BrowserContextOptions {
126+
const { browserName, device } = this._config
127+
const browserType = getBrowserType(browserName)
128+
const { contextOptions } = this._jestPlaywrightConfig
129+
const deviceBrowserContextOptions = getDeviceConfig(device, devices)
130+
const resultContextOptions = deepMerge(
131+
deviceBrowserContextOptions,
132+
getBrowserOptions(browserName, contextOptions),
133+
)
134+
if (browserType === FIREFOX && resultContextOptions.isMobile) {
135+
console.warn(formatError(`isMobile is not supported in ${FIREFOX}.`))
136+
delete resultContextOptions.isMobile
137+
}
138+
return resultContextOptions
139+
}
140+
125141
_getSeparateEnvBrowserConfig(
126142
isDebug: boolean,
127143
config: TestPlaywrightConfigOptions,
@@ -201,17 +217,14 @@ export const getPlaywrightEnv = (basicEnv = 'node'): unknown => {
201217
}
202218
}
203219
const browserType = getBrowserType(browserName)
204-
let contextOptions = getBrowserOptions(
205-
browserName,
206-
this._jestPlaywrightConfig.contextOptions,
207-
)
208220
const device = this._config.device
209221
const deviceName: Nullable<string> = getDeviceName(device)
210222
const {
211223
name,
212224
instance: playwrightInstance,
213225
devices,
214226
} = getPlaywrightInstance(browserType)
227+
const contextOptions = this._getContextOptions(devices)
215228

216229
if (name === IMPORT_KIND_PLAYWRIGHT) {
217230
const playwright = require('playwright')
@@ -230,12 +243,6 @@ export const getPlaywrightEnv = (basicEnv = 'node'): unknown => {
230243
}
231244
}
232245

233-
const deviceBrowserContextOptions = getDeviceConfig(device, devices)
234-
contextOptions = deepMerge(deviceBrowserContextOptions, contextOptions)
235-
if (browserType === FIREFOX && contextOptions.isMobile) {
236-
console.warn(formatError(`isMobile is not supported in ${FIREFOX}.`))
237-
delete contextOptions.isMobile
238-
}
239246
this.global.browserName = browserType
240247
this.global.deviceName = deviceName
241248
if (!skipInitialization) {
@@ -251,11 +258,11 @@ export const getPlaywrightEnv = (basicEnv = 'node'): unknown => {
251258
? browserOrContext
252259
: await this.global.browser.newContext(contextOptions)
253260
if (collectCoverage) {
254-
;(this.global.context as BrowserContext).exposeFunction(
261+
await (this.global.context as BrowserContext).exposeFunction(
255262
'reportCodeCoverage',
256263
saveCoverageToFile,
257264
)
258-
;(this.global.context as BrowserContext).addInitScript(() =>
265+
await (this.global.context as BrowserContext).addInitScript(() =>
259266
window.addEventListener('beforeunload', () => {
260267
// @ts-ignore
261268
reportCodeCoverage(window.__coverage__)

src/coverage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const saveCoverageToFile = async (coverage: unknown): Promise<void> => {
3333

3434
export const saveCoverageOnPage = async (
3535
page: Page,
36-
collectCoverage: boolean,
36+
collectCoverage = false,
3737
): Promise<void> => {
3838
if (!collectCoverage) {
3939
console.warn(

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export function getBrowserOptions<T>(
162162
let result: Options<T> | undefined = options
163163
if (result) {
164164
if (result[browserName]) {
165-
result = { ...result, ...result[browserName] }
165+
result = deepMerge(result, result[browserName]!)
166166
}
167167
BROWSERS.forEach((browser) => {
168168
delete result![browser as BrowserType]

types/global.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,14 @@ export interface JestPlaywrightConfig {
208208
connectOptions?: Options<ConnectOptions>
209209
contextOptions?: Options<BrowserContextOptions>
210210
userDataDir?: string
211-
exitOnPageError: boolean
211+
exitOnPageError?: boolean
212212
displayName?: string
213213
browsers: (BrowserType | (JestPlaywrightConfig & { name: BrowserType }))[]
214214
devices?: ConfigDeviceType[] | RegExp
215215
useDefaultBrowserType?: boolean
216216
serverOptions?: JestProcessManagerOptions
217217
selectors?: SelectorType[]
218-
collectCoverage: boolean
218+
collectCoverage?: boolean
219219
}
220220

221221
export interface JestPlaywrightProjectConfig extends JestConfig.ProjectConfig {

0 commit comments

Comments
 (0)