@@ -32,6 +32,15 @@ export { expect, config } from '@playwright/test-runner';
32
32
const removeFolderAsync = util . promisify ( require ( 'rimraf' ) ) ;
33
33
const mkdtempAsync = util . promisify ( fs . mkdtemp ) ;
34
34
35
+ const getExecutablePath = browserName => {
36
+ if ( browserName === 'chromium' && process . env . CRPATH )
37
+ return process . env . CRPATH ;
38
+ if ( browserName === 'firefox' && process . env . FFPATH )
39
+ return process . env . FFPATH ;
40
+ if ( browserName === 'webkit' && process . env . WKPATH )
41
+ return process . env . WKPATH ;
42
+ } ;
43
+
35
44
type AllTestFixtures = {
36
45
createUserDataDir : ( ) => Promise < string > ;
37
46
launchPersistent : ( options ?: Parameters < BrowserType < Browser > [ 'launchPersistentContext' ] > [ 1 ] ) => Promise < { context : BrowserContext , page : Page } > ;
@@ -73,8 +82,70 @@ export const fixtures = playwrightFixtures
73
82
if ( context )
74
83
await context . close ( ) ;
75
84
} ,
85
+ } )
86
+ . overrideWorkerFixtures ( {
87
+ defaultBrowserOptions : async ( { browserName, headful, slowMo } , runTest ) => {
88
+ const executablePath = getExecutablePath ( browserName ) ;
89
+ if ( executablePath )
90
+ console . error ( `Using executable at ${ executablePath } ` ) ;
91
+ await runTest ( {
92
+ executablePath,
93
+ handleSIGINT : false ,
94
+ slowMo,
95
+ headless : ! headful ,
96
+ } ) ;
97
+ } ,
98
+
99
+ playwright : async ( { browserName, testWorkerIndex, platform, wire } , runTest ) => {
100
+ assert ( platform ) ; // Depend on platform to generate all tests.
101
+ const { coverage, uninstall } = installCoverageHooks ( browserName ) ;
102
+ if ( wire ) {
103
+ require ( '../lib/utils/utils' ) . setUnderTest ( ) ;
104
+ const connection = new Connection ( ) ;
105
+ const spawnedProcess = childProcess . fork ( path . join ( __dirname , '..' , 'lib' , 'driver.js' ) , [ 'serve' ] , {
106
+ stdio : 'pipe' ,
107
+ detached : true ,
108
+ } ) ;
109
+ spawnedProcess . unref ( ) ;
110
+ const onExit = ( exitCode , signal ) => {
111
+ throw new Error ( `Server closed with exitCode=${ exitCode } signal=${ signal } ` ) ;
112
+ } ;
113
+ spawnedProcess . on ( 'exit' , onExit ) ;
114
+ const transport = new Transport ( spawnedProcess . stdin , spawnedProcess . stdout ) ;
115
+ connection . onmessage = message => transport . send ( JSON . stringify ( message ) ) ;
116
+ transport . onmessage = message => connection . dispatch ( JSON . parse ( message ) ) ;
117
+ const playwrightObject = await connection . waitForObjectWithKnownName ( 'Playwright' ) ;
118
+ await runTest ( playwrightObject ) ;
119
+ spawnedProcess . removeListener ( 'exit' , onExit ) ;
120
+ spawnedProcess . stdin . destroy ( ) ;
121
+ spawnedProcess . stdout . destroy ( ) ;
122
+ spawnedProcess . stderr . destroy ( ) ;
123
+ await teardownCoverage ( ) ;
124
+ } else {
125
+ const playwright = require ( '../index' ) ;
126
+ await runTest ( playwright ) ;
127
+ await teardownCoverage ( ) ;
128
+ }
129
+
130
+ async function teardownCoverage ( ) {
131
+ uninstall ( ) ;
132
+ const coveragePath = path . join ( __dirname , 'coverage-report' , testWorkerIndex + '.json' ) ;
133
+ const coverageJSON = [ ...coverage . keys ( ) ] . filter ( key => coverage . get ( key ) ) ;
134
+ await fs . promises . mkdir ( path . dirname ( coveragePath ) , { recursive : true } ) ;
135
+ await fs . promises . writeFile ( coveragePath , JSON . stringify ( coverageJSON , undefined , 2 ) , 'utf8' ) ;
136
+ }
137
+ } ,
138
+ } )
139
+ . overrideTestFixtures ( {
140
+ testParametersPathSegment : async ( { browserName } , runTest ) => {
141
+ await runTest ( browserName ) ;
142
+ }
76
143
} ) ;
77
144
145
+ fixtures . generateParametrizedTests (
146
+ 'platform' ,
147
+ process . env . PWTESTREPORT ? [ 'win32' , 'darwin' , 'linux' ] : [ process . platform as ( 'win32' | 'linux' | 'darwin' ) ] ) ;
148
+
78
149
export const it = fixtures . it ;
79
150
export const fit = fixtures . fit ;
80
151
export const xit = fixtures . xit ;
@@ -85,77 +156,3 @@ export const beforeEach = fixtures.beforeEach;
85
156
export const afterEach = fixtures . afterEach ;
86
157
export const beforeAll = fixtures . beforeAll ;
87
158
export const afterAll = fixtures . afterAll ;
88
-
89
-
90
- fixtures . generateParametrizedTests (
91
- 'platform' ,
92
- process . env . PWTESTREPORT ? [ 'win32' , 'darwin' , 'linux' ] : [ process . platform as ( 'win32' | 'linux' | 'darwin' ) ] ) ;
93
-
94
- const getExecutablePath = browserName => {
95
- if ( browserName === 'chromium' && process . env . CRPATH )
96
- return process . env . CRPATH ;
97
- if ( browserName === 'firefox' && process . env . FFPATH )
98
- return process . env . FFPATH ;
99
- if ( browserName === 'webkit' && process . env . WKPATH )
100
- return process . env . WKPATH ;
101
- } ;
102
-
103
- fixtures . overrideWorkerFixtures ( {
104
- defaultBrowserOptions : async ( { browserName, headful, slowMo } , runTest ) => {
105
- const executablePath = getExecutablePath ( browserName ) ;
106
- if ( executablePath )
107
- console . error ( `Using executable at ${ executablePath } ` ) ;
108
- await runTest ( {
109
- executablePath,
110
- handleSIGINT : false ,
111
- slowMo,
112
- headless : ! headful ,
113
- } ) ;
114
- } ,
115
-
116
- playwright : async ( { browserName, testWorkerIndex, platform, wire } , runTest ) => {
117
- assert ( platform ) ; // Depend on platform to generate all tests.
118
- const { coverage, uninstall } = installCoverageHooks ( browserName ) ;
119
- if ( wire ) {
120
- require ( '../lib/utils/utils' ) . setUnderTest ( ) ;
121
- const connection = new Connection ( ) ;
122
- const spawnedProcess = childProcess . fork ( path . join ( __dirname , '..' , 'lib' , 'driver.js' ) , [ 'serve' ] , {
123
- stdio : 'pipe' ,
124
- detached : true ,
125
- } ) ;
126
- spawnedProcess . unref ( ) ;
127
- const onExit = ( exitCode , signal ) => {
128
- throw new Error ( `Server closed with exitCode=${ exitCode } signal=${ signal } ` ) ;
129
- } ;
130
- spawnedProcess . on ( 'exit' , onExit ) ;
131
- const transport = new Transport ( spawnedProcess . stdin , spawnedProcess . stdout ) ;
132
- connection . onmessage = message => transport . send ( JSON . stringify ( message ) ) ;
133
- transport . onmessage = message => connection . dispatch ( JSON . parse ( message ) ) ;
134
- const playwrightObject = await connection . waitForObjectWithKnownName ( 'Playwright' ) ;
135
- await runTest ( playwrightObject ) ;
136
- spawnedProcess . removeListener ( 'exit' , onExit ) ;
137
- spawnedProcess . stdin . destroy ( ) ;
138
- spawnedProcess . stdout . destroy ( ) ;
139
- spawnedProcess . stderr . destroy ( ) ;
140
- await teardownCoverage ( ) ;
141
- } else {
142
- const playwright = require ( '../index' ) ;
143
- await runTest ( playwright ) ;
144
- await teardownCoverage ( ) ;
145
- }
146
-
147
- async function teardownCoverage ( ) {
148
- uninstall ( ) ;
149
- const coveragePath = path . join ( __dirname , 'coverage-report' , testWorkerIndex + '.json' ) ;
150
- const coverageJSON = [ ...coverage . keys ( ) ] . filter ( key => coverage . get ( key ) ) ;
151
- await fs . promises . mkdir ( path . dirname ( coveragePath ) , { recursive : true } ) ;
152
- await fs . promises . writeFile ( coveragePath , JSON . stringify ( coverageJSON , undefined , 2 ) , 'utf8' ) ;
153
- }
154
- } ,
155
- } ) ;
156
-
157
- fixtures . overrideTestFixtures ( {
158
- testParametersPathSegment : async ( { browserName } , runTest ) => {
159
- await runTest ( browserName ) ;
160
- }
161
- } ) ;
0 commit comments