|
3 | 3 | constcommon=require('../common'); |
4 | 4 | constassert=require('assert'); |
5 | 5 | constcp=require('child_process'); |
| 6 | +const{ test }=require('node:test'); |
6 | 7 | constinternalCp=require('internal/child_process'); |
7 | 8 | constcmd=process.execPath; |
8 | 9 | constargs=['-p','42']; |
9 | 10 | constoptions={windowsHide: true}; |
10 | 11 |
|
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. |
15 | 15 |
|
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'); |
27 | 18 | constchild=cp.spawnSync(cmd,args,options); |
28 | 19 |
|
29 | 20 | assert.strictEqual(child.status,0); |
30 | 21 | assert.strictEqual(child.signal,null); |
31 | 22 | assert.strictEqual(child.stdout.toString().trim(),'42'); |
32 | 23 | 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 | +}); |
34 | 27 |
|
35 | | -{ |
| 28 | +test('spawn() passes windowsHide correctly',(t,done)=>{ |
| 29 | +constspy=t.mock.method(internalCp.ChildProcess.prototype,'spawn'); |
36 | 30 | constchild=cp.spawn(cmd,args,options); |
37 | 31 |
|
38 | 32 | child.on('exit',common.mustCall((code,signal)=>{ |
39 | 33 | assert.strictEqual(code,0); |
40 | 34 | 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(); |
41 | 38 | })); |
42 | | -} |
| 39 | +}); |
43 | 40 |
|
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)=>{ |
46 | 44 | assert.strictEqual(stdout.trim(),'42'); |
47 | 45 | 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