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
26 changes: 13 additions & 13 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ appearance, race, religion, or sexual identity and orientation.
Examples of behavior that contributes to creating a positive environment
include:

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

Examples of unacceptable behavior by participants include:

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

## Our Responsibilities

Expand Down
31 changes: 19 additions & 12 deletions src/PlaywrightEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,22 @@ export const getPlaywrightEnv = (basicEnv = 'node'): unknown => {
this._config = config
}

_getContextOptions(devices: Playwright['devices']): BrowserContextOptions {
const { browserName, device } = this._config
const browserType = getBrowserType(browserName)
const { contextOptions } = this._jestPlaywrightConfig
const deviceBrowserContextOptions = getDeviceConfig(device, devices)
const resultContextOptions = deepMerge(
deviceBrowserContextOptions,
getBrowserOptions(browserName, contextOptions),
)
if (browserType === FIREFOX && resultContextOptions.isMobile) {
console.warn(formatError(`isMobile is not supported in ${FIREFOX}.`))
delete resultContextOptions.isMobile
}
return resultContextOptions
}

_getSeparateEnvBrowserConfig(
isDebug: boolean,
config: TestPlaywrightConfigOptions,
Expand Down Expand Up @@ -201,17 +217,14 @@ export const getPlaywrightEnv = (basicEnv = 'node'): unknown => {
}
}
const browserType = getBrowserType(browserName)
let contextOptions = getBrowserOptions(
browserName,
this._jestPlaywrightConfig.contextOptions,
)
const device = this._config.device
const deviceName: Nullable<string> = getDeviceName(device)
const {
name,
instance: playwrightInstance,
devices,
} = getPlaywrightInstance(browserType)
const contextOptions = this._getContextOptions(devices)

if (name === IMPORT_KIND_PLAYWRIGHT) {
const playwright = require('playwright')
Expand All @@ -230,12 +243,6 @@ export const getPlaywrightEnv = (basicEnv = 'node'): unknown => {
}
}

const deviceBrowserContextOptions = getDeviceConfig(device, devices)
contextOptions = deepMerge(deviceBrowserContextOptions, contextOptions)
if (browserType === FIREFOX && contextOptions.isMobile) {
console.warn(formatError(`isMobile is not supported in ${FIREFOX}.`))
delete contextOptions.isMobile
}
this.global.browserName = browserType
this.global.deviceName = deviceName
if (!skipInitialization) {
Expand All @@ -251,11 +258,11 @@ export const getPlaywrightEnv = (basicEnv = 'node'): unknown => {
? browserOrContext
: await this.global.browser.newContext(contextOptions)
if (collectCoverage) {
;(this.global.context as BrowserContext).exposeFunction(
await (this.global.context as BrowserContext).exposeFunction(
'reportCodeCoverage',
saveCoverageToFile,
)
;(this.global.context as BrowserContext).addInitScript(() =>
await (this.global.context as BrowserContext).addInitScript(() =>
window.addEventListener('beforeunload', () => {
// @ts-ignore
reportCodeCoverage(window.__coverage__)
Expand Down
2 changes: 1 addition & 1 deletion src/coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const saveCoverageToFile = async (coverage: unknown): Promise<void> => {

export const saveCoverageOnPage = async (
page: Page,
collectCoverage: boolean,
collectCoverage = false,
): Promise<void> => {
if (!collectCoverage) {
console.warn(
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export function getBrowserOptions<T>(
let result: Options<T> | undefined = options
if (result) {
if (result[browserName]) {
result = { ...result, ...result[browserName] }
result = deepMerge(result, result[browserName]!)
}
BROWSERS.forEach((browser) => {
delete result![browser as BrowserType]
Expand Down
4 changes: 2 additions & 2 deletions types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,14 @@ export interface JestPlaywrightConfig {
connectOptions?: Options<ConnectOptions>
contextOptions?: Options<BrowserContextOptions>
userDataDir?: string
exitOnPageError: boolean
exitOnPageError?: boolean
displayName?: string
browsers: (BrowserType | (JestPlaywrightConfig & { name: BrowserType }))[]
devices?: ConfigDeviceType[] | RegExp
useDefaultBrowserType?: boolean
serverOptions?: JestProcessManagerOptions
selectors?: SelectorType[]
collectCoverage: boolean
collectCoverage?: boolean
}

export interface JestPlaywrightProjectConfig extends JestConfig.ProjectConfig {
Expand Down