Files
node/test/parallel/test-child-process-windows-hide.js
Junsoo Ha de31195b93 test: use spawnSyncAndAssert in windowsHide test
Signed-off-by: Junsoo Ha <junsoo2018@naver.com>
PR-URL: https://github.com/nodejs/node/pull/65351
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
2026-08-23 15:40:14 +00:00

52 lines
1.8 KiB
JavaScript

// Flags: --expose-internals
'use strict';
const common = require('../common');
const assert = require('assert');
const cp = require('child_process');
const { test } = require('node:test');
const internalCp = require('internal/child_process');
const cmd = process.execPath;
const args = ['-p', '42'];
const options = { windowsHide: true };
const { spawnSyncAndAssert } = require('../common/child_process');
// Since windowsHide isn't really observable, this test relies on monkey
// patching spawn() and spawnSync() to verify that the flag is being passed
// through correctly.
test('spawnSync() passes windowsHide correctly', (t) => {
const spy = t.mock.method(internalCp, 'spawnSync');
spawnSyncAndAssert(cmd, args, options, {
stdout: '42',
stderr: '',
trim: true
});
assert.strictEqual(spy.mock.calls.length, 1);
assert.strictEqual(spy.mock.calls[0].arguments[0].windowsHide, true);
});
test('spawn() passes windowsHide correctly', (t, done) => {
const spy = t.mock.method(internalCp.ChildProcess.prototype, 'spawn');
const child = cp.spawn(cmd, args, options);
child.on('exit', common.mustCall((code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
assert.strictEqual(spy.mock.calls.length, 1);
assert.strictEqual(spy.mock.calls[0].arguments[0].windowsHide, true);
done();
}));
});
test('execFile() passes windowsHide correctly', (t, done) => {
const spy = t.mock.method(internalCp.ChildProcess.prototype, 'spawn');
cp.execFile(cmd, args, options, common.mustSucceed((stdout, stderr) => {
assert.strictEqual(stdout.trim(), '42');
assert.strictEqual(stderr.trim(), '');
assert.strictEqual(spy.mock.calls.length, 1);
assert.strictEqual(spy.mock.calls[0].arguments[0].windowsHide, true);
done();
}));
});