@@ -81,7 +81,7 @@ describe('launchers/base.js', () => {
81
81
} )
82
82
} )
83
83
84
- it ( 'should not restart when being force killed' , ( done ) => {
84
+ it ( 'should not restart when being force killed' , async ( ) => {
85
85
const spyOnStart = sinon . spy ( )
86
86
const spyOnKill = sinon . spy ( )
87
87
launcher . on ( 'start' , spyOnStart )
@@ -98,22 +98,18 @@ describe('launchers/base.js', () => {
98
98
launcher . _done ( )
99
99
spyOnKill . callArg ( 0 )
100
100
101
- onceKilled . done ( ( ) => {
102
- expect ( spyOnStart ) . to . not . have . been . called
103
- done ( )
104
- } )
101
+ await onceKilled
102
+ expect ( spyOnStart ) . to . not . have . been . called
105
103
} )
106
104
} )
107
105
108
106
describe ( 'kill' , ( ) => {
109
- it ( 'should manage state' , ( done ) => {
107
+ it ( 'should manage state' , async ( ) => {
110
108
const onceKilled = launcher . kill ( )
111
109
expect ( launcher . state ) . to . equal ( launcher . STATE_BEING_KILLED )
112
110
113
- onceKilled . done ( ( ) => {
114
- expect ( launcher . state ) . to . equal ( launcher . STATE_FINISHED )
115
- done ( )
116
- } )
111
+ await onceKilled
112
+ expect ( launcher . state ) . to . equal ( launcher . STATE_FINISHED )
117
113
} )
118
114
119
115
it ( 'should fire "kill" and wait for all listeners to finish' , ( done ) => {
@@ -152,66 +148,51 @@ describe('launchers/base.js', () => {
152
148
spyOnKill . callArg ( 0 )
153
149
} )
154
150
155
- it ( 'should not fire "kill" if already being killed, but wait for all listeners ' , ( done ) => {
151
+ it ( 'should not fire "kill" second time if already being killed' , async ( ) => {
156
152
const spyOnKill = sinon . spy ( )
157
153
launcher . on ( 'kill' , spyOnKill )
158
154
159
- const expectOnKillListenerIsAlreadyFinishedAndHasBeenOnlyCalledOnce = ( ) => {
160
- expect ( spyOnKill ) . to . have . been . called
161
- expect ( spyOnKill . callCount ) . to . equal ( 1 )
162
- expect ( spyOnKill . finished ) . to . equal ( true )
163
- expect ( launcher . state ) . to . equal ( launcher . STATE_FINISHED )
164
- }
165
-
166
155
launcher . start ( 'http://localhost:9876/' )
167
- const firstKilling = launcher . kill ( ) . then ( ( ) => {
168
- expectOnKillListenerIsAlreadyFinishedAndHasBeenOnlyCalledOnce ( )
169
- } )
170
-
171
- const secondKilling = launcher . kill ( ) . then ( ( ) => {
172
- expectOnKillListenerIsAlreadyFinishedAndHasBeenOnlyCalledOnce ( )
173
- } )
156
+ launcher . kill ( )
157
+ const killing = launcher . kill ( )
174
158
175
159
expect ( launcher . state ) . to . equal ( launcher . STATE_BEING_KILLED )
176
160
177
- _ . defer ( ( ) => {
178
- spyOnKill . finished = true
179
- spyOnKill . callArg ( 0 )
180
- } )
161
+ spyOnKill . callArg ( 0 )
181
162
182
- // finish the test once everything is done
183
- firstKilling . done ( ( ) => secondKilling . done ( ( ) => done ( ) ) )
163
+ await killing
164
+
165
+ expect ( spyOnKill ) . to . have . been . called
166
+ expect ( spyOnKill . callCount ) . to . equal ( 1 )
167
+ expect ( launcher . state ) . to . equal ( launcher . STATE_FINISHED )
184
168
} )
185
169
186
- it ( 'should not kill already crashed browser' , ( done ) => {
170
+ it ( 'should not kill already crashed browser' , async ( ) => {
187
171
const spyOnKill = sinon . spy ( ( killDone ) => killDone ( ) )
188
172
launcher . on ( 'kill' , spyOnKill )
189
173
190
174
launcher . _done ( 'crash' )
191
- launcher . kill ( ) . done ( ( ) => {
192
- expect ( spyOnKill ) . to . not . have . been . called
193
- done ( )
194
- } )
175
+ await launcher . kill ( )
176
+ expect ( spyOnKill ) . to . not . have . been . called
195
177
} )
196
178
} )
197
179
198
180
describe ( 'forceKill' , ( ) => {
199
- it ( 'should cancel restart' , ( done ) => {
181
+ it ( 'should cancel restart' , async ( ) => {
200
182
const spyOnStart = sinon . spy ( )
201
183
launcher . on ( 'start' , spyOnStart )
202
184
203
185
launcher . start ( 'http://localhost:9876/' )
204
186
spyOnStart . resetHistory ( )
205
187
launcher . restart ( )
206
188
207
- launcher . forceKill ( ) . done ( ( ) => {
208
- expect ( launcher . state ) . to . equal ( launcher . STATE_FINISHED )
209
- expect ( spyOnStart ) . to . not . have . been . called
210
- done ( )
211
- } )
189
+ await launcher . forceKill ( )
190
+
191
+ expect ( launcher . state ) . to . equal ( launcher . STATE_FINISHED )
192
+ expect ( spyOnStart ) . to . not . have . been . called
212
193
} )
213
194
214
- it ( 'should not fire "browser_process_failure" even if browser crashes' , ( done ) => {
195
+ it ( 'should not fire "browser_process_failure" even if browser crashes' , async ( ) => {
215
196
const spyOnBrowserProcessFailure = sinon . spy ( )
216
197
emitter . on ( 'browser_process_failure' , spyOnBrowserProcessFailure )
217
198
@@ -223,10 +204,9 @@ describe('launchers/base.js', () => {
223
204
} )
224
205
225
206
launcher . start ( 'http://localhost:9876/' )
226
- launcher . forceKill ( ) . done ( ( ) => {
227
- expect ( spyOnBrowserProcessFailure ) . to . not . have . been . called
228
- done ( )
229
- } )
207
+ await launcher . forceKill ( )
208
+
209
+ expect ( spyOnBrowserProcessFailure ) . to . not . have . been . called
230
210
} )
231
211
} )
232
212
0 commit comments