Skip to content

Commit d17bf2f

Browse files
cjihrigmarco-ippolito
authored andcommitted
test: update test-child-process-bad-stdio to use node:test
This commit updates test/parallel/test-child-process-bad-stdio.js to use node:test. This change prevents multiple child processes from being spawned in parallel, which can be problematic in the CI. PR-URL: #56562 Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent 5660b99 commit d17bf2f

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
'use strict';
22
// Flags: --expose-internals
33
constcommon=require('../common');
4-
constassert=require('assert');
5-
constcp=require('child_process');
64

75
if(process.argv[2]==='child'){
86
setTimeout(()=>{},common.platformTimeout(100));
97
return;
108
}
119

10+
constassert=require('node:assert');
11+
constcp=require('node:child_process');
12+
const{ mock, test }=require('node:test');
13+
const{ ChildProcess }=require('internal/child_process');
14+
1215
// Monkey patch spawn() to create a child process normally, but destroy the
1316
// stdout and stderr streams. This replicates the conditions where the streams
1417
// cannot be properly created.
15-
constChildProcess=require('internal/child_process').ChildProcess;
1618
constoriginal=ChildProcess.prototype.spawn;
1719

18-
ChildProcess.prototype.spawn=function(){
20+
mock.method(ChildProcess.prototype,'spawn',function(){
1921
consterr=original.apply(this,arguments);
2022

2123
this.stdout.destroy();
@@ -24,40 +26,40 @@ ChildProcess.prototype.spawn = function() {
2426
this.stderr=null;
2527

2628
returnerr;
27-
};
29+
});
2830

2931
functioncreateChild(options,callback){
3032
constcmd=`"${process.execPath}" "${__filename}" child`;
3133

3234
returncp.exec(cmd,options,common.mustCall(callback));
3335
}
3436

35-
// Verify that normal execution of a child process is handled.
36-
{
37+
test('normal execution of a child process is handled',(_,done)=>{
3738
createChild({},(err,stdout,stderr)=>{
3839
assert.strictEqual(err,null);
3940
assert.strictEqual(stdout,'');
4041
assert.strictEqual(stderr,'');
42+
done();
4143
});
42-
}
44+
});
4345

44-
// Verify that execution with an error event is handled.
45-
{
46+
test('execution with an error event is handled',(_,done)=>{
4647
consterror=newError('foo');
4748
constchild=createChild({},(err,stdout,stderr)=>{
4849
assert.strictEqual(err,error);
4950
assert.strictEqual(stdout,'');
5051
assert.strictEqual(stderr,'');
52+
done();
5153
});
5254

5355
child.emit('error',error);
54-
}
56+
});
5557

56-
// Verify that execution with a killed process is handled.
57-
{
58+
test('execution with a killed process is handled',(_,done)=>{
5859
createChild({timeout: 1},(err,stdout,stderr)=>{
5960
assert.strictEqual(err.killed,true);
6061
assert.strictEqual(stdout,'');
6162
assert.strictEqual(stderr,'');
63+
done();
6264
});
63-
}
65+
});

0 commit comments

Comments
 (0)