Skip to content

Commit de4de30

Browse files
committed
chore: remove mocks from completion tests
1 parent edbd884 commit de4de30

File tree

3 files changed

+48
-12
lines changed

3 files changed

+48
-12
lines changed

tap-snapshots/test/lib/commands/audit.js.test.cjs

+30-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,38 @@
55
* Make sure to inspect the output below. Do not ignore changes!
66
*/
77
'use strict'
8+
exports[`test/lib/commands/audit.js TAP audit fix > lockfile has [email protected] 1`] = `
9+
{
10+
"name": "test-dep",
11+
"version": "1.0.0",
12+
"lockfileVersion": 2,
13+
"requires": true,
14+
"packages": {
15+
"": {
16+
"name": "test-dep",
17+
"version": "1.0.0",
18+
"dependencies": {
19+
"test-dep-a": "*"
20+
}
21+
},
22+
"node_modules/test-dep-a": {
23+
"version": "1.0.1",
24+
"resolved": "https://registry.npmjs.org/test-dep-a/-/test-dep-a-1.0.1.tgz"
25+
}
26+
},
27+
"dependencies": {
28+
"test-dep-a": {
29+
"version": "1.0.1",
30+
"resolved": "https://registry.npmjs.org/test-dep-a/-/test-dep-a-1.0.1.tgz"
31+
}
32+
}
33+
}
34+
35+
`
36+
837
exports[`test/lib/commands/audit.js TAP audit fix > must match snapshot 1`] = `
938
10-
added 1 package, and audited 2 packages in 120ms
39+
added 1 package, and audited 2 packages in xxx
1140
1241
found 0 vulnerabilities
1342
`

test/lib/commands/audit.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ const util = require('util')
66
const zlib = require('zlib')
77
const gzip = util.promisify(zlib.gzip)
88
const path = require('path')
9+
const fs = require('fs')
10+
11+
t.cleanSnapshot = str => str.replace(/packages in [0-9]+[a-z]+/g, 'packages in xxx')
912

1013
const tree = {
1114
'package.json': JSON.stringify({
@@ -114,7 +117,6 @@ t.test('audit fix', async t => {
114117
tap: t,
115118
registry: npm.config.get('registry'),
116119
})
117-
// with fix
118120
const manifest = registry.manifest({
119121
name: 'test-dep-a',
120122
packuments: [{ version: '1.0.0' }, { version: '1.0.1' }],
@@ -139,6 +141,12 @@ t.test('audit fix', async t => {
139141
})
140142
await npm.exec('audit', ['fix'])
141143
t.matchSnapshot(joinedOutput())
144+
const pkg = fs.readFileSync(path.join(npm.prefix, 'package-lock.json'), 'utf8')
145+
t.matchSnapshot(pkg, 'lockfile has [email protected]')
146+
t.ok(
147+
fs.existsSync(path.join(npm.prefix, 'node_modules', 'test-dep-a', 'fixed.txt')),
148+
'has [email protected] on disk'
149+
)
142150
})
143151

144152
t.test('completion', async t => {

test/lib/commands/completion.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,19 @@ const completionScript = fs
66
.readFileSync(path.resolve(__dirname, '../../../lib/utils/completion.sh'), { encoding: 'utf8' })
77
.replace(/^#!.*?\n/, '')
88

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

1212
const loadMockCompletion = async (t, o = {}) => {
13-
const { globals, windows, ...options } = o
13+
const { globals = {}, windows, ...options } = o
1414
let resetGlobals = {}
15-
if (globals) {
16-
resetGlobals = mockGlobals(t, globals).reset
17-
}
18-
const res = await _loadMockNpm(t, {
19-
mocks: {
20-
'../../lib/utils/is-windows.js': { isWindowsShell: !!windows },
21-
...options.mocks,
22-
},
15+
resetGlobals = mockGlobals(t, {
16+
'process.platform': windows ? 'win32' : 'posix',
17+
'process.env.term': 'notcygwin',
18+
'process.env.msystem': 'nogmingw',
19+
...globals,
20+
}).reset
21+
const res = await loadMockNpm(t, {
2322
...options,
2423
})
2524
const completion = await res.npm.cmd('completion')

0 commit comments

Comments
 (0)