Skip to content

Commit 51ff71a

Browse files
cjihrigmarco-ippolito
authored andcommitted
test: update test-child-process-windows-hide to use node:test
This commit updates test/parallel/test-child-process-windows-hide.js to use node:test. This allows the test to use the built in mocking functionality instead of managing spies manually. It also prevents multiple child processes from being spawned in parallel, which can be problematic in the CI. PR-URL: #56437 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent bc8c39b commit 51ff71a

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

‎test/parallel/test-child-process-windows-hide.js‎

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,48 @@
33
constcommon=require('../common');
44
constassert=require('assert');
55
constcp=require('child_process');
6+
const{ test }=require('node:test');
67
constinternalCp=require('internal/child_process');
78
constcmd=process.execPath;
89
constargs=['-p','42'];
910
constoptions={windowsHide: true};
1011

11-
// Since windowsHide isn't really observable, monkey patch spawn() and
12-
// spawnSync() to verify that the flag is being passed through correctly.
13-
constoriginalSpawn=internalCp.ChildProcess.prototype.spawn;
14-
constoriginalSpawnSync=internalCp.spawnSync;
12+
// Since windowsHide isn't really observable, this test relies on monkey
13+
// patching spawn() and spawnSync() to verify that the flag is being passed
14+
// through correctly.
1515

16-
internalCp.ChildProcess.prototype.spawn=common.mustCall(function(options){
17-
assert.strictEqual(options.windowsHide,true);
18-
returnoriginalSpawn.apply(this,arguments);
19-
},2);
20-
21-
internalCp.spawnSync=common.mustCall(function(options){
22-
assert.strictEqual(options.windowsHide,true);
23-
returnoriginalSpawnSync.apply(this,arguments);
24-
});
25-
26-
{
16+
test('spawnSync() passes windowsHide correctly',(t)=>{
17+
constspy=t.mock.method(internalCp,'spawnSync');
2718
constchild=cp.spawnSync(cmd,args,options);
2819

2920
assert.strictEqual(child.status,0);
3021
assert.strictEqual(child.signal,null);
3122
assert.strictEqual(child.stdout.toString().trim(),'42');
3223
assert.strictEqual(child.stderr.toString().trim(),'');
33-
}
24+
assert.strictEqual(spy.mock.calls.length,1);
25+
assert.strictEqual(spy.mock.calls[0].arguments[0].windowsHide,true);
26+
});
3427

35-
{
28+
test('spawn() passes windowsHide correctly',(t,done)=>{
29+
constspy=t.mock.method(internalCp.ChildProcess.prototype,'spawn');
3630
constchild=cp.spawn(cmd,args,options);
3731

3832
child.on('exit',common.mustCall((code,signal)=>{
3933
assert.strictEqual(code,0);
4034
assert.strictEqual(signal,null);
35+
assert.strictEqual(spy.mock.calls.length,1);
36+
assert.strictEqual(spy.mock.calls[0].arguments[0].windowsHide,true);
37+
done();
4138
}));
42-
}
39+
});
4340

44-
{
45-
constcallback=common.mustSucceed((stdout,stderr)=>{
41+
test('execFile() passes windowsHide correctly',(t,done)=>{
42+
constspy=t.mock.method(internalCp.ChildProcess.prototype,'spawn');
43+
cp.execFile(cmd,args,options,common.mustSucceed((stdout,stderr)=>{
4644
assert.strictEqual(stdout.trim(),'42');
4745
assert.strictEqual(stderr.trim(),'');
48-
});
49-
50-
cp.execFile(cmd,args,options,callback);
51-
}
46+
assert.strictEqual(spy.mock.calls.length,1);
47+
assert.strictEqual(spy.mock.calls[0].arguments[0].windowsHide,true);
48+
done();
49+
}));
50+
});

0 commit comments

Comments
(0)