diff options
author | npm-robot <ops+robot@npmjs.com> | 2021-05-31 23:00:00 +0000 |
---|---|---|
committer | Ruy Adorno <ruyadorno@hotmail.com> | 2021-06-01 18:39:17 -0400 |
commit | 5d9fd768f050b38e1ddd4c9a965fe7344e1f5a04 (patch) | |
tree | 30bd05898e2109bc2921d3b049473d058aa7833e /deps/npm/test/lib/utils | |
parent | 26bf4f3833f68a5287d9c91cb54ee1fba6330866 (diff) | |
download | node-new-5d9fd768f050b38e1ddd4c9a965fe7344e1f5a04.tar.gz |
deps: upgrade npm to 7.15.1
PR-URL: https://github.com/nodejs/node/pull/38880
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ruy Adorno <ruyadorno@github.com>
Diffstat (limited to 'deps/npm/test/lib/utils')
-rw-r--r-- | deps/npm/test/lib/utils/read-package-name.js (renamed from deps/npm/test/lib/utils/read-local-package.js) | 25 | ||||
-rw-r--r-- | deps/npm/test/lib/utils/reify-output.js | 165 |
2 files changed, 148 insertions, 42 deletions
diff --git a/deps/npm/test/lib/utils/read-local-package.js b/deps/npm/test/lib/utils/read-package-name.js index 966e74a7ab..c8f88bacd4 100644 --- a/deps/npm/test/lib/utils/read-local-package.js +++ b/deps/npm/test/lib/utils/read-package-name.js @@ -1,13 +1,8 @@ const t = require('tap') const mockNpm = require('../../fixtures/mock-npm') +const npm = mockNpm() -const config = { - json: false, - global: false, -} -const npm = mockNpm({ config }) - -const readLocalPackageName = require('../../../lib/utils/read-local-package.js') +const readPackageName = require('../../../lib/utils/read-package-name.js') t.test('read local package.json', async (t) => { npm.prefix = t.testdir({ @@ -16,7 +11,7 @@ t.test('read local package.json', async (t) => { version: '1.0.0', }), }) - const packageName = await readLocalPackageName(npm) + const packageName = await readPackageName(npm.prefix) t.equal( packageName, 'my-local-package', @@ -31,22 +26,10 @@ t.test('read local scoped-package.json', async (t) => { version: '1.0.0', }), }) - const packageName = await readLocalPackageName(npm) + const packageName = await readPackageName(npm.prefix) t.equal( packageName, '@my-scope/my-local-package', 'should retrieve scoped package name' ) }) - -t.test('read using --global', async (t) => { - npm.prefix = t.testdir({}) - config.global = true - const packageName = await readLocalPackageName(npm) - t.equal( - packageName, - undefined, - 'should not retrieve a package name' - ) - config.global = false -}) diff --git a/deps/npm/test/lib/utils/reify-output.js b/deps/npm/test/lib/utils/reify-output.js index 2142566b90..3ffbdf86a2 100644 --- a/deps/npm/test/lib/utils/reify-output.js +++ b/deps/npm/test/lib/utils/reify-output.js @@ -187,31 +187,154 @@ t.test('print appropriate message for many packages', (t) => { }) }) -t.test('no output when silent', t => { - npm.output = out => { - t.fail('should not get output when silent', { actual: out }) - } - t.teardown(() => log.level = 'warn') - log.level = 'silent' - reifyOutput(npm, { - actualTree: { inventory: { size: 999 }, children: [] }, - auditReport: { - toJSON: () => { - throw new Error('this should not get called') - }, - vulnerabilities: {}, - metadata: { - vulnerabilities: { - total: 99, - }, +t.test('showing and not showing audit report', async t => { + const auditReport = { + toJSON: () => auditReport, + auditReportVersion: 2, + vulnerabilities: { + minimist: { + name: 'minimist', + severity: 'low', + via: [ + { + id: 1179, + url: 'https://npmjs.com/advisories/1179', + title: 'Prototype Pollution', + severity: 'low', + vulnerable_versions: '<0.2.1 || >=1.0.0 <1.2.3', + }, + ], + effects: [], + range: '<0.2.1 || >=1.0.0 <1.2.3', + nodes: [ + 'node_modules/minimist', + ], + fixAvailable: true, }, }, - diff: { - children: [ - { action: 'ADD', ideal: { location: 'loc' } }, - ], + metadata: { + vulnerabilities: { + info: 0, + low: 1, + moderate: 0, + high: 0, + critical: 0, + total: 1, + }, + dependencies: { + prod: 1, + dev: 0, + optional: 0, + peer: 0, + peerOptional: 0, + total: 1, + }, }, + } + + t.test('no output when silent', t => { + npm.output = out => { + t.fail('should not get output when silent', { actual: out }) + } + t.teardown(() => log.level = 'warn') + log.level = 'silent' + reifyOutput(npm, { + actualTree: { inventory: { size: 999 }, children: [] }, + auditReport, + diff: { + children: [ + { action: 'ADD', ideal: { location: 'loc' } }, + ], + }, + }) + t.end() }) + + t.test('output when not silent', t => { + const OUT = [] + npm.output = out => { + OUT.push(out) + } + reifyOutput(npm, { + actualTree: { inventory: new Map(), children: [] }, + auditReport, + diff: { + children: [ + { action: 'ADD', ideal: { location: 'loc' } }, + ], + }, + }) + t.match(OUT.join('\n'), /Run `npm audit` for details\.$/, 'got audit report') + t.end() + }) + + for (const json of [true, false]) { + t.test(`json=${json}`, t => { + t.teardown(() => { + delete npm.flatOptions.json + }) + npm.flatOptions.json = json + t.test('set exit code when cmd is audit', t => { + npm.output = () => {} + const { exitCode } = process + const { command } = npm + npm.flatOptions.auditLevel = 'low' + t.teardown(() => { + delete npm.flatOptions.auditLevel + npm.command = command + // only set exitCode back if we're passing tests + if (t.passing()) + process.exitCode = exitCode + }) + + process.exitCode = 0 + npm.command = 'audit' + reifyOutput(npm, { + actualTree: { inventory: new Map(), children: [] }, + auditReport, + diff: { + children: [ + { action: 'ADD', ideal: { location: 'loc' } }, + ], + }, + }) + + t.equal(process.exitCode, 1, 'set exit code') + t.end() + }) + + t.test('do not set exit code when cmd is install', t => { + npm.output = () => {} + const { exitCode } = process + const { command } = npm + npm.flatOptions.auditLevel = 'low' + t.teardown(() => { + delete npm.flatOptions.auditLevel + npm.command = command + // only set exitCode back if we're passing tests + if (t.passing()) + process.exitCode = exitCode + }) + + process.exitCode = 0 + npm.command = 'install' + reifyOutput(npm, { + actualTree: { inventory: new Map(), children: [] }, + auditReport, + diff: { + children: [ + { action: 'ADD', ideal: { location: 'loc' } }, + ], + }, + }) + + t.equal(process.exitCode, 0, 'did not set exit code') + t.end() + }) + t.end() + }) + } + t.end() }) |