Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function fork(modulePath, args = [], options) {
throw new ERR_CHILD_PROCESS_IPC_REQUIRED('options.stdio');
}

return spawn(options.execPath, args, options);
return module.exports.spawn(options.execPath, args, options);
}

function _forkChild(fd, serializationMode) {
Expand Down Expand Up @@ -346,7 +346,7 @@ function execFile(file, args, options, callback) {

options.killSignal = sanitizeKillSignal(options.killSignal);

const child = spawn(file, args, {
const child = module.exports.spawn(file, args, {
cwd: options.cwd,
env: options.env,
gid: options.gid,
Expand Down
33 changes: 33 additions & 0 deletions test/parallel/test-child-process-spawn-module-exports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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());
}));
Loading