Skip to content

Commit 22e7b69

Browse files
committed
cleaning snapshots are betting than mocks
1 parent f9cae27 commit 22e7b69

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ XX timing npm:load:configScope Completed in {TIME}ms
2323
XX timing npm:load Completed in {TIME}ms
2424
XX verbose stack Error: Unknown error
2525
XX verbose cwd {CWD}/prefix
26-
XX verbose Foo 1.0.0
26+
XX verbose {OS}
2727
XX verbose {NODE-VERSION}
28-
XX verbose npm v1.0.0
28+
XX verbose npm {NPM-VERSION}
2929
XX error code ECODE
3030
XX error ERR SUMMARY Unknown error
3131
XX error ERR DETAIL Unknown error
@@ -54,9 +54,9 @@ timing npm:load:configScope Completed in {TIME}ms
5454
timing npm:load Completed in {TIME}ms
5555
verbose stack Error: Unknown error
5656
verbose cwd {CWD}/prefix
57-
verbose Foo 1.0.0
57+
verbose {OS}
5858
verbose {NODE-VERSION}
59-
verbose npm v1.0.0
59+
verbose npm {NPM-VERSION}
6060
error code ECODE
6161
error ERR SUMMARY Unknown error
6262
error ERR DETAIL Unknown error

test/lib/utils/exit-handler.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ const fs = require('fs')
33
const fsMiniPass = require('fs-minipass')
44
const { join, resolve } = require('path')
55
const EventEmitter = require('events')
6+
const os = require('node:os')
67
const { output, time } = require('proc-log')
78
const { load: loadMockNpm } = require('../../fixtures/mock-npm')
89
const mockGlobals = require('@npmcli/mock-globals')
910
const { cleanCwd, cleanDate } = require('../../fixtures/clean-snapshot')
1011
const tmock = require('../../fixtures/tmock')
12+
const { version: NPM_VERSION } = require('../../../package.json')
1113

1214
const pick = (obj, ...keys) => keys.reduce((acc, key) => {
1315
acc[key] = obj[key]
@@ -32,6 +34,9 @@ t.cleanSnapshot = (path) => cleanDate(cleanCwd(path))
3234
.replace(/(Completed in )\d+(ms)/g, '$1{TIME}$2')
3335
.replace(/(removing )\d+( files)/g, '$1${NUM}2')
3436
.replaceAll(`node ${process.version}`, '{NODE-VERSION}')
37+
.replaceAll(`node ${process.version}`, '{NODE-VERSION}')
38+
.replaceAll(`${os.type()} ${os.release()}`, '{OS}')
39+
.replaceAll(`v${NPM_VERSION}`, '{NPM-VERSION}')
3540

3641
// cut off process from script so that it won't quit the test runner
3742
// while trying to run through the myriad of cases. need to make it
@@ -58,12 +63,7 @@ const mockExitHandler = async (t, { config, mocks, files, ...opts } = {}) => {
5863

5964
const { npm, logMocks, ...rest } = await loadMockNpm(t, {
6065
...opts,
61-
mocks: {
62-
'{ROOT}/package.json': {
63-
version: '1.0.0',
64-
},
65-
...mocks,
66-
},
66+
mocks,
6767
config: (dirs) => ({
6868
loglevel: 'notice',
6969
...(typeof config === 'function' ? config(dirs) : config),
@@ -86,11 +86,6 @@ const mockExitHandler = async (t, { config, mocks, files, ...opts } = {}) => {
8686
},
8787
},
8888
}),
89-
os: {
90-
type: () => 'Foo',
91-
release: () => '1.0.0',
92-
},
93-
...logMocks,
9489
...mocks,
9590
})
9691

@@ -492,7 +487,7 @@ t.test('timing with no error', async (t) => {
492487
t.match(timingFileData, {
493488
metadata: {
494489
command: [],
495-
version: '1.0.0',
490+
version: npm.version,
496491
logfiles: [String],
497492
},
498493
timers: {
@@ -529,7 +524,7 @@ t.test('unfinished timers', async (t) => {
529524
t.match(timingFileData, {
530525
metadata: {
531526
command: [],
532-
version: '1.0.0',
527+
version: npm.version,
533528
logfiles: [String],
534529
},
535530
timers: {

0 commit comments

Comments
 (0)