@@ -5,51 +5,71 @@ const assert = require('assert');
55const { ChildProcess } = require ( 'child_process' ) ;
66assert . strictEqual ( typeof ChildProcess , 'function' ) ;
77
8+ function typeName ( value ) {
9+ return value === null ? 'null' : typeof value ;
10+ }
11+
812{
913 // Verify that invalid options to spawn() throw.
1014 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 $ / ;
1215
1316 [ undefined , null , 'foo' , 0 , 1 , NaN , true , false ] . forEach ( ( options ) => {
1417 assert . throws ( ( ) => {
1518 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+ } ) ) ;
1725 } ) ;
1826}
1927
2028{
2129 // Verify that spawn throws if file is not a string.
2230 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 $ / ;
2431
2532 [ undefined , null , 0 , 1 , NaN , true , false , { } ] . forEach ( ( file ) => {
2633 assert . throws ( ( ) => {
2734 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+ } ) ) ;
2941 } ) ;
3042}
3143
3244{
3345 // Verify that spawn throws if envPairs is not an array or undefined.
3446 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 $ / ;
3647
3748 [ null , 0 , 1 , NaN , true , false , { } , 'foo' ] . forEach ( ( envPairs ) => {
3849 assert . throws ( ( ) => {
3950 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+ } ) ) ;
4157 } ) ;
4258}
4359
4460{
4561 // Verify that spawn throws if args is not an array or undefined.
4662 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 $ / ;
4863
4964 [ null , 0 , 1 , NaN , true , false , { } , 'foo' ] . forEach ( ( args ) => {
5065 assert . throws ( ( ) => {
5166 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+ } ) ) ;
5373 } ) ;
5474}
5575
0 commit comments