diff options
author | npm team <ops+robot@npmjs.com> | 2021-10-07 20:21:11 +0000 |
---|---|---|
committer | Myles Borins <mylesborins@github.com> | 2021-10-07 20:39:53 -0400 |
commit | dbc91de0115bddaa7b90f9675f12de6748363ba2 (patch) | |
tree | 0516deefba9c2b2a3d60932f6d17d31392eed544 /deps/npm/test | |
parent | 58739edf9921ef6d07d3a66230af24abf4e2d1a6 (diff) | |
download | node-new-dbc91de0115bddaa7b90f9675f12de6748363ba2.tar.gz |
deps: upgrade npm to 8.0.0
PR-URL: https://github.com/nodejs/node/pull/40369
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Reviewed-By: Danielle Adams <adamzdanielle@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'deps/npm/test')
-rw-r--r-- | deps/npm/test/coverage-map.js | 2 | ||||
-rw-r--r-- | deps/npm/test/index.js | 22 | ||||
-rw-r--r-- | deps/npm/test/lib/npm.js | 39 | ||||
-rw-r--r-- | deps/npm/test/lib/outdated.js | 26 | ||||
-rw-r--r-- | deps/npm/test/lib/publish.js | 20 | ||||
-rw-r--r-- | deps/npm/test/lib/utils/open-url.js | 23 | ||||
-rw-r--r-- | deps/npm/test/lib/utils/unsupported.js | 13 |
7 files changed, 103 insertions, 42 deletions
diff --git a/deps/npm/test/coverage-map.js b/deps/npm/test/coverage-map.js index 63f2a608e0..aff7a65277 100644 --- a/deps/npm/test/coverage-map.js +++ b/deps/npm/test/coverage-map.js @@ -11,7 +11,7 @@ const coverageMap = (filename) => { // this one doesn't provide any coverage nyc can track return [] } - if (/^test\/(lib|bin)\//.test(filename)) + if (/^test\/(lib\/|bin\/|index\.js$)/.test(filename)) return filename.replace(/^test\//, '') return [] } diff --git a/deps/npm/test/index.js b/deps/npm/test/index.js new file mode 100644 index 0000000000..9f97709acf --- /dev/null +++ b/deps/npm/test/index.js @@ -0,0 +1,22 @@ +const t = require('tap') +const index = require.resolve('../index.js') +const packageIndex = require.resolve('../') +t.equal(index, packageIndex, 'index is main package require() export') +t.throws(() => require(index), { + message: 'The programmatic API was removed in npm v8.0.0', +}) + +t.test('loading as main module will load the cli', t => { + const { spawn } = require('child_process') + const LS = require('../lib/ls.js') + const ls = new LS({}) + const p = spawn(process.execPath, [index, 'ls', '-h']) + const out = [] + p.stdout.on('data', c => out.push(c)) + p.on('close', (code, signal) => { + t.equal(code, 0) + t.equal(signal, null) + t.match(Buffer.concat(out).toString(), ls.usage) + t.end() + }) +}) diff --git a/deps/npm/test/lib/npm.js b/deps/npm/test/lib/npm.js index 03bb46d8d8..7d61762470 100644 --- a/deps/npm/test/lib/npm.js +++ b/deps/npm/test/lib/npm.js @@ -412,22 +412,6 @@ t.test('npm.load', t => { t.end() }) -t.test('loading as main will load the cli', t => { - const { spawn } = require('child_process') - const npm = require.resolve('../../lib/npm.js') - const LS = require('../../lib/ls.js') - const ls = new LS({}) - const p = spawn(process.execPath, [npm, 'ls', '-h']) - const out = [] - p.stdout.on('data', c => out.push(c)) - p.on('close', (code, signal) => { - t.equal(code, 0) - t.equal(signal, null) - t.match(Buffer.concat(out).toString(), ls.usage) - t.end() - }) -}) - t.test('set process.title', t => { t.test('basic title setting', async t => { process.argv = [ @@ -501,3 +485,26 @@ t.test('timings', t => { t.match(npm.timings, { foo: Number, bar: Number }) t.end() }) + +t.test('output clears progress and console.logs the message', t => { + const npm = require('../../lib/npm.js') + const logs = [] + const { log } = console + const { log: { clearProgress, showProgress } } = npm + let showingProgress = true + npm.log.clearProgress = () => showingProgress = false + npm.log.showProgress = () => showingProgress = true + console.log = (...args) => { + t.equal(showingProgress, false, 'should not be showing progress right now') + logs.push(args) + } + t.teardown(() => { + console.log = log + npm.log.showProgress = showProgress + npm.log.clearProgress = clearProgress + }) + + npm.output('hello') + t.strictSame(logs, [['hello']]) + t.end() +}) diff --git a/deps/npm/test/lib/outdated.js b/deps/npm/test/lib/outdated.js index 34a0aa6c9e..518436d0af 100644 --- a/deps/npm/test/lib/outdated.js +++ b/deps/npm/test/lib/outdated.js @@ -102,6 +102,10 @@ const outdated = (dir, opts) => { t.beforeEach(() => logs = '') +const { exitCode } = process + +t.afterEach(() => process.exitCode = exitCode) + const redactCwd = (path) => { const normalizePath = p => p .replace(/\\+/g, '/') @@ -175,6 +179,7 @@ t.test('should display outdated deps', t => { outdated(null, { config: { global: true }, }).exec([], () => { + t.equal(process.exitCode, 1) t.matchSnapshot(logs) t.end() }) @@ -187,6 +192,7 @@ t.test('should display outdated deps', t => { }, color: true, }).exec([], () => { + t.equal(process.exitCode, 1) t.matchSnapshot(logs) t.end() }) @@ -200,6 +206,7 @@ t.test('should display outdated deps', t => { }, color: true, }).exec([], () => { + t.equal(process.exitCode, 1) t.matchSnapshot(logs) t.end() }) @@ -213,6 +220,7 @@ t.test('should display outdated deps', t => { }, color: true, }).exec([], () => { + t.equal(process.exitCode, 1) t.matchSnapshot(logs) t.end() }) @@ -226,6 +234,7 @@ t.test('should display outdated deps', t => { }, color: true, }).exec([], () => { + t.equal(process.exitCode, 1) t.matchSnapshot(logs) t.end() }) @@ -238,6 +247,7 @@ t.test('should display outdated deps', t => { long: true, }, }).exec([], () => { + t.equal(process.exitCode, 1) t.matchSnapshot(logs) t.end() }) @@ -250,6 +260,7 @@ t.test('should display outdated deps', t => { json: true, }, }).exec([], () => { + t.equal(process.exitCode, 1) t.matchSnapshot(logs) t.end() }) @@ -263,6 +274,7 @@ t.test('should display outdated deps', t => { long: true, }, }).exec([], () => { + t.equal(process.exitCode, 1) t.matchSnapshot(logs) t.end() }) @@ -275,6 +287,7 @@ t.test('should display outdated deps', t => { parseable: true, }, }).exec([], () => { + t.equal(process.exitCode, 1) t.matchSnapshot(logs) t.end() }) @@ -288,6 +301,7 @@ t.test('should display outdated deps', t => { long: true, }, }).exec([], () => { + t.equal(process.exitCode, 1) t.matchSnapshot(logs) t.end() }) @@ -299,6 +313,7 @@ t.test('should display outdated deps', t => { all: true, }, }).exec([], () => { + t.equal(process.exitCode, 1) t.matchSnapshot(logs) t.end() }) @@ -310,6 +325,7 @@ t.test('should display outdated deps', t => { global: false, }, }).exec(['cat'], () => { + t.equal(process.exitCode, 1) t.matchSnapshot(logs) t.end() }) @@ -540,6 +556,7 @@ t.test('workspaces', async t => { rej(err) t.matchSnapshot(logs, 'should display ws outdated deps human output') + t.equal(process.exitCode, 1) res() }) }) @@ -554,6 +571,7 @@ t.test('workspaces', async t => { rej(err) t.matchSnapshot(logs, 'should display ws outdated deps json output') + t.equal(process.exitCode, 1) res() }) }) @@ -568,6 +586,7 @@ t.test('workspaces', async t => { rej(err) t.matchSnapshot(logs, 'should display ws outdated deps parseable output') + t.equal(process.exitCode, 1) res() }) }) @@ -582,6 +601,7 @@ t.test('workspaces', async t => { rej(err) t.matchSnapshot(logs, 'should display all dependencies') + t.equal(process.exitCode, 1) res() }) }) @@ -594,6 +614,7 @@ t.test('workspaces', async t => { rej(err) t.matchSnapshot(logs, 'should highlight ws in dependend by section') + t.equal(process.exitCode, 1) res() }) }) @@ -604,6 +625,7 @@ t.test('workspaces', async t => { rej(err) t.matchSnapshot(logs, 'should display results filtered by ws') + t.equal(process.exitCode, 1) res() }) }) @@ -618,6 +640,7 @@ t.test('workspaces', async t => { rej(err) t.matchSnapshot(logs, 'should display json results filtered by ws') + t.equal(process.exitCode, 1) res() }) }) @@ -632,6 +655,7 @@ t.test('workspaces', async t => { rej(err) t.matchSnapshot(logs, 'should display parseable results filtered by ws') + t.equal(process.exitCode, 1) res() }) }) @@ -647,6 +671,7 @@ t.test('workspaces', async t => { t.matchSnapshot(logs, 'should display nested deps when filtering by ws and using --all') + t.equal(process.exitCode, 1) res() }) }) @@ -669,6 +694,7 @@ t.test('workspaces', async t => { t.matchSnapshot(logs, 'should display missing deps when filtering by ws') + t.equal(process.exitCode, 1) res() }) }) diff --git a/deps/npm/test/lib/publish.js b/deps/npm/test/lib/publish.js index 6e0075835c..df73b6863b 100644 --- a/deps/npm/test/lib/publish.js +++ b/deps/npm/test/lib/publish.js @@ -9,14 +9,10 @@ const fs = require('fs') const log = require('npmlog') log.level = 'silent' -const cleanGithead = (result) => { - return result.map((r) => { - if (r.gitHead) - r.gitHead = '{GITHEAD}' - - return r - }) +t.cleanSnapshot = (data) => { + return data.replace(/^ *"gitHead": .*$\n/gm, '') } + const {definitions} = require('../../lib/utils/config') const defaults = Object.entries(definitions).reduce((defaults, [key, def]) => { defaults[key] = def.default @@ -589,7 +585,7 @@ t.test('workspaces', (t) => { log.level = 'info' publish.execWorkspaces([], [], (err) => { t.notOk(err) - t.matchSnapshot(cleanGithead(publishes), 'should publish all workspaces') + t.matchSnapshot(publishes, 'should publish all workspaces') t.matchSnapshot(outputs, 'should output all publishes') t.end() }) @@ -599,7 +595,7 @@ t.test('workspaces', (t) => { log.level = 'info' publish.execWorkspaces([], ['workspace-a'], (err) => { t.notOk(err) - t.matchSnapshot(cleanGithead(publishes), 'should publish given workspace') + t.matchSnapshot(publishes, 'should publish given workspace') t.matchSnapshot(outputs, 'should output one publish') t.end() }) @@ -618,7 +614,7 @@ t.test('workspaces', (t) => { npm.config.set('json', true) publish.execWorkspaces([], [], (err) => { t.notOk(err) - t.matchSnapshot(cleanGithead(publishes), 'should publish all workspaces') + t.matchSnapshot(publishes, 'should publish all workspaces') t.matchSnapshot(outputs, 'should output all publishes as json') t.end() }) @@ -707,7 +703,7 @@ t.test('private workspaces', (t) => { npm.color = true publish.execWorkspaces([], [], (err) => { t.notOk(err) - t.matchSnapshot(cleanGithead(publishes), 'should publish all non-private workspaces') + t.matchSnapshot(publishes, 'should publish all non-private workspaces') t.matchSnapshot(outputs, 'should output all publishes') npm.color = false t.end() @@ -734,7 +730,7 @@ t.test('private workspaces', (t) => { publish.execWorkspaces([], [], (err) => { t.notOk(err) - t.matchSnapshot(cleanGithead(publishes), 'should publish all non-private workspaces') + t.matchSnapshot(publishes, 'should publish all non-private workspaces') t.matchSnapshot(outputs, 'should output all publishes') t.end() }) diff --git a/deps/npm/test/lib/utils/open-url.js b/deps/npm/test/lib/utils/open-url.js index a31a8cb686..36724d0adf 100644 --- a/deps/npm/test/lib/utils/open-url.js +++ b/deps/npm/test/lib/utils/open-url.js @@ -47,11 +47,10 @@ t.test('returns error for non-https and non-file url', async (t) => { openerOpts = null OUTPUT.length = 0 }) - t.rejects(openUrl(npm, 'ftp://www.npmjs.com', 'npm home'), /Invalid URL/, 'got the correct error') + await t.rejects(openUrl(npm, 'ftp://www.npmjs.com', 'npm home'), /Invalid URL/, 'got the correct error') t.equal(openerUrl, null, 'did not open') t.same(openerOpts, null, 'did not open') t.same(OUTPUT, [], 'printed no output') - t.end() }) t.test('returns error for non-parseable url', async (t) => { @@ -60,11 +59,22 @@ t.test('returns error for non-parseable url', async (t) => { openerOpts = null OUTPUT.length = 0 }) - t.rejects(openUrl(npm, 'git+ssh://user@host:repo.git', 'npm home'), /Invalid URL/, 'got the correct error') + await t.rejects(openUrl(npm, 'git+ssh://user@host:repo.git', 'npm home'), /Invalid URL/, 'got the correct error') t.equal(openerUrl, null, 'did not open') t.same(openerOpts, null, 'did not open') t.same(OUTPUT, [], 'printed no output') - t.end() +}) + +t.test('encodes non-URL-safe characters in url provided', async (t) => { + t.teardown(() => { + openerUrl = null + openerOpts = null + OUTPUT.length = 0 + }) + await openUrl(npm, 'https://www.npmjs.com/|cat', 'npm home') + t.equal(openerUrl, 'https://www.npmjs.com/%7Ccat', 'opened the encoded url') + t.same(openerOpts, { command: null }, 'passed command as null (the default)') + t.same(OUTPUT, [], 'printed no output') }) t.test('opens a url with the given browser', async (t) => { @@ -79,7 +89,6 @@ t.test('opens a url with the given browser', async (t) => { t.equal(openerUrl, 'https://www.npmjs.com', 'opened the given url') t.same(openerOpts, { command: 'chrome' }, 'passed the given browser as command') t.same(OUTPUT, [], 'printed no output') - t.end() }) t.test('prints where to go when browser is disabled', async (t) => { @@ -96,7 +105,6 @@ t.test('prints where to go when browser is disabled', async (t) => { t.equal(OUTPUT.length, 1, 'got one logged message') t.equal(OUTPUT[0].length, 1, 'logged message had one value') t.matchSnapshot(OUTPUT[0][0], 'printed expected message') - t.end() }) t.test('prints where to go when browser is disabled and json is enabled', async (t) => { @@ -115,7 +123,6 @@ t.test('prints where to go when browser is disabled and json is enabled', async t.equal(OUTPUT.length, 1, 'got one logged message') t.equal(OUTPUT[0].length, 1, 'logged message had one value') t.matchSnapshot(OUTPUT[0][0], 'printed expected message') - t.end() }) t.test('prints where to go when given browser does not exist', async (t) => { @@ -133,7 +140,6 @@ t.test('prints where to go when given browser does not exist', async (t) => { t.equal(OUTPUT.length, 1, 'got one logged message') t.equal(OUTPUT[0].length, 1, 'logged message had one value') t.matchSnapshot(OUTPUT[0][0], 'printed expected message') - t.end() }) t.test('handles unknown opener error', async (t) => { @@ -146,5 +152,4 @@ t.test('handles unknown opener error', async (t) => { npm.config.set('browser', true) }) t.rejects(openUrl(npm, 'https://www.npmjs.com', 'npm home'), 'failed', 'got the correct error') - t.end() }) diff --git a/deps/npm/test/lib/utils/unsupported.js b/deps/npm/test/lib/utils/unsupported.js index 3a05d90666..4d806cefc4 100644 --- a/deps/npm/test/lib/utils/unsupported.js +++ b/deps/npm/test/lib/utils/unsupported.js @@ -27,10 +27,15 @@ const versions = [ ['v7.2.3', false, true], ['v8.4.0', false, true], ['v9.3.0', false, true], - ['v10.0.0-0', false, false], - ['v11.0.0-0', false, false], - ['v12.0.0-0', false, false], - ['v13.0.0-0', false, false], + ['v10.0.0-0', false, true], + ['v11.0.0-0', false, true], + ['v12.0.0-0', false, true], + ['v12.13.0-0', false, false], + ['v13.0.0-0', false, true], + ['v14.0.0-0', false, true], + ['v14.15.0-0', false, false], + ['v15.0.0-0', false, true], + ['v16.0.0-0', false, false], ] t.test('versions', function (t) { |