Skip to content

Commit

Permalink
fix: fix test, return options.env immutability
Browse files Browse the repository at this point in the history
  • Loading branch information
VerteDinde committed Nov 29, 2022
1 parent 9463804 commit d0e268c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 33 deletions.
20 changes: 2 additions & 18 deletions patches/node/enable_crashpad_linux_node_processes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ to child processes spawned with `ELECTRON_RUN_AS_NODE` which is used
by the crashpad client to connect with the handler process.

diff --git a/lib/child_process.js b/lib/child_process.js
index 73c1dc769542865bdf7a2a03c16cef141d3f4b05..a77e75c0893378021c9289185e6dd9facc064e39 100644
index 73c1dc769542865bdf7a2a03c16cef141d3f4b05..76151c75ef7ad420d2642c1cd11c8624b7d7e2a0 100644
--- a/lib/child_process.js
+++ b/lib/child_process.js
@@ -59,6 +59,7 @@ let debug = require('internal/util/debuglog').debuglog(
Expand All @@ -27,23 +27,7 @@ index 73c1dc769542865bdf7a2a03c16cef141d3f4b05..a77e75c0893378021c9289185e6dd9fa
args = [...execArgv, modulePath, ...args];

if (typeof options.stdio === 'string') {
@@ -561,10 +561,12 @@ function normalizeSpawnArguments(file, args, options) {
args = [];
}

- if (options === undefined)
- options = kEmptyObject;
- else
+ if (options === undefined) {
+ options = Object.create(null);
+ options.env = Object.create(null);
+ } else {
validateObject(options, 'options');
+ }

let cwd = options.cwd;

@@ -613,6 +615,21 @@ function normalizeSpawnArguments(file, args, options) {
@@ -613,6 +613,21 @@ function normalizeSpawnArguments(file, args, options) {
'options.windowsVerbatimArguments');
}

Expand Down
21 changes: 15 additions & 6 deletions spec/api-crash-reporter-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,22 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
expect(crash.rendererSpecific).to.be.undefined();
});

ifit(!isLinuxOnArm)('ensure child process args are not modified', async () => {
// Ensures that passing in crashpadHandlerPID flag for Linx child processes
// does not affect child proocess args.
ifit(process.platform === 'linux')('ensure linux child process args are not modified', async () => {
const { port, waitForCrash } = await startServer();
runCrashApp('node-extra-args', port);
const crash = await waitForCrash();
checkCrash('node', crash);
expect(crash.mainProcessSpecific).to.be.undefined();
expect(crash.rendererSpecific).to.be.undefined();
let exitCode: number | null = null;
const appPath = path.join(__dirname, 'fixtures', 'apps', 'crash');
const crashType = 'node-extra-args';
const crashProcess = childProcess.spawn(process.execPath, [appPath,
`--crash-type=${crashType}`,
`--crash-reporter-url=http://127.0.0.1:${port}`
], { stdio: 'inherit' });
crashProcess.once('close', (code) => {
exitCode = code;
});
await waitForCrash();
expect(exitCode).to.equal(0);
});

describe('with guid', () => {
Expand Down
7 changes: 6 additions & 1 deletion spec/fixtures/apps/crash/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,14 @@ app.whenReady().then(() => {
const child = childProcess.fork(scriptPath, { silent: true });
child.on('exit', () => process.exit(0));
} else if (crashType === 'node-extra-args') {
let exitcode = -1;
const crashPath = path.join(__dirname, 'node-extra-args.js');
const child = childProcess.fork(crashPath, ['--enable-logging'], { silent: true });
child.on('exit', () => process.exit(0));
child.send('message');
child.on('message', (forkedArgs) => {
if (JSON.stringify(forkedArgs) !== JSON.stringify(child.spawnargs)) { exitcode = 1; } else { exitcode = 0; }
process.exit(exitcode);
});
} else {
console.error(`Unrecognized crash type: '${crashType}'`);
process.exit(1);
Expand Down
15 changes: 7 additions & 8 deletions spec/fixtures/apps/crash/node-extra-args.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const path = require('path');
const childProcess = require('child_process');
const argv = process.argv;
let exitCode = 0;
if (argv.length !== 3) {
exitCode = 1;
}
const crashPath = path.join(__dirname, 'node-crash.js');
const child = childProcess.fork(crashPath, { silent: true });
child.on('exit', () => process.exit(exitCode));

process.on('message', function () {
process.send(process.argv);
});

// Allow time to send args, then crash the app.
setTimeout(() => process.nextTick(() => process.crash()), 10000);

0 comments on commit d0e268c

Please sign in to comment.