-
Notifications
You must be signed in to change notification settings - Fork 12k
test: improve test error message logs #23694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,39 +96,42 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce | |
_processes.push(childProcess); | ||
|
||
// Create the error here so the stack shows who called this function. | ||
const error = new Error(); | ||
|
||
// Return log info about the current process status | ||
function envDump() { | ||
return [ | ||
`ENV:${JSON.stringify(spawnOptions.env, null, 2)}`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also changed but is a bit hard to see. It now outputs the env of the process being spawned, not the parent process - |
||
`STDOUT:\n${stdout}`, | ||
`STDERR:\n${stderr}`, | ||
].join('\n\n'); | ||
} | ||
|
||
return new Promise((resolve, reject) => { | ||
return new Promise<ProcessOutput>((resolve, reject) => { | ||
let matched = false; | ||
|
||
childProcess.on('exit', (error: any) => { | ||
childProcess.on('exit', (code: number) => { | ||
_processes = _processes.filter((p) => p !== childProcess); | ||
|
||
if (options.waitForMatch && !matched) { | ||
error = `Output didn't match '${options.waitForMatch}'.`; | ||
reject( | ||
`Process output didn't match - "${cmd} ${args.join(' ')}": '${ | ||
options.waitForMatch | ||
}': ${code}...\n\n${envDump()}\n`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note both the |
||
); | ||
return; | ||
} | ||
|
||
if (!error) { | ||
if (!code) { | ||
resolve({ stdout, stderr }); | ||
return; | ||
} | ||
|
||
reject( | ||
new Error( | ||
`Running "${cmd} ${args.join(' ')}" returned error. ${error}...\n\nENV:${JSON.stringify( | ||
process.env, | ||
null, | ||
2, | ||
)}\n\nSTDOUT:\n${stdout}\n\nSTDERR:\n${stderr}\n`, | ||
), | ||
); | ||
reject(`Process exit error - "${cmd} ${args.join(' ')}": ${code}...\n\n${envDump()}\n`); | ||
}); | ||
|
||
childProcess.on('error', (err) => { | ||
err.message += `${err}...\n\nENV:${JSON.stringify( | ||
process.env, | ||
null, | ||
2, | ||
)}\n\nSTDOUT:\n${stdout}\n\nSTDERR:\n${stderr}\n`; | ||
reject(err); | ||
reject(`Process error - "${cmd} ${args.join(' ')}": ${err}...\n\n${envDump()}\n`); | ||
}); | ||
|
||
if (options.waitForMatch) { | ||
|
@@ -154,6 +157,9 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce | |
childProcess.stdin!.write(options.stdin); | ||
childProcess.stdin!.end(); | ||
} | ||
}).catch((err) => { | ||
error.message = err.toString(); | ||
return Promise.reject(error); | ||
}); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this wasn't actually done before? Creating the
error
with the stack trace at this point is the primary change. Otherwise the stack trace is always just the child_process exit/error stack which is useless.