-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathtest-child-process-spawn-module-exports.js
More file actions
33 lines (26 loc) · 986 Bytes
/
test-child-process-spawn-module-exports.js
File metadata and controls
33 lines (26 loc) · 986 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict';
const common = require('../common');
const assert = require('assert');
const cp = require('child_process');
// Verify that fork() and execFile() call spawn through module.exports
// so that user-level wrapping of child_process.spawn works correctly.
// This is consistent with exec() which already uses module.exports.execFile().
if (process.argv[2] === 'child') {
process.exit(0);
}
const originalSpawn = cp.spawn;
// Test that fork() uses module.exports.spawn.
cp.spawn = common.mustCall(function(...args) {
cp.spawn = originalSpawn;
return originalSpawn.apply(this, args);
});
const child = cp.fork(__filename, ['child']);
child.on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0);
// Test that execFile() uses module.exports.spawn.
cp.spawn = common.mustCall(function(...args) {
cp.spawn = originalSpawn;
return originalSpawn.apply(this, args);
});
cp.execFile(process.execPath, ['--version'], common.mustSucceed());
}));