File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,48 @@
33
const common = require('../common');
44
const assert = require('assert');
55
const cp = require('child_process');
6+
const { test } = require('node:test');
67
const internalCp = require('internal/child_process');
78
const cmd = process.execPath;
89
const args = ['-p', '42'];
910
const options = { windowsHide: true };
1011

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

16-
internalCp.ChildProcess..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');
2718
const child = 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+
const spy = t.mock.method(internalCp.ChildProcess., 'spawn');
3630
const child = 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-
const callback = common.mustSucceed((stdout, stderr) => {
41+
test('execFile() passes windowsHide correctly', (t, done) => {
42+
const spy = t.mock.method(internalCp.ChildProcess., '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)