Skip to content

Commit

Permalink
cleaning snapshots are betting than mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Apr 18, 2024
1 parent f9cae27 commit 22e7b69
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
8 changes: 4 additions & 4 deletions tap-snapshots/test/lib/utils/exit-handler.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ XX timing npm:load:configScope Completed in {TIME}ms
XX timing npm:load Completed in {TIME}ms
XX verbose stack Error: Unknown error
XX verbose cwd {CWD}/prefix
XX verbose Foo 1.0.0
XX verbose {OS}
XX verbose {NODE-VERSION}
XX verbose npm v1.0.0
XX verbose npm {NPM-VERSION}
XX error code ECODE
XX error ERR SUMMARY Unknown error
XX error ERR DETAIL Unknown error
Expand Down Expand Up @@ -54,9 +54,9 @@ timing npm:load:configScope Completed in {TIME}ms
timing npm:load Completed in {TIME}ms
verbose stack Error: Unknown error
verbose cwd {CWD}/prefix
verbose Foo 1.0.0
verbose {OS}
verbose {NODE-VERSION}
verbose npm v1.0.0
verbose npm {NPM-VERSION}
error code ECODE
error ERR SUMMARY Unknown error
error ERR DETAIL Unknown error
Expand Down
21 changes: 8 additions & 13 deletions test/lib/utils/exit-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ const fs = require('fs')
const fsMiniPass = require('fs-minipass')
const { join, resolve } = require('path')
const EventEmitter = require('events')
const os = require('node:os')
const { output, time } = require('proc-log')
const { load: loadMockNpm } = require('../../fixtures/mock-npm')
const mockGlobals = require('@npmcli/mock-globals')
const { cleanCwd, cleanDate } = require('../../fixtures/clean-snapshot')
const tmock = require('../../fixtures/tmock')
const { version: NPM_VERSION } = require('../../../package.json')

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

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

const { npm, logMocks, ...rest } = await loadMockNpm(t, {
...opts,
mocks: {
'{ROOT}/package.json': {
version: '1.0.0',
},
...mocks,
},
mocks,
config: (dirs) => ({
loglevel: 'notice',
...(typeof config === 'function' ? config(dirs) : config),
Expand All @@ -86,11 +86,6 @@ const mockExitHandler = async (t, { config, mocks, files, ...opts } = {}) => {
},
},
}),
os: {
type: () => 'Foo',
release: () => '1.0.0',
},
...logMocks,
...mocks,
})

Expand Down Expand Up @@ -492,7 +487,7 @@ t.test('timing with no error', async (t) => {
t.match(timingFileData, {
metadata: {
command: [],
version: '1.0.0',
version: npm.version,
logfiles: [String],
},
timers: {
Expand Down Expand Up @@ -529,7 +524,7 @@ t.test('unfinished timers', async (t) => {
t.match(timingFileData, {
metadata: {
command: [],
version: '1.0.0',
version: npm.version,
logfiles: [String],
},
timers: {
Expand Down

0 comments on commit 22e7b69

Please sign in to comment.