Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit be8c417

Browse filesBrowse files
joyeecheungaduh95
authored andcommitted
test: only show overridden env in child process failures
Previously when the child process helpers are used to print information about the failed expectations and the env of the child process was overridden, it printed the entire env object, which may be too much if the caller does something like { env: { ENV: 'var', ...process.env } } (which tend to be always the case for specifying env because we need to copy the process.env for dynamic library loading in the CI). This updates it to only show the env vars that differ from process.env for a cleaner log in the case of failure. PR-URL: #60556 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 8cae858 commit be8c417
Copy full SHA for be8c417

File tree

Expand file treeCollapse file tree

1 file changed

+16
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+16
-2
lines changed
Open diff view settings
Collapse file

‎test/common/child_process.js‎

Copy file name to clipboardExpand all lines: test/common/child_process.js
+16-2Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,22 @@ function expectSyncExit(caller, spawnArgs, {
8686
console.error(`${tag} status = ${child.status}, signal = ${child.signal}`);
8787

8888
const error = new Error(`${failures.join('\n')}`);
89-
if (spawnArgs[2]) {
90-
error.options = spawnArgs[2];
89+
if (typeof spawnArgs[2] === 'object' && spawnArgs[2] !== null) {
90+
const envInOptions = spawnArgs[2].env;
91+
// If the env is overridden in the spawn options, include it in the error
92+
// object for easier debugging.
93+
if (typeof envInOptions === 'object' && envInOptions !== null && envInOptions !== process.env) {
94+
// Only include the environment variables that are different from
95+
// the current process.env to avoid cluttering the output.
96+
error.options = { ...spawnArgs[2], env: {} };
97+
for (const key of Object.keys(envInOptions)) {
98+
if (envInOptions[key] !== process.env[key]) {
99+
error.options.env[key] = spawnArgs[2].env[key];
100+
}
101+
}
102+
} else {
103+
error.options = spawnArgs[2];
104+
}
91105
}
92106
let command = spawnArgs[0];
93107
if (Array.isArray(spawnArgs[1])) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.