17
17
18
18
const path = require ( 'path' ) ;
19
19
const { spawn, execSync} = require ( 'child_process' ) ;
20
- const { FFOX , CHROMIUM , WEBKIT , WIN , LINUX } = require ( './utils' ) . testOptions ( browserType ) ;
20
+ const { FFOX , CHROMIUM , WEBKIT , WIN , LINUX , HEADLESS } = testOptions ;
21
+
22
+ const playwrightPath = path . join ( __dirname , '..' ) ;
21
23
22
24
class Wrapper {
23
- constructor ( state , extraOptions ) {
25
+ constructor ( browserType , defaultBrowserOptions , extraOptions ) {
24
26
this . _output = new Map ( ) ;
25
27
this . _outputCallback = new Map ( ) ;
26
28
27
- this . _browserType = state . browserType ;
28
- const launchOptions = { ...state . defaultBrowserOptions ,
29
+ this . _browserType = browserType ;
30
+ const launchOptions = { ...defaultBrowserOptions ,
29
31
handleSIGINT : true ,
30
32
handleSIGTERM : true ,
31
33
handleSIGHUP : true ,
32
- executablePath : state . browserType . executablePath ( ) ,
34
+ executablePath : browserType . executablePath ( ) ,
33
35
logger : undefined ,
34
36
} ;
35
37
const options = {
36
- playwrightFile : path . join ( state . playwrightPath , 'index' ) ,
37
- browserTypeName : state . browserType . name ( ) ,
38
+ playwrightFile : path . join ( playwrightPath , 'index' ) ,
39
+ browserTypeName : browserType . name ( ) ,
38
40
launchOptions,
39
41
...extraOptions ,
40
42
} ;
@@ -89,15 +91,20 @@ class Wrapper {
89
91
}
90
92
}
91
93
92
- async function setup ( state , options = { } ) {
93
- const wrapper = new Wrapper ( state , options ) ;
94
+ registerFixture ( 'wrapper' , async ( { browserType , defaultBrowserOptions } , test ) => {
95
+ const wrapper = new Wrapper ( browserType , defaultBrowserOptions ) ;
94
96
await wrapper . connect ( ) ;
95
- return wrapper ;
96
- }
97
+ await test ( wrapper ) ;
98
+ } ) ;
99
+
100
+ registerFixture ( 'stallingWrapper' , async ( { browserType, defaultBrowserOptions} , test ) => {
101
+ const wrapper = new Wrapper ( browserType , defaultBrowserOptions , { stallOnClose : true } ) ;
102
+ await wrapper . connect ( ) ;
103
+ await test ( wrapper ) ;
104
+ } ) ;
97
105
98
106
describe ( 'Fixtures' , function ( ) {
99
- it . slow ( ) ( 'should close the browser when the node process closes' , async state => {
100
- const wrapper = await setup ( state ) ;
107
+ it . slow ( ) ( 'should close the browser when the node process closes' , async ( { wrapper} ) => {
101
108
if ( WIN )
102
109
execSync ( `taskkill /pid ${ wrapper . child ( ) . pid } /T /F` ) ;
103
110
else
@@ -107,67 +114,62 @@ describe('Fixtures', function() {
107
114
// so we don't check it here.
108
115
} ) ;
109
116
110
- describe . skip ( WIN ) . skip ( ! HEADLESS ) ( 'signals' , ( ) => {
117
+ describe . skip ( WIN || ! HEADLESS ) ( 'signals' , ( ) => {
111
118
// Cannot reliably send signals on Windows.
112
- it . slow ( ) ( 'should report browser close signal' , async state => {
113
- const wrapper = await setup ( state ) ;
119
+ it . slow ( ) ( 'should report browser close signal' , async ( { wrapper} ) => {
114
120
const pid = await wrapper . out ( 'pid' ) ;
115
121
process . kill ( - pid , 'SIGTERM' ) ;
116
122
expect ( await wrapper . out ( 'exitCode' ) ) . toBe ( 'null' ) ;
117
123
expect ( await wrapper . out ( 'signal' ) ) . toBe ( 'SIGTERM' ) ;
118
124
process . kill ( wrapper . child ( ) . pid ) ;
119
125
await wrapper . childExitCode ( ) ;
120
126
} ) ;
121
- it . slow ( ) ( 'should report browser close signal 2' , async state => {
122
- const wrapper = await setup ( state ) ;
127
+ it . slow ( ) ( 'should report browser close signal 2' , async ( { wrapper} ) => {
123
128
const pid = await wrapper . out ( 'pid' ) ;
124
129
process . kill ( - pid , 'SIGKILL' ) ;
125
130
expect ( await wrapper . out ( 'exitCode' ) ) . toBe ( 'null' ) ;
126
131
expect ( await wrapper . out ( 'signal' ) ) . toBe ( 'SIGKILL' ) ;
127
132
process . kill ( wrapper . child ( ) . pid ) ;
128
133
await wrapper . childExitCode ( ) ;
129
134
} ) ;
130
- it . slow ( ) ( 'should close the browser on SIGINT' , async state => {
131
- const wrapper = await setup ( state ) ;
135
+ it . slow ( ) ( 'should close the browser on SIGINT' , async ( { wrapper} ) => {
132
136
process . kill ( wrapper . child ( ) . pid , 'SIGINT' ) ;
133
137
expect ( await wrapper . out ( 'exitCode' ) ) . toBe ( '0' ) ;
134
138
expect ( await wrapper . out ( 'signal' ) ) . toBe ( 'null' ) ;
135
139
expect ( await wrapper . childExitCode ( ) ) . toBe ( 130 ) ;
136
140
} ) ;
137
- it . slow ( ) ( 'should close the browser on SIGTERM' , async state => {
138
- const wrapper = await setup ( state ) ;
141
+ it . slow ( ) ( 'should close the browser on SIGTERM' , async ( { wrapper} ) => {
139
142
process . kill ( wrapper . child ( ) . pid , 'SIGTERM' ) ;
140
143
expect ( await wrapper . out ( 'exitCode' ) ) . toBe ( '0' ) ;
141
144
expect ( await wrapper . out ( 'signal' ) ) . toBe ( 'null' ) ;
142
145
expect ( await wrapper . childExitCode ( ) ) . toBe ( 0 ) ;
143
146
} ) ;
144
- it . slow ( ) ( 'should close the browser on SIGHUP' , async state => {
145
- const wrapper = await setup ( state ) ;
147
+ it . slow ( ) ( 'should close the browser on SIGHUP' , async ( { wrapper} ) => {
146
148
process . kill ( wrapper . child ( ) . pid , 'SIGHUP' ) ;
147
149
expect ( await wrapper . out ( 'exitCode' ) ) . toBe ( '0' ) ;
148
150
expect ( await wrapper . out ( 'signal' ) ) . toBe ( 'null' ) ;
149
151
expect ( await wrapper . childExitCode ( ) ) . toBe ( 0 ) ;
150
152
} ) ;
151
- it . slow ( ) ( 'should kill the browser on double SIGINT' , async state => {
152
- const wrapper = await setup ( state , { stallOnClose : true } ) ;
153
+ it . slow ( ) ( 'should kill the browser on double SIGINT' , async ( { stallingWrapper } ) => {
154
+ const wrapper = stallingWrapper ;
153
155
process . kill ( wrapper . child ( ) . pid , 'SIGINT' ) ;
154
156
await wrapper . out ( 'stalled' ) ;
155
157
process . kill ( wrapper . child ( ) . pid , 'SIGINT' ) ;
156
158
expect ( await wrapper . out ( 'exitCode' ) ) . toBe ( 'null' ) ;
157
159
expect ( await wrapper . out ( 'signal' ) ) . toBe ( 'SIGKILL' ) ;
158
160
expect ( await wrapper . childExitCode ( ) ) . toBe ( 130 ) ;
159
161
} ) ;
160
- it . slow ( ) ( 'should kill the browser on SIGINT + SIGTERM' , async state => {
161
- const wrapper = await setup ( state , { stallOnClose : true } ) ;
162
+ it . slow ( ) ( 'should kill the browser on SIGINT + SIGTERM' , async ( { stallingWrapper } ) => {
163
+ const wrapper = stallingWrapper ;
162
164
process . kill ( wrapper . child ( ) . pid , 'SIGINT' ) ;
163
165
await wrapper . out ( 'stalled' ) ;
164
166
process . kill ( wrapper . child ( ) . pid , 'SIGTERM' ) ;
165
167
expect ( await wrapper . out ( 'exitCode' ) ) . toBe ( 'null' ) ;
166
168
expect ( await wrapper . out ( 'signal' ) ) . toBe ( 'SIGKILL' ) ;
167
169
expect ( await wrapper . childExitCode ( ) ) . toBe ( 0 ) ;
168
170
} ) ;
169
- it . slow ( ) ( 'should kill the browser on SIGTERM + SIGINT' , async state => {
170
- const wrapper = await setup ( state , { stallOnClose : true } ) ;
171
+ it . slow ( ) ( 'should kill the browser on SIGTERM + SIGINT' , async ( { stallingWrapper } ) => {
172
+ const wrapper = stallingWrapper ;
171
173
process . kill ( wrapper . child ( ) . pid , 'SIGTERM' ) ;
172
174
await wrapper . out ( 'stalled' ) ;
173
175
process . kill ( wrapper . child ( ) . pid , 'SIGINT' ) ;
@@ -179,8 +181,8 @@ describe('Fixtures', function() {
179
181
} ) ;
180
182
181
183
describe ( 'StackTrace' , ( ) => {
182
- it ( 'caller file path' , async state => {
183
- const stackTrace = require ( path . join ( state . playwrightPath , 'lib' , 'utils' , 'stackTrace' ) ) ;
184
+ it ( 'caller file path' , async ( { } ) => {
185
+ const stackTrace = require ( path . join ( playwrightPath , 'lib' , 'utils' , 'stackTrace' ) ) ;
184
186
const callme = require ( './fixtures/callback' ) ;
185
187
const filePath = callme ( ( ) => {
186
188
return stackTrace . getCallerFilePath ( path . join ( __dirname , 'fixtures' ) + path . sep ) ;
0 commit comments