Skip to content

Commit

Permalink
chore: remove mocks from completion tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Apr 2, 2022
1 parent 4f596ef commit b573bc1
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
31 changes: 30 additions & 1 deletion tap-snapshots/test/lib/commands/audit.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,38 @@
* Make sure to inspect the output below. Do not ignore changes!
*/
'use strict'
exports[`test/lib/commands/audit.js TAP audit fix > lockfile has test-dep-a@1.0.1 1`] = `
{
"name": "test-dep",
"version": "1.0.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "test-dep",
"version": "1.0.0",
"dependencies": {
"test-dep-a": "*"
}
},
"node_modules/test-dep-a": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/test-dep-a/-/test-dep-a-1.0.1.tgz"
}
},
"dependencies": {
"test-dep-a": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/test-dep-a/-/test-dep-a-1.0.1.tgz"
}
}
}
`

exports[`test/lib/commands/audit.js TAP audit fix > must match snapshot 1`] = `
added 1 package, and audited 2 packages in 120ms
added 1 package, and audited 2 packages in xxxms
found 0 vulnerabilities
`
Expand Down
10 changes: 9 additions & 1 deletion test/lib/commands/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const util = require('util')
const zlib = require('zlib')
const gzip = util.promisify(zlib.gzip)
const path = require('path')
const fs = require('fs')

t.cleanSnapshot = str => str.replace(/[0-9]+ms/g, 'xxxms')

const tree = {
'package.json': JSON.stringify({
Expand Down Expand Up @@ -114,7 +117,6 @@ t.test('audit fix', async t => {
tap: t,
registry: npm.config.get('registry'),
})
// with fix
const manifest = registry.manifest({
name: 'test-dep-a',
packuments: [{ version: '1.0.0' }, { version: '1.0.1' }],
Expand All @@ -139,6 +141,12 @@ t.test('audit fix', async t => {
})
await npm.exec('audit', ['fix'])
t.matchSnapshot(joinedOutput())
const pkg = fs.readFileSync(path.join(npm.prefix, 'package-lock.json'), 'utf8')
t.matchSnapshot(pkg, 'lockfile has test-dep-a@1.0.1')
t.ok(
fs.existsSync(path.join(npm.prefix, 'node_modules', 'test-dep-a', 'fixed.txt')),
'has test-dep-a@1.0.1 on disk'
)
})

t.test('completion', async t => {
Expand Down
19 changes: 9 additions & 10 deletions test/lib/commands/completion.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@ const completionScript = fs
.readFileSync(path.resolve(__dirname, '../../../lib/utils/completion.sh'), { encoding: 'utf8' })
.replace(/^#!.*?\n/, '')

const { load: _loadMockNpm } = require('../../fixtures/mock-npm')
const { load: loadMockNpm } = require('../../fixtures/mock-npm')
const mockGlobals = require('../../fixtures/mock-globals')

const loadMockCompletion = async (t, o = {}) => {
const { globals, windows, ...options } = o
const { globals = {}, windows, ...options } = o
let resetGlobals = {}
if (globals) {
resetGlobals = mockGlobals(t, globals).reset
}
const res = await _loadMockNpm(t, {
mocks: {
'../../lib/utils/is-windows.js': { isWindowsShell: !!windows },
...options.mocks,
},
resetGlobals = mockGlobals(t, {
'process.platform': windows ? 'win32' : 'posix',
'process.env.term': 'notcygwin',
'process.env.msystem': 'nogmingw',
...globals,
}).reset
const res = await loadMockNpm(t, {
...options,
})
const completion = await res.npm.cmd('completion')
Expand Down

0 comments on commit b573bc1

Please sign in to comment.