@@ -5,51 +5,71 @@ const assert = require('assert');
5
5
const { ChildProcess } = require ( 'child_process' ) ;
6
6
assert . strictEqual ( typeof ChildProcess , 'function' ) ;
7
7
8
+ function typeName ( value ) {
9
+ return value === null ? 'null' : typeof value ;
10
+ }
11
+
8
12
{
9
13
// Verify that invalid options to spawn() throw.
10
14
const child = new ChildProcess ( ) ;
11
- const re = / ^ T y p e E r r o r : " o p t i o n s " m u s t b e a n o b j e c t $ / ;
12
15
13
16
[ undefined , null , 'foo' , 0 , 1 , NaN , true , false ] . forEach ( ( options ) => {
14
17
assert . throws ( ( ) => {
15
18
child . spawn ( options ) ;
16
- } , re ) ;
19
+ } , common . expectsError ( {
20
+ code : 'ERR_INVALID_ARG_TYPE' ,
21
+ type : TypeError ,
22
+ message : 'The "options" argument must be of type object. Received type ' +
23
+ typeName ( options )
24
+ } ) ) ;
17
25
} ) ;
18
26
}
19
27
20
28
{
21
29
// Verify that spawn throws if file is not a string.
22
30
const child = new ChildProcess ( ) ;
23
- const re = / ^ T y p e E r r o r : " f i l e " m u s t b e a s t r i n g $ / ;
24
31
25
32
[ undefined , null , 0 , 1 , NaN , true , false , { } ] . forEach ( ( file ) => {
26
33
assert . throws ( ( ) => {
27
34
child . spawn ( { file } ) ;
28
- } , re ) ;
35
+ } , common . expectsError ( {
36
+ code : 'ERR_INVALID_ARG_TYPE' ,
37
+ type : TypeError ,
38
+ message : 'The "options.file" property must be of type string. Received ' +
39
+ 'type ' + typeName ( file )
40
+ } ) ) ;
29
41
} ) ;
30
42
}
31
43
32
44
{
33
45
// Verify that spawn throws if envPairs is not an array or undefined.
34
46
const child = new ChildProcess ( ) ;
35
- const re = / ^ T y p e E r r o r : " e n v P a i r s " m u s t b e a n a r r a y $ / ;
36
47
37
48
[ null , 0 , 1 , NaN , true , false , { } , 'foo' ] . forEach ( ( envPairs ) => {
38
49
assert . throws ( ( ) => {
39
50
child . spawn ( { envPairs, stdio : [ 'ignore' , 'ignore' , 'ignore' , 'ipc' ] } ) ;
40
- } , re ) ;
51
+ } , common . expectsError ( {
52
+ code : 'ERR_INVALID_ARG_TYPE' ,
53
+ type : TypeError ,
54
+ message : 'The "options.envPairs" property must be of type array. ' +
55
+ 'Received type ' + typeName ( envPairs )
56
+ } ) ) ;
41
57
} ) ;
42
58
}
43
59
44
60
{
45
61
// Verify that spawn throws if args is not an array or undefined.
46
62
const child = new ChildProcess ( ) ;
47
- const re = / ^ T y p e E r r o r : " a r g s " m u s t b e a n a r r a y $ / ;
48
63
49
64
[ null , 0 , 1 , NaN , true , false , { } , 'foo' ] . forEach ( ( args ) => {
50
65
assert . throws ( ( ) => {
51
66
child . spawn ( { file : 'foo' , args } ) ;
52
- } , re ) ;
67
+ } , common . expectsError ( {
68
+ code : 'ERR_INVALID_ARG_TYPE' ,
69
+ type : TypeError ,
70
+ message : 'The "options.args" property must be of type array. Received ' +
71
+ 'type ' + typeName ( args )
72
+ } ) ) ;
53
73
} ) ;
54
74
}
55
75
0 commit comments