@@ -43,42 +43,57 @@ function childProcessTest (name_, opts_, cb_, args, fn) {
4343
4444function test ( name_ , opts_ , cb_ ) {
4545 var args = getTestArgs ( name_ , opts_ , cb_ )
46- if ( process . env . TEST_ISOLATE === 'child-process' ) {
47- childProcessTest ( name_ , opts_ , cb_ , args , tape . only )
46+ if ( args . skip ) {
47+ test . skip ( name_ , opts_ , cb_ )
48+ } else if ( args . only ) {
49+ test . only ( name_ , opts_ , cb_ )
50+ } else if ( process . env . TEST_ISOLATE === 'child-process' ) {
51+ childProcessTest ( name_ + ' (child process running in ' + process . pid + ')' , opts_ , cb_ , args , tape . only )
4852 } else {
4953 if ( args . opts . isolate === 'child-process' ) {
50- var testName
51- if ( args . name !== '(anonymous)' ) {
52- testName = args . name
53- } else {
54- var sha1 = crypto . createHash ( 'sha1' )
55- sha1 . update ( String ( args . cb ) )
56- testName = sha1 . digest ( )
57- }
58- var childEnv = defaultsDeep ( {
59- TEST_NAME : testName ,
60- TEST_ISOLATE : 'child-process'
61- } , process . env )
62- var res
63- if ( spawnSync ) {
64- res = spawnSync ( process . argv [ 0 ] , process . argv . slice ( 1 ) , defaultsDeep (
65- { stdio : [ 'ignore' , process . stdout , process . stderr ] } ,
66- args . opts . childProcessOpts ,
67- { env : childEnv } )
68- )
69- } else {
70- res = spawnSyncFallback ( process . argv [ 0 ] , process . argv . slice ( 1 ) , defaultsDeep (
71- { stdio : [ 'ignore' , 'pipe' , 'ignore' ] } ,
72- args . opts . childProcessOpts ,
73- { env : childEnv } )
74- )
75- process . stdout . write ( res . stdout ) // very performant
76- }
77- if ( res . status !== 0 ) {
78- tape ( name_ , opts_ , function ( t ) {
79- t . fail ( 'child process exited with ' + res . status )
80- } )
81- }
54+ tape ( name_ , defaultsDeep ( opts_ , { timeout : 10000 } ) , function ( t ) {
55+ var testName
56+ if ( args . name !== '(anonymous)' ) {
57+ testName = args . name
58+ } else {
59+ var sha1 = crypto . createHash ( 'sha1' )
60+ sha1 . update ( String ( args . cb ) )
61+ testName = sha1 . digest ( )
62+ }
63+ var childEnv = defaultsDeep ( {
64+ TEST_NAME : testName ,
65+ TEST_ISOLATE : 'child-process'
66+ } , process . env )
67+ var res
68+ if ( spawnSync ) {
69+ try {
70+ res = spawnSync ( process . argv [ 0 ] , process . argv . slice ( 1 ) , defaultsDeep (
71+ { stdio : [ 'ignore' , process . stdout , process . stderr ] } ,
72+ args . opts . childProcessOpts ,
73+ { env : childEnv } )
74+ )
75+ } catch ( err ) {
76+ t . fail ( 'child process thrown exception: ' + err )
77+ }
78+ } else {
79+ try {
80+ res = spawnSyncFallback ( process . argv [ 0 ] , process . argv . slice ( 1 ) , defaultsDeep (
81+ { stdio : [ 'ignore' , 'pipe' , 'ignore' ] } ,
82+ args . opts . childProcessOpts ,
83+ { env : childEnv } )
84+ )
85+ process . stdout . write ( res . stdout ) // very performant
86+ } catch ( err ) {
87+ t . fail ( 'child process thrown exception: ' + err )
88+ }
89+ }
90+ if ( res . status !== 0 ) {
91+ t . fail ( 'child process failed with ' + res . status )
92+ } else {
93+ t . pass ( 'child process succeeded' )
94+ }
95+ t . end ( )
96+ } )
8297 } else {
8398 tape ( name_ , opts_ , cb_ )
8499 }
0 commit comments