@@ -182,122 +182,73 @@ test('removes exit handler on exit', async t => {
182
182
t . false ( exitListeners . includes ( listener ) ) ;
183
183
} ) ;
184
184
185
- test ( 'cancel method kills the subprocess' , async t => {
186
- const subprocess = execa ( 'node' ) ;
187
- subprocess . cancel ( ) ;
188
- t . true ( subprocess . killed ) ;
189
- const { isTerminated} = await t . throwsAsync ( subprocess ) ;
190
- t . true ( isTerminated ) ;
191
- } ) ;
192
-
193
- test ( 'result.isCanceled is false when spawned.cancel() isn\'t called (success)' , async t => {
185
+ test ( 'result.isCanceled is false when abort isn\'t called (success)' , async t => {
194
186
const { isCanceled} = await execa ( 'noop.js' ) ;
195
187
t . false ( isCanceled ) ;
196
188
} ) ;
197
189
198
- test ( 'result.isCanceled is false when spawned.cancel() isn\'t called (failure)' , async t => {
190
+ test ( 'result.isCanceled is false when abort isn\'t called (failure)' , async t => {
199
191
const { isCanceled} = await t . throwsAsync ( execa ( 'fail.js' ) ) ;
200
192
t . false ( isCanceled ) ;
201
193
} ) ;
202
194
203
- test ( 'result.isCanceled is false when spawned.cancel() isn\'t called in sync mode (success)' , t => {
195
+ test ( 'result.isCanceled is false when abort isn\'t called in sync mode (success)' , t => {
204
196
const { isCanceled} = execaSync ( 'noop.js' ) ;
205
197
t . false ( isCanceled ) ;
206
198
} ) ;
207
199
208
- test ( 'result.isCanceled is false when spawned.cancel() isn\'t called in sync mode (failure)' , t => {
200
+ test ( 'result.isCanceled is false when abort isn\'t called in sync mode (failure)' , t => {
209
201
const { isCanceled} = t . throws ( ( ) => {
210
202
execaSync ( 'fail.js' ) ;
211
203
} ) ;
212
204
t . false ( isCanceled ) ;
213
205
} ) ;
214
206
215
- test ( 'calling cancel method throws an error with message "Command was canceled"' , async t => {
216
- const subprocess = execa ( 'noop.js' ) ;
217
- subprocess . cancel ( ) ;
218
- await t . throwsAsync ( subprocess , { message : / C o m m a n d w a s c a n c e l e d / } ) ;
207
+ test ( 'calling abort is not considered a signal termination' , async t => {
208
+ const abortController = new AbortController ( ) ;
209
+ const subprocess = execa ( 'noop.js' , { signal : abortController . signal } ) ;
210
+ abortController . abort ( ) ;
211
+ const { isTerminated, signal} = await t . throwsAsync ( subprocess ) ;
212
+ t . false ( isTerminated ) ;
213
+ t . is ( signal , undefined ) ;
219
214
} ) ;
220
215
221
- test ( 'error.isCanceled is true when cancel method is used' , async t => {
222
- const subprocess = execa ( 'noop.js' ) ;
223
- subprocess . cancel ( ) ;
216
+ test ( 'error.isCanceled is true when abort is used' , async t => {
217
+ const abortController = new AbortController ( ) ;
218
+ const subprocess = execa ( 'noop.js' , { signal : abortController . signal } ) ;
219
+ abortController . abort ( ) ;
224
220
const { isCanceled} = await t . throwsAsync ( subprocess ) ;
225
221
t . true ( isCanceled ) ;
226
222
} ) ;
227
223
228
224
test ( 'error.isCanceled is false when kill method is used' , async t => {
229
- const subprocess = execa ( 'noop.js' ) ;
225
+ const abortController = new AbortController ( ) ;
226
+ const subprocess = execa ( 'noop.js' , { signal : abortController . signal } ) ;
230
227
subprocess . kill ( ) ;
231
228
const { isCanceled} = await t . throwsAsync ( subprocess ) ;
232
229
t . false ( isCanceled ) ;
233
230
} ) ;
234
231
235
- test ( 'calling cancel method twice should show the same behaviour as calling it once' , async t => {
236
- const subprocess = execa ( 'noop.js' ) ;
237
- subprocess . cancel ( ) ;
238
- subprocess . cancel ( ) ;
239
- const { isCanceled} = await t . throwsAsync ( subprocess ) ;
240
- t . true ( isCanceled ) ;
241
- t . true ( subprocess . killed ) ;
242
- } ) ;
243
-
244
- test ( 'calling cancel method on a successfully completed process does not make result.isCanceled true' , async t => {
245
- const subprocess = execa ( 'noop.js' ) ;
246
- const { isCanceled} = await subprocess ;
247
- subprocess . cancel ( ) ;
248
- t . false ( isCanceled ) ;
232
+ test ( 'calling abort throws an error with message "Command was canceled"' , async t => {
233
+ const abortController = new AbortController ( ) ;
234
+ const subprocess = execa ( 'noop.js' , { signal : abortController . signal } ) ;
235
+ abortController . abort ( ) ;
236
+ await t . throwsAsync ( subprocess , { message : / C o m m a n d w a s c a n c e l e d / } ) ;
249
237
} ) ;
250
238
251
- test ( 'calling cancel method on a process which has been killed does not make error.isCanceled true' , async t => {
252
- const subprocess = execa ( 'noop.js' ) ;
253
- subprocess . kill ( ) ;
239
+ test ( 'calling abort twice should show the same behaviour as calling it once' , async t => {
240
+ const abortController = new AbortController ( ) ;
241
+ const subprocess = execa ( 'noop.js' , { signal : abortController . signal } ) ;
242
+ abortController . abort ( ) ;
243
+ abortController . abort ( ) ;
254
244
const { isCanceled} = await t . throwsAsync ( subprocess ) ;
255
- t . false ( isCanceled ) ;
245
+ t . true ( isCanceled ) ;
256
246
} ) ;
257
247
258
- if ( globalThis . AbortController !== undefined ) {
259
- test ( 'calling abort throws an error with message "Command was canceled"' , async t => {
260
- const abortController = new AbortController ( ) ;
261
- const subprocess = execa ( 'noop.js' , [ ] , { signal : abortController . signal } ) ;
262
- abortController . abort ( ) ;
263
- await t . throwsAsync ( subprocess , { message : / C o m m a n d w a s c a n c e l e d / } ) ;
264
- } ) ;
265
-
266
- test ( 'calling abort twice should show the same behaviour as calling it once' , async t => {
267
- const abortController = new AbortController ( ) ;
268
- const subprocess = execa ( 'noop.js' , [ ] , { signal : abortController . signal } ) ;
269
- abortController . abort ( ) ;
270
- abortController . abort ( ) ;
271
- const { isCanceled} = await t . throwsAsync ( subprocess ) ;
272
- t . true ( isCanceled ) ;
273
- t . true ( subprocess . killed ) ;
274
- } ) ;
275
-
276
- test ( 'calling abort on a successfully completed process does not make result.isCanceled true' , async t => {
277
- const abortController = new AbortController ( ) ;
278
- const subprocess = execa ( 'noop.js' , [ ] , { signal : abortController . signal } ) ;
279
- const { isCanceled} = await subprocess ;
280
- abortController . abort ( ) ;
281
- t . false ( isCanceled ) ;
282
- } ) ;
283
-
284
- test ( 'calling cancel after abort should show the same behaviour as only calling cancel' , async t => {
285
- const abortController = new AbortController ( ) ;
286
- const subprocess = execa ( 'noop.js' , [ ] , { signal : abortController . signal } ) ;
287
- abortController . abort ( ) ;
288
- subprocess . cancel ( ) ;
289
- const { isCanceled} = await t . throwsAsync ( subprocess ) ;
290
- t . true ( isCanceled ) ;
291
- t . true ( subprocess . killed ) ;
292
- } ) ;
293
-
294
- test ( 'calling abort after cancel should show the same behaviour as only calling cancel' , async t => {
295
- const abortController = new AbortController ( ) ;
296
- const subprocess = execa ( 'noop.js' , [ ] , { signal : abortController . signal } ) ;
297
- subprocess . cancel ( ) ;
298
- abortController . abort ( ) ;
299
- const { isCanceled} = await t . throwsAsync ( subprocess ) ;
300
- t . true ( isCanceled ) ;
301
- t . true ( subprocess . killed ) ;
302
- } ) ;
303
- }
248
+ test ( 'calling abort on a successfully completed process does not make result.isCanceled true' , async t => {
249
+ const abortController = new AbortController ( ) ;
250
+ const subprocess = execa ( 'noop.js' , { signal : abortController . signal } ) ;
251
+ const result = await subprocess ;
252
+ abortController . abort ( ) ;
253
+ t . false ( result . isCanceled ) ;
254
+ } ) ;
0 commit comments