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