@@ -182,122 +182,73 @@ test('removes exit handler on exit', async t => {
182182 t . false ( exitListeners . includes ( listener ) ) ;
183183} ) ;
184184
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 => {
194186 const { isCanceled} = await execa ( 'noop.js' ) ;
195187 t . false ( isCanceled ) ;
196188} ) ;
197189
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 => {
199191 const { isCanceled} = await t . throwsAsync ( execa ( 'fail.js' ) ) ;
200192 t . false ( isCanceled ) ;
201193} ) ;
202194
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 => {
204196 const { isCanceled} = execaSync ( 'noop.js' ) ;
205197 t . false ( isCanceled ) ;
206198} ) ;
207199
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 => {
209201 const { isCanceled} = t . throws ( ( ) => {
210202 execaSync ( 'fail.js' ) ;
211203 } ) ;
212204 t . false ( isCanceled ) ;
213205} ) ;
214206
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 ) ;
219214} ) ;
220215
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 ( ) ;
224220 const { isCanceled} = await t . throwsAsync ( subprocess ) ;
225221 t . true ( isCanceled ) ;
226222} ) ;
227223
228224test ( '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 } ) ;
230227 subprocess . kill ( ) ;
231228 const { isCanceled} = await t . throwsAsync ( subprocess ) ;
232229 t . false ( isCanceled ) ;
233230} ) ;
234231
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 / } ) ;
249237} ) ;
250238
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 ( ) ;
254244 const { isCanceled} = await t . throwsAsync ( subprocess ) ;
255- t . false ( isCanceled ) ;
245+ t . true ( isCanceled ) ;
256246} ) ;
257247
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