Skip to content

Commit 45b44cf

Browse files
committed
fix exit handler test
1 parent 53215c7 commit 45b44cf

File tree

5 files changed

+47
-60
lines changed

5 files changed

+47
-60
lines changed

package-lock.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161
"@npmcli/git": "^6.0.1",
162162
"@npmcli/mock-globals": "^1.0.0",
163163
"@npmcli/mock-registry": "^1.0.0",
164-
"@npmcli/template-oss": "^4.24.1",
164+
"@npmcli/template-oss": "4.24.1",
165165
"@tufjs/repo-mock": "^3.0.1",
166166
"ajv": "^8.12.0",
167167
"ajv-formats": "^2.1.1",
@@ -3447,6 +3447,10 @@
34473447
"integrity": "sha512-IRMjivMDmGHu1oQb8/F22vVWukvgN1SsYBsC3hzxTjqTlISaL9L+Qkb5gIGsgEfumcjT1Y8lHQevu2slcaf/hA==",
34483448
"dev": true,
34493449
"hasInstallScript": true,
3450+
"license": "ISC",
3451+
"workspaces": [
3452+
"workspace/test-workspace"
3453+
],
34503454
"dependencies": {
34513455
"@actions/core": "^1.9.1",
34523456
"@commitlint/cli": "^19.0.3",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
"@npmcli/git": "^6.0.1",
193193
"@npmcli/mock-globals": "^1.0.0",
194194
"@npmcli/mock-registry": "^1.0.0",
195-
"@npmcli/template-oss": "^4.24.1",
195+
"@npmcli/template-oss": "4.24.1",
196196
"@tufjs/repo-mock": "^3.0.1",
197197
"ajv": "^8.12.0",
198198
"ajv-formats": "^2.1.1",

tap-snapshots/test/lib/cli/exit-handler.js.test.cjs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,62 +5,62 @@
55
* Make sure to inspect the output below. Do not ignore changes!
66
*/
77
'use strict'
8-
exports[`test/lib/cli/exit-handler.js TAP handles unknown error with logs and debug file > debug file contents 1`] = `
8+
exports[`test/lib/cli/exit-handler.js > TAP > handles unknown error with logs and debug file > debug file contents 1`] = `
99
XX timing npm:load:whichnode Completed in {TIME}ms
1010
XX silly config load:file:{CWD}/npmrc
11-
XX silly config load:file:{CWD}/prefix/.npmrc
12-
XX silly config load:file:{CWD}/home/.npmrc
13-
XX silly config load:file:{CWD}/global/etc/npmrc
11+
XX silly config load:file:{CWD}/.tap/fixtures/test-lib-cli-exit-handler.js-handles-unknown-error-with-logs-and-debug-file/prefix/.npmrc
12+
XX silly config load:file:{CWD}/.tap/fixtures/test-lib-cli-exit-handler.js-handles-unknown-error-with-logs-and-debug-file/home/.npmrc
13+
XX silly config load:file:{CWD}/.tap/fixtures/test-lib-cli-exit-handler.js-handles-unknown-error-with-logs-and-debug-file/global/etc/npmrc
1414
XX timing npm:load:configload Completed in {TIME}ms
1515
XX timing npm:load:mkdirpcache Completed in {TIME}ms
1616
XX timing npm:load:mkdirplogs Completed in {TIME}ms
1717
XX verbose title npm
18-
XX verbose argv "--fetch-retries" "0" "--cache" "{CWD}/cache" "--loglevel" "silly" "--color" "false" "--timing" "true"
18+
XX verbose argv "--fetch-retries" "0" "--cache" "{CWD}/.tap/fixtures/test-lib-cli-exit-handler.js-handles-unknown-error-with-logs-and-debug-file/cache" "--loglevel" "silly" "--color" "false" "--timing" "true"
1919
XX timing npm:load:setTitle Completed in {TIME}ms
20-
XX verbose logfile logs-max:10 dir:{CWD}/cache/_logs/{DATE}-
21-
XX verbose logfile {CWD}/cache/_logs/{DATE}-debug-0.log
20+
XX verbose logfile logs-max:10 dir:{CWD}/.tap/fixtures/test-lib-cli-exit-handler.js-handles-unknown-error-with-logs-and-debug-file/cache/_logs/{DATE}-
21+
XX verbose logfile {CWD}/.tap/fixtures/test-lib-cli-exit-handler.js-handles-unknown-error-with-logs-and-debug-file/cache/_logs/{DATE}-debug-0.log
2222
XX timing npm:load Completed in {TIME}ms
2323
XX timing command:root Completed in {TIME}ms
2424
XX verbose stack Error: Unknown error
2525
XX error code ECODE
2626
XX error Unknown error
2727
XX timing npm Completed in {TIME}ms
28-
XX info timing Timing info written to: {CWD}/cache/_logs/{DATE}-timing.json
29-
XX verbose cwd {CWD}/prefix
28+
XX info timing Timing info written to: {CWD}/.tap/fixtures/test-lib-cli-exit-handler.js-handles-unknown-error-with-logs-and-debug-file/cache/_logs/{DATE}-timing.json
29+
XX verbose cwd {CWD}/.tap/fixtures/test-lib-cli-exit-handler.js-handles-unknown-error-with-logs-and-debug-file/prefix
3030
XX verbose os {OS}
3131
XX verbose {NODE-VERSION}
3232
XX verbose npm {NPM-VERSION}
3333
XX verbose exit 1
3434
XX verbose code 1
35-
XX error A complete log of this run can be found in: {CWD}/cache/_logs/{DATE}-debug-0.log
35+
XX error A complete log of this run can be found in: {CWD}/.tap/fixtures/test-lib-cli-exit-handler.js-handles-unknown-error-with-logs-and-debug-file/cache/_logs/{DATE}-debug-0.log
3636
`
3737

38-
exports[`test/lib/cli/exit-handler.js TAP handles unknown error with logs and debug file > logs 1`] = `
38+
exports[`test/lib/cli/exit-handler.js > TAP > handles unknown error with logs and debug file > logs 1`] = `
3939
timing npm:load:whichnode Completed in {TIME}ms
4040
silly config load:file:{CWD}/npmrc
41-
silly config load:file:{CWD}/prefix/.npmrc
42-
silly config load:file:{CWD}/home/.npmrc
43-
silly config load:file:{CWD}/global/etc/npmrc
41+
silly config load:file:{CWD}/.tap/fixtures/test-lib-cli-exit-handler.js-handles-unknown-error-with-logs-and-debug-file/prefix/.npmrc
42+
silly config load:file:{CWD}/.tap/fixtures/test-lib-cli-exit-handler.js-handles-unknown-error-with-logs-and-debug-file/home/.npmrc
43+
silly config load:file:{CWD}/.tap/fixtures/test-lib-cli-exit-handler.js-handles-unknown-error-with-logs-and-debug-file/global/etc/npmrc
4444
timing npm:load:configload Completed in {TIME}ms
4545
timing npm:load:mkdirpcache Completed in {TIME}ms
4646
timing npm:load:mkdirplogs Completed in {TIME}ms
4747
verbose title npm
48-
verbose argv "--fetch-retries" "0" "--cache" "{CWD}/cache" "--loglevel" "silly" "--color" "false" "--timing" "true"
48+
verbose argv "--fetch-retries" "0" "--cache" "{CWD}/.tap/fixtures/test-lib-cli-exit-handler.js-handles-unknown-error-with-logs-and-debug-file/cache" "--loglevel" "silly" "--color" "false" "--timing" "true"
4949
timing npm:load:setTitle Completed in {TIME}ms
50-
verbose logfile logs-max:10 dir:{CWD}/cache/_logs/{DATE}-
51-
verbose logfile {CWD}/cache/_logs/{DATE}-debug-0.log
50+
verbose logfile logs-max:10 dir:{CWD}/.tap/fixtures/test-lib-cli-exit-handler.js-handles-unknown-error-with-logs-and-debug-file/cache/_logs/{DATE}-
51+
verbose logfile {CWD}/.tap/fixtures/test-lib-cli-exit-handler.js-handles-unknown-error-with-logs-and-debug-file/cache/_logs/{DATE}-debug-0.log
5252
timing npm:load Completed in {TIME}ms
5353
timing command:root Completed in {TIME}ms
5454
verbose stack Error: Unknown error
5555
error code ECODE
5656
error Unknown error
5757
timing npm Completed in {TIME}ms
58-
info timing Timing info written to: {CWD}/cache/_logs/{DATE}-timing.json
59-
verbose cwd {CWD}/prefix
58+
info timing Timing info written to: {CWD}/.tap/fixtures/test-lib-cli-exit-handler.js-handles-unknown-error-with-logs-and-debug-file/cache/_logs/{DATE}-timing.json
59+
verbose cwd {CWD}/.tap/fixtures/test-lib-cli-exit-handler.js-handles-unknown-error-with-logs-and-debug-file/prefix
6060
verbose os {OS}
6161
verbose {NODE-VERSION}
6262
verbose npm {NPM-VERSION}
6363
verbose exit 1
6464
verbose code 1
65-
error A complete log of this run can be found in: {CWD}/cache/_logs/{DATE}-debug-0.log
65+
error A complete log of this run can be found in: {CWD}/.tap/fixtures/test-lib-cli-exit-handler.js-handles-unknown-error-with-logs-and-debug-file/cache/_logs/{DATE}-debug-0.log
6666
`

test/lib/cli/exit-handler.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -344,26 +344,27 @@ t.test('throw a string error', async (t) => {
344344
])
345345
})
346346

347-
t.test('update notification - shows even with loglevel error', async (t) => {
348-
const { exitHandler, logs, npm } = await mockExitHandler(t, {
349-
config: { loglevel: 'error' },
350-
})
351-
npm.updateNotification = 'you should update npm!'
352-
353-
await exitHandler()
354-
355-
t.match(logs.notice, ['you should update npm!'])
356-
})
357-
358-
t.test('update notification - hidden with silent', async (t) => {
359-
const { exitHandler, logs, npm } = await mockExitHandler(t, {
360-
config: { loglevel: 'silent' },
361-
})
362-
npm.updateNotification = 'you should update npm!'
363-
364-
await exitHandler()
365-
366-
t.strictSame(logs.notice, [])
347+
t.test('update notification - shows even with every loglevel', async (t) => {
348+
const loglevels = {
349+
silent: false,
350+
error: false,
351+
warn: false,
352+
notice: true,
353+
http: true,
354+
info: true,
355+
verbose: true,
356+
silly: true,
357+
}
358+
await Promise.all(Object.entries(loglevels).map(async ([loglevel, shouldLog]) => {
359+
t.test(loglevel, async (t) => {
360+
const { exitHandler, logs, npm } = await mockExitHandler(t, {
361+
config: { loglevel },
362+
})
363+
npm.updateNotification = 'you should update npm!'
364+
await exitHandler()
365+
t.match(logs.notice, shouldLog ? ['you should update npm!'] : [])
366+
})
367+
}))
367368
})
368369

369370
t.test('npm.config not ready', async (t) => {

test/meta/main.test.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)