◐ Shell
clean mode source ↗

test: update test-child-process-windows-hide to use node:test · nodejs/node@51ff71a

@@ -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 };

101111-

// 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.

151516-

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');

2718

const child = cp.spawnSync(cmd, args, options);

28192920

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+

});

342735-

{

28+

test('spawn() passes windowsHide correctly', (t, done) => {

29+

const spy = t.mock.method(internalCp.ChildProcess.prototype, 'spawn');

3630

const child = cp.spawn(cmd, args, options);

37313832

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+

});

434044-

{

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) => {

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+

});