diff --git a/tap-snapshots/test/lib/commands/audit.js.test.cjs b/tap-snapshots/test/lib/commands/audit.js.test.cjs index 1f8e2e6c7a361..f8cee61123a6e 100644 --- a/tap-snapshots/test/lib/commands/audit.js.test.cjs +++ b/tap-snapshots/test/lib/commands/audit.js.test.cjs @@ -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 xxx found 0 vulnerabilities ` diff --git a/test/lib/commands/audit.js b/test/lib/commands/audit.js index 8b79b02ba6900..1afb8d333b7ce 100644 --- a/test/lib/commands/audit.js +++ b/test/lib/commands/audit.js @@ -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(/packages in [0-9]+[a-z]+/g, 'packages in xxx') const tree = { 'package.json': JSON.stringify({ @@ -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' }], @@ -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 => { diff --git a/test/lib/commands/completion.js b/test/lib/commands/completion.js index d4e6f1199c457..6cc1677552e8a 100644 --- a/test/lib/commands/completion.js +++ b/test/lib/commands/completion.js @@ -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')