@@ -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__ )
0 commit comments