|
3 | 3 | const common = require('../common');
|
4 | 4 | const assert = require('assert');
|
5 | 5 | const cp = require('child_process');
|
| 6 | +const { test } = require('node:test'); |
6 | 7 | const internalCp = require('internal/child_process');
|
7 | 8 | const cmd = process.execPath;
|
8 | 9 | const args = ['-p', '42'];
|
9 | 10 | const options = { 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 |
| -const originalSpawn = internalCp.ChildProcess.prototype.spawn; |
14 |
| -const originalSpawnSync = 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 |
| - return originalSpawn.apply(this, arguments); |
19 |
| -}, 2); |
20 |
| - |
21 |
| -internalCp.spawnSync = common.mustCall(function(options) { |
22 |
| - assert.strictEqual(options.windowsHide, true); |
23 |
| - return originalSpawnSync.apply(this, arguments); |
24 |
| -}); |
25 |
| - |
26 |
| -{ |
| 16 | +test('spawnSync() passes windowsHide correctly', (t) => { |
| 17 | + const spy = t.mock.method(internalCp, 'spawnSync'); |
27 | 18 | const child = 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 | + const spy = t.mock.method(internalCp.ChildProcess.prototype, 'spawn'); |
36 | 30 | const child = 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 |
| - const callback = common.mustSucceed((stdout, stderr) => { |
| 41 | +test('execFile() passes windowsHide correctly', (t, done) => { |
| 42 | + const spy = 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