Skip to content
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

fix(exitHandler): write code to logfile #3469

Merged
merged 1 commit into from
Jun 25, 2021
Merged
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: 1 addition & 3 deletions lib/utils/exit-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ process.on('exit', code => {
if (!code)
log.info('ok')
else {
log.verbose('code', code)
if (!exitHandlerCalled) {
log.error('', 'Exit handler never called!')
console.error('')
Expand All @@ -66,7 +67,6 @@ process.on('exit', code => {
// TODO this doesn't have an npm.config.loaded guard
writeLogFile()
}
log.verbose('code', code)
}
// In timing mode we always write the log file
if (npm.config && npm.config.loaded && npm.config.get('timing') && !wroteLogFile)
Expand Down Expand Up @@ -107,8 +107,6 @@ const exit = (code, noLog) => {
// background at this point, and this makes sure anything left dangling
// for whatever reason gets thrown away, instead of leaving the CLI open
process.stdout.write('', () => {
// `|| process.exitCode` supports a single use case, where we set the exit
// code to 1 if npm is called with no arguments
process.exit(code)
})
}
Expand Down
23 changes: 10 additions & 13 deletions tap-snapshots/test/lib/utils/exit-handler.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@
*/
'use strict'
exports[`test/lib/utils/exit-handler.js TAP handles unknown error > should have expected log contents for unknown error 1`] = `
0 verbose code 1
1 error foo A complete log of this run can be found in:
1 error foo {CWD}/test/lib/utils/tap-testdir-exit-handler/_logs/expecteddate-debug.log
2 verbose stack Error: ERROR
3 verbose cwd {CWD}
4 verbose Foo 1.0.0
5 verbose argv "/node" "{CWD}/test/lib/utils/exit-handler.js"
6 verbose node v1.0.0
7 verbose npm v1.0.0
8 error foo code ERROR
9 error foo ERR ERROR
10 error foo ERR ERROR
11 verbose exit 1
0 verbose stack Error: ERROR
1 verbose cwd {CWD}
2 verbose Foo 1.0.0
3 verbose argv "/node" "{CWD}/test/lib/utils/exit-handler.js"
4 verbose node v1.0.0
5 verbose npm v1.0.0
6 error foo code ERROR
7 error foo ERR ERROR
8 error foo ERR ERROR
9 verbose exit 1
`
4 changes: 4 additions & 0 deletions test/lib/utils/exit-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ process = Object.assign(
// in order for tap to exit properly
t.teardown(() => {
process = _process
})

t.afterEach(() => {
// clear out the 'A complete log' message
npmlog.record.length = 0
})

Expand Down