Skip to content

Commit

Permalink
add a fixed node test
Browse files Browse the repository at this point in the history
  • Loading branch information
RiskyMH committed Feb 11, 2025
1 parent 6b45f07 commit ea3f262
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 13 deletions.
25 changes: 13 additions & 12 deletions src/js/node/child_process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ var ArrayPrototypeMap = Array.prototype.map;
var ArrayPrototypeIncludes = Array.prototype.includes;
var ArrayPrototypeSlice = Array.prototype.slice;
var ArrayPrototypeUnshift = Array.prototype.unshift;
var ArrayPrototypeLastIndexOf = Array.prototype.lastIndexOf;
var ArrayPrototypeSplice = Array.prototype.splice;
const ArrayPrototypeFilter = Array.prototype.filter;
const ArrayPrototypeSort = Array.prototype.sort;
const StringPrototypeToUpperCase = String.prototype.toUpperCase;
Expand Down Expand Up @@ -748,20 +750,19 @@ function fork(modulePath, args = [], options) {
options.execPath = options.execPath || process.execPath;
validateArgumentNullCheck(options.execPath, "options.execPath");

// Prepare arguments for fork:
// execArgv = options.execArgv || process.execArgv;
// validateArgumentsNullCheck(execArgv, "options.execArgv");
execArgv = options.execArgv || process.execArgv;
validateArgumentsNullCheck(execArgv, "options.execArgv");

// if (execArgv === process.execArgv && process._eval != null) {
// const index = ArrayPrototypeLastIndexOf.$call(execArgv, process._eval);
// if (index > 0) {
// // Remove the -e switch to avoid fork bombing ourselves.
// execArgv = ArrayPrototypeSlice.$call(execArgv);
// ArrayPrototypeSplice.$call(execArgv, index - 1, 2);
// }
// }
if (execArgv === process.execArgv && process._eval != null) {
const index = ArrayPrototypeLastIndexOf.$call(execArgv, process._eval);
if (index > 0) {
// Remove the -e switch to avoid fork bombing ourselves.
execArgv = ArrayPrototypeSlice.$call(execArgv);
ArrayPrototypeSplice.$call(execArgv, index - 1, 2);
}
}

args = [/*...execArgv,*/ modulePath, ...args];
args = [...execArgv, modulePath, ...args];

if (typeof options.stdio === "string") {
options.stdio = stdioStringToArray(options.stdio, "ipc");
Expand Down
2 changes: 1 addition & 1 deletion test/cli/run/run-eval.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function group(run: (code: string) => SyncSubprocess<"pipe", "inherit">) {

test("process.argv", async () => {
const { stdout } = run("console.log(process.argv)");
expect(stdout.toString("utf8")).toEqual(`[ "${bunExe()}", "-" ]\n`);
expect(JSON.parse(stdout.toString("utf8"))).toEqual([bunExe(), "-"]);
});
}

Expand Down
49 changes: 49 additions & 0 deletions test/js/node/test/parallel/test-child-process-fork-exec-argv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
const common = require('../common');
const assert = require('assert');
const child_process = require('child_process');
const spawn = child_process.spawn;
const fork = child_process.fork;

if (process.argv[2] === 'fork') {
process.stdout.write(JSON.stringify(process.execArgv), function() {
process.exit();
});
} else if (process.argv[2] === 'child') {
fork(__filename, ['fork']);
} else {
const execArgv = ['--stack-size=256'];
const args = [__filename, 'child', 'arg0'];

const child = spawn(process.execPath, execArgv.concat(args));
let out = '';

child.stdout.on('data', function(chunk) {
out += chunk;
});

child.on('exit', common.mustCall(function() {
assert.deepStrictEqual(JSON.parse(out), execArgv);
}));
}

0 comments on commit ea3f262

Please sign in to comment.