@@ -5,18 +5,38 @@ const common = require('../common');
5
5
const assert = require ( 'assert' ) ;
6
6
const cp = require ( 'child_process' ) ;
7
7
8
- // Verify that passing an AbortSignal works
9
- const controller = new AbortController ( ) ;
10
- const { signal } = controller ;
8
+ {
9
+ // Verify that passing an AbortSignal works
10
+ const controller = new AbortController ( ) ;
11
+ const { signal } = controller ;
11
12
12
- const echo = cp . spawn ( 'echo' , [ 'fun' ] , {
13
- encoding : 'utf8' ,
14
- shell : true ,
15
- signal
16
- } ) ;
13
+ const echo = cp . spawn ( 'echo' , [ 'fun' ] , {
14
+ encoding : 'utf8' ,
15
+ shell : true ,
16
+ signal
17
+ } ) ;
17
18
18
- echo . on ( 'error' , common . mustCall ( ( e ) => {
19
- assert . strictEqual ( e . name , 'AbortError' ) ;
20
- } ) ) ;
19
+ echo . on ( 'error' , common . mustCall ( ( e ) => {
20
+ assert . strictEqual ( e . name , 'AbortError' ) ;
21
+ } ) ) ;
21
22
22
- controller . abort ( ) ;
23
+ controller . abort ( ) ;
24
+ }
25
+
26
+ {
27
+ // Verify that passing an already-aborted signal works.
28
+ const controller = new AbortController ( ) ;
29
+ const { signal } = controller ;
30
+
31
+ controller . abort ( ) ;
32
+
33
+ const echo = cp . spawn ( 'echo' , [ 'fun' ] , {
34
+ encoding : 'utf8' ,
35
+ shell : true ,
36
+ signal
37
+ } ) ;
38
+
39
+ echo . on ( 'error' , common . mustCall ( ( e ) => {
40
+ assert . strictEqual ( e . name , 'AbortError' ) ;
41
+ } ) ) ;
42
+ }
0 commit comments