summaryrefslogtreecommitdiff
path: root/deps/npm/test/lib
diff options
context:
space:
mode:
authorRuy Adorno <ruyadorno@hotmail.com>2021-03-01 11:38:43 -0500
committerMichaël Zasso <targos@protonmail.com>2021-03-02 09:31:29 +0100
commit993963e2ee1c24dee0f39dbdbb3283272c30679c (patch)
tree7ad138c8a4b240f948e322eb2bc5c6d7acca32e6 /deps/npm/test/lib
parentb3f35e2c70c7d1e3ee7b4c3fd74672adceb16c52 (diff)
downloadnode-new-993963e2ee1c24dee0f39dbdbb3283272c30679c.tar.gz
deps: upgrade npm to 7.6.0
PR-URL: https://github.com/nodejs/node/pull/37559 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
Diffstat (limited to 'deps/npm/test/lib')
-rw-r--r--deps/npm/test/lib/access.js45
-rw-r--r--deps/npm/test/lib/audit.js33
-rw-r--r--deps/npm/test/lib/bugs.js8
-rw-r--r--deps/npm/test/lib/cache.js12
-rw-r--r--deps/npm/test/lib/completion.js93
-rw-r--r--deps/npm/test/lib/config.js36
-rw-r--r--deps/npm/test/lib/deprecate.js29
-rw-r--r--deps/npm/test/lib/dist-tag.js36
-rw-r--r--deps/npm/test/lib/docs.js8
-rw-r--r--deps/npm/test/lib/help.js13
-rw-r--r--deps/npm/test/lib/install.js74
-rw-r--r--deps/npm/test/lib/link.js31
-rw-r--r--deps/npm/test/lib/load-all-commands.js7
-rw-r--r--deps/npm/test/lib/ls.js15
-rw-r--r--deps/npm/test/lib/org.js11
-rw-r--r--deps/npm/test/lib/owner.js66
-rw-r--r--deps/npm/test/lib/profile.js47
-rw-r--r--deps/npm/test/lib/repo.js8
-rw-r--r--deps/npm/test/lib/restart.js1
-rw-r--r--deps/npm/test/lib/run-script.js48
-rw-r--r--deps/npm/test/lib/set-script.js1
-rw-r--r--deps/npm/test/lib/start.js1
-rw-r--r--deps/npm/test/lib/stop.js1
-rw-r--r--deps/npm/test/lib/team.js65
-rw-r--r--deps/npm/test/lib/token.js21
-rw-r--r--deps/npm/test/lib/unpublish.js16
-rw-r--r--deps/npm/test/lib/utils/completion/installed-deep.js125
-rw-r--r--deps/npm/test/lib/utils/completion/installed-shallow.js49
-rw-r--r--deps/npm/test/lib/utils/completion/none.js6
-rw-r--r--deps/npm/test/lib/utils/explain-dep.js17
-rw-r--r--deps/npm/test/lib/utils/lifecycle-cmd.js1
-rw-r--r--deps/npm/test/lib/version.js14
-rw-r--r--deps/npm/test/lib/view.js22
33 files changed, 370 insertions, 590 deletions
diff --git a/deps/npm/test/lib/access.js b/deps/npm/test/lib/access.js
index 3063b6c532..fb799f2df2 100644
--- a/deps/npm/test/lib/access.js
+++ b/deps/npm/test/lib/access.js
@@ -1,35 +1,24 @@
const { test } = require('tap')
const requireInject = require('require-inject')
-const emptyMock = requireInject('../../lib/access.js', {
+const access = requireInject('../../lib/access.js', {
'../../lib/npm.js': {
flatOptions: {},
},
})
test('completion', t => {
- const { completion } = emptyMock
+ const { completion } = access
const testComp = (argv, expect) => {
- completion({conf: {argv: {remain: argv}}}, (er, res) => {
- if (er)
- throw er
- t.strictSame(res, expect, argv.join(' '))
- })
+ const res = completion({conf: {argv: {remain: argv}}})
+ t.resolves(res, expect, argv.join(' '))
}
testComp(['npm', 'access'], [
- 'public',
- 'restricted',
- 'grant',
- 'revoke',
- 'ls-packages',
- 'ls-collaborators',
- 'edit',
- '2fa-required',
- '2fa-not-required',
+ 'public', 'restricted', 'grant', 'revoke', 'ls-packages',
+ 'ls-collaborators', 'edit', '2fa-required', '2fa-not-required',
])
-
testComp(['npm', 'access', 'grant'], ['read-only', 'read-write'])
testComp(['npm', 'access', 'grant', 'read-only'], [])
testComp(['npm', 'access', 'public'], [])
@@ -42,15 +31,15 @@ test('completion', t => {
testComp(['npm', 'access', '2fa-not-required'], [])
testComp(['npm', 'access', 'revoke'], [])
- completion({conf: {argv: {remain: ['npm', 'access', 'foobar']}}}, (er) => {
- t.match(er, { message: 'foobar not recognized' })
- })
+ t.rejects(
+ completion({conf: {argv: {remain: ['npm', 'access', 'foobar']}}}),
+ { message: 'foobar not recognized' }
+ )
t.end()
})
test('subcommand required', t => {
- const access = emptyMock
access([], (err) => {
t.equal(err, '\nUsage: Subcommand is required.\n\n' + access.usage)
t.end()
@@ -58,8 +47,6 @@ test('subcommand required', t => {
})
test('unrecognized subcommand', (t) => {
- const access = emptyMock
-
access(['blerg'], (err) => {
t.match(
err,
@@ -71,8 +58,6 @@ test('unrecognized subcommand', (t) => {
})
test('edit', (t) => {
- const access = emptyMock
-
access([
'edit',
'@scoped/another',
@@ -349,8 +334,6 @@ test('access grant current cwd', (t) => {
})
test('access grant others', (t) => {
- const access = emptyMock
-
access([
'grant',
'rerere',
@@ -367,8 +350,6 @@ test('access grant others', (t) => {
})
test('access grant missing team args', (t) => {
- const access = emptyMock
-
access([
'grant',
'read-only',
@@ -385,8 +366,6 @@ test('access grant missing team args', (t) => {
})
test('access grant malformed team arg', (t) => {
- const access = emptyMock
-
access([
'grant',
'read-only',
@@ -452,8 +431,6 @@ test('access revoke', (t) => {
})
test('access revoke missing team args', (t) => {
- const access = emptyMock
-
access([
'revoke',
undefined,
@@ -469,8 +446,6 @@ test('access revoke missing team args', (t) => {
})
test('access revoke malformed team arg', (t) => {
- const access = emptyMock
-
access([
'revoke',
'foo',
diff --git a/deps/npm/test/lib/audit.js b/deps/npm/test/lib/audit.js
index cc7379394b..3d6296bac6 100644
--- a/deps/npm/test/lib/audit.js
+++ b/deps/npm/test/lib/audit.js
@@ -168,35 +168,22 @@ t.test('report endpoint error', t => {
})
t.test('completion', t => {
- t.test('fix', t => {
- audit.completion({
- conf: { argv: { remain: ['npm', 'audit'] } },
- }, (err, res) => {
- if (err)
- throw err
- const subcmd = res.pop()
- t.equals('fix', subcmd, 'completes to fix')
- t.end()
- })
+ t.test('fix', async t => {
+ t.resolveMatch(audit.completion({ conf: { argv: { remain: ['npm', 'audit'] } } }), ['fix'], 'completes to fix')
+ t.end()
})
t.test('subcommand fix', t => {
- audit.completion({
- conf: { argv: { remain: ['npm', 'audit', 'fix'] } },
- }, (err) => {
- if (err)
- throw err
- t.end()
- })
+ t.resolveMatch(audit.completion({ conf: { argv: { remain: ['npm', 'audit', 'fix'] } } }), [], 'resolves to ?')
+ t.end()
})
t.test('subcommand not recognized', t => {
- audit.completion({
- conf: { argv: { remain: ['npm', 'audit', 'repare'] } },
- }, (err) => {
- t.ok(err, 'not recognized')
- t.end()
- })
+ t.rejects(
+ audit.completion({ conf: { argv: { remain: ['npm', 'audit', 'repare'] } } }),
+ { message: 'repare not recognized' }
+ )
+ t.end()
})
t.end()
diff --git a/deps/npm/test/lib/bugs.js b/deps/npm/test/lib/bugs.js
index df64349878..992bd9f614 100644
--- a/deps/npm/test/lib/bugs.js
+++ b/deps/npm/test/lib/bugs.js
@@ -54,14 +54,6 @@ const bugs = requireInject('../../lib/bugs.js', {
'../../lib/utils/open-url.js': openUrl,
})
-t.test('completion', t => {
- bugs.completion({}, (er, res) => {
- t.equal(er, null)
- t.same(res, [])
- t.end()
- })
-})
-
t.test('open bugs urls', t => {
const expect = {
nobugs: 'https://www.npmjs.com/package/nobugs',
diff --git a/deps/npm/test/lib/cache.js b/deps/npm/test/lib/cache.js
index 2e9ad346bb..05d269dd4d 100644
--- a/deps/npm/test/lib/cache.js
+++ b/deps/npm/test/lib/cache.js
@@ -208,18 +208,10 @@ t.test('cache completion', t => {
const { completion } = cache
const testComp = (argv, expect) => {
- completion({ conf: { argv: { remain: argv } } }, (err, res) => {
- t.ifError(err)
- t.strictSame(res, expect, argv.join(' '))
- })
+ t.resolveMatch(completion({ conf: { argv: { remain: argv } } }), expect, argv.join(' '))
}
- testComp(['npm', 'cache'], [
- 'add',
- 'clean',
- 'verify',
- ])
-
+ testComp(['npm', 'cache'], ['add', 'clean', 'verify'])
testComp(['npm', 'cache', 'add'], [])
testComp(['npm', 'cache', 'clean'], [])
testComp(['npm', 'cache', 'verify'], [])
diff --git a/deps/npm/test/lib/completion.js b/deps/npm/test/lib/completion.js
index 367a1c03ab..19f70df20e 100644
--- a/deps/npm/test/lib/completion.js
+++ b/deps/npm/test/lib/completion.js
@@ -21,28 +21,28 @@ const npm = {
},
commands: {
completion: {
- completion: (opts, cb) => {
- return cb(null, [['>>', '~/.bashrc']])
- },
+ completion: () => [['>>', '~/.bashrc']],
},
adduser: {},
access: {
- completion: (opts, cb) => {
+ completion: () => {
if (accessCompletionError)
- return cb(new Error('access completion failed'))
+ throw new Error('access completion failed')
- return cb(null, ['public', 'restricted'])
+ return ['public', 'restricted']
},
},
+ promise: {
+ completion: () => Promise.resolve(['resolved_completion_promise']),
+ },
donothing: {
- completion: (opts, cb) => {
- return cb(null, null)
+ completion: () => {
+ return null
},
},
driveaboat: {
- completion: (opts, cb) => {
- // the leading space here is to exercise the escape method
- return cb(null, ' fast')
+ completion: () => {
+ return ' fast'
},
},
},
@@ -86,7 +86,7 @@ const completion = requireInject('../../lib/completion.js', {
},
})
-test('completion completion', t => {
+test('completion completion', async t => {
const home = process.env.HOME
t.teardown(() => {
process.env.HOME = home
@@ -97,19 +97,15 @@ test('completion completion', t => {
'.zshrc': '',
})
- completion.completion({ w: 2 }, (err, res) => {
- if (err)
- throw err
-
- t.strictSame(res, [
- ['>>', '~/.zshrc'],
- ['>>', '~/.bashrc'],
- ], 'identifies both shells')
- t.end()
- })
+ const res = await completion.completion({ w: 2 })
+ t.strictSame(res, [
+ ['>>', '~/.zshrc'],
+ ['>>', '~/.bashrc'],
+ ], 'identifies both shells')
+ t.end()
})
-test('completion completion no known shells', t => {
+test('completion completion no known shells', async t => {
const home = process.env.HOME
t.teardown(() => {
process.env.HOME = home
@@ -117,23 +113,15 @@ test('completion completion no known shells', t => {
process.env.HOME = t.testdir()
- completion.completion({ w: 2 }, (err, res) => {
- if (err)
- throw err
-
- t.strictSame(res, [], 'no responses')
- t.end()
- })
+ const res = await completion.completion({ w: 2 })
+ t.strictSame(res, [], 'no responses')
+ t.end()
})
-test('completion completion wrong word count', t => {
- completion.completion({ w: 3 }, (err, res) => {
- if (err)
- throw err
-
- t.strictSame(res, undefined, 'no responses')
- t.end()
- })
+test('completion completion wrong word count', async t => {
+ const res = await completion.completion({ w: 3 })
+ t.strictSame(res, undefined, 'no responses')
+ t.end()
})
test('completion errors in windows without bash', t => {
@@ -313,6 +301,35 @@ test('completion of invalid command name does nothing', t => {
})
})
+test('handles async completion function', t => {
+ process.env.COMP_CWORD = 2
+ process.env.COMP_LINE = 'npm promise'
+ process.env.COMP_POINT = process.env.COMP_LINE.length
+
+ t.teardown(() => {
+ delete process.env.COMP_CWORD
+ delete process.env.COMP_LINE
+ delete process.env.COMP_POINT
+ npm.config.clear()
+ output.length = 0
+ })
+
+ completion(['npm', 'promise', ''], (err, res) => {
+ if (err)
+ throw err
+
+ t.strictSame(npmConfig, {
+ argv: {
+ remain: ['npm', 'promise'],
+ cooked: ['npm', 'promise'],
+ original: ['npm', 'promise'],
+ },
+ }, 'applies command config appropriately')
+ t.strictSame(output, ['resolved_completion_promise'], 'resolves async completion results')
+ t.end()
+ })
+})
+
test('completion triggers command completions', t => {
process.env.COMP_CWORD = 2
process.env.COMP_LINE = 'npm access '
diff --git a/deps/npm/test/lib/config.js b/deps/npm/test/lib/config.js
index 5d2f54249c..edaa6486cd 100644
--- a/deps/npm/test/lib/config.js
+++ b/deps/npm/test/lib/config.js
@@ -610,23 +610,13 @@ t.test('completion', t => {
const { completion } = config
const testComp = (argv, expect) => {
- completion({ conf: { argv: { remain: argv } } }, (er, res) => {
- t.ifError(er)
- t.strictSame(res, expect, argv.join(' '))
- })
+ t.resolveMatch(completion({ conf: { argv: { remain: argv } } }), expect, argv.join(' '))
}
testComp(['npm', 'foo'], [])
- testComp(['npm', 'config'], [
- 'get',
- 'set',
- 'delete',
- 'ls',
- 'rm',
- 'edit',
- 'list',
- ])
+ testComp(['npm', 'config'], ['get', 'set', 'delete', 'ls', 'rm', 'edit', 'list'])
testComp(['npm', 'config', 'set', 'foo'], [])
+
const possibleConfigKeys = [...Object.keys(types)]
testComp(['npm', 'config', 'get'], possibleConfigKeys)
testComp(['npm', 'config', 'set'], possibleConfigKeys)
@@ -636,24 +626,8 @@ t.test('completion', t => {
testComp(['npm', 'config', 'list'], [])
testComp(['npm', 'config', 'ls'], [])
- completion({
- conf: {
- argv: {
- remain: ['npm', 'config'],
- },
- },
- partialWord: 'l',
- }, (er, res) => {
- t.ifError(er)
- t.strictSame(res, [
- 'get',
- 'set',
- 'delete',
- 'ls',
- 'rm',
- 'edit',
- ], 'npm config')
- })
+ const partial = completion({conf: { argv: { remain: ['npm', 'config'] } }, partialWord: 'l'})
+ t.resolveMatch(partial, ['get', 'set', 'delete', 'ls', 'rm', 'edit'], 'npm config')
t.end()
})
diff --git a/deps/npm/test/lib/deprecate.js b/deps/npm/test/lib/deprecate.js
index 229cb9137a..fd563de120 100644
--- a/deps/npm/test/lib/deprecate.js
+++ b/deps/npm/test/lib/deprecate.js
@@ -38,29 +38,24 @@ test('completion', async t => {
const { completion } = deprecate
- const testComp = (argv, expect) => {
- return new Promise((resolve, reject) => {
- completion({ conf: { argv: { remain: argv } } }, (err, res) => {
- if (err)
- return reject(err)
-
- t.strictSame(res, expect, `completion: ${argv}`)
- resolve()
- })
- })
+ const testComp = async (argv, expect) => {
+ const res = await completion({ conf: { argv: { remain: argv } } })
+ t.strictSame(res, expect, `completion: ${argv}`)
}
- await testComp([], ['foo', 'bar', 'baz'])
- await testComp(['b'], ['bar', 'baz'])
- await testComp(['fo'], ['foo'])
- await testComp(['g'], [])
- await testComp(['foo', 'something'], [])
+ await Promise.all([
+ testComp([], ['foo', 'bar', 'baz']),
+ testComp(['b'], ['bar', 'baz']),
+ testComp(['fo'], ['foo']),
+ testComp(['g'], []),
+ testComp(['foo', 'something'], []),
+ ])
getIdentityImpl = () => {
- throw new Error('unknown failure')
+ throw new Error('deprecate test failure')
}
- t.rejects(testComp([], []), /unknown failure/)
+ t.rejects(testComp([], []), { message: 'deprecate test failure' })
})
test('no args', t => {
diff --git a/deps/npm/test/lib/dist-tag.js b/deps/npm/test/lib/dist-tag.js
index 8b1106fa39..c189352302 100644
--- a/deps/npm/test/lib/dist-tag.js
+++ b/deps/npm/test/lib/dist-tag.js
@@ -294,35 +294,13 @@ test('remove missing pkg name', (t) => {
test('completion', t => {
const { completion } = distTag
- t.plan(3)
+ t.plan(2)
- completion({
- conf: {
- argv: {
- remain: ['npm', 'dist-tag'],
- },
- },
- }, (err, res) => {
- t.ifError(err, 'npm dist-tags completion')
-
- t.strictSame(
- res,
- [
- 'add',
- 'rm',
- 'ls',
- ],
- 'should list npm dist-tag commands for completion'
- )
- })
+ const match = completion({ conf: { argv: { remain: ['npm', 'dist-tag'] } } })
+ t.resolveMatch(match, ['add', 'rm', 'ls'],
+ 'should list npm dist-tag commands for completion')
- completion({
- conf: {
- argv: {
- remain: ['npm', 'dist-tag', 'foobar'],
- },
- },
- }, (err) => {
- t.notOk(err, 'should ignore any unknown name')
- })
+ const noMatch = completion({ conf: { argv: { remain: ['npm', 'dist-tag', 'foobar'] } } })
+ t.resolveMatch(noMatch, [])
+ t.end()
})
diff --git a/deps/npm/test/lib/docs.js b/deps/npm/test/lib/docs.js
index b4ede87316..8a59ed7cc0 100644
--- a/deps/npm/test/lib/docs.js
+++ b/deps/npm/test/lib/docs.js
@@ -44,14 +44,6 @@ const docs = requireInject('../../lib/docs.js', {
'../../lib/utils/open-url.js': openUrl,
})
-t.test('completion', t => {
- docs.completion({}, (er, res) => {
- t.equal(er, null)
- t.same(res, [])
- t.end()
- })
-})
-
t.test('open docs urls', t => {
const expect = {
nodocs: 'https://www.npmjs.com/package/nodocs',
diff --git a/deps/npm/test/lib/help.js b/deps/npm/test/lib/help.js
index 40a0354210..fc4a32e07b 100644
--- a/deps/npm/test/lib/help.js
+++ b/deps/npm/test/lib/help.js
@@ -101,20 +101,13 @@ test('npm help completion', async t => {
t.teardown(() => {
globErr = null
})
- const completion = (opts) => new Promise((resolve, reject) => {
- help.completion(opts, (err, res) => {
- if (err)
- return reject(err)
- return resolve(res)
- })
- })
- const noArgs = await completion({ conf: { argv: { remain: [] } } })
+ const noArgs = await help.completion({ conf: { argv: { remain: [] } } })
t.strictSame(noArgs, ['help', 'whoami', 'npmrc', 'disputes'], 'outputs available help pages')
- const threeArgs = await completion({ conf: { argv: { remain: ['one', 'two', 'three'] } } })
+ const threeArgs = await help.completion({ conf: { argv: { remain: ['one', 'two', 'three'] } } })
t.strictSame(threeArgs, [], 'outputs no results when more than 2 args are provided')
globErr = new Error('glob failed')
- t.rejects(completion({ conf: { argv: { remain: [] } } }), /glob failed/, 'glob errors propagate')
+ t.rejects(help.completion({ conf: { argv: { remain: [] } } }), /glob failed/, 'glob errors propagate')
})
test('npm help -h', t => {
diff --git a/deps/npm/test/lib/install.js b/deps/npm/test/lib/install.js
index 177952b9e9..859a4bdaaa 100644
--- a/deps/npm/test/lib/install.js
+++ b/deps/npm/test/lib/install.js
@@ -130,7 +130,7 @@ test('should install globally using Arborist', (t) => {
})
})
-test('completion to folder', (t) => {
+test('completion to folder', async t => {
const install = requireInject('../../lib/install.js', {
'../../lib/utils/reify-finish.js': async () => {},
util: {
@@ -145,17 +145,13 @@ test('completion to folder', (t) => {
},
},
})
- install.completion({
- partialWord: '/ar',
- }, (er, res) => {
- t.equal(er, null)
- const expect = process.platform === 'win32' ? '\\arborist' : '/arborist'
- t.strictSame(res, [expect], 'package dir match')
- t.end()
- })
+ const res = await install.completion({ partialWord: '/ar' })
+ const expect = process.platform === 'win32' ? '\\arborist' : '/arborist'
+ t.strictSame(res, [expect], 'package dir match')
+ t.end()
})
-test('completion to folder - invalid dir', (t) => {
+test('completion to folder - invalid dir', async t => {
const install = requireInject('../../lib/install.js', {
'../../lib/utils/reify-finish.js': async () => {},
util: {
@@ -167,16 +163,12 @@ test('completion to folder - invalid dir', (t) => {
},
},
})
- install.completion({
- partialWord: 'path/to/folder',
- }, (er, res) => {
- t.equal(er, null)
- t.strictSame(res, [], 'invalid dir: no matching')
- t.end()
- })
+ const res = await install.completion({ partialWord: 'path/to/folder' })
+ t.strictSame(res, [], 'invalid dir: no matching')
+ t.end()
})
-test('completion to folder - no matches', (t) => {
+test('completion to folder - no matches', async t => {
const install = requireInject('../../lib/install.js', {
'../../lib/utils/reify-finish.js': async () => {},
util: {
@@ -188,16 +180,12 @@ test('completion to folder - no matches', (t) => {
},
},
})
- install.completion({
- partialWord: '/pa',
- }, (er, res) => {
- t.equal(er, null)
- t.strictSame(res, [], 'no name match')
- t.end()
- })
+ const res = await install.completion({ partialWord: '/pa' })
+ t.strictSame(res, [], 'no name match')
+ t.end()
})
-test('completion to folder - match is not a package', (t) => {
+test('completion to folder - match is not a package', async t => {
const install = requireInject('../../lib/install.js', {
'../../lib/utils/reify-finish.js': async () => {},
util: {
@@ -212,31 +200,19 @@ test('completion to folder - match is not a package', (t) => {
},
},
})
- install.completion({
- partialWord: '/ar',
- }, (er, res) => {
- t.equal(er, null)
- t.strictSame(res, [], 'no name match')
- t.end()
- })
+ const res = await install.completion({ partialWord: '/ar' })
+ t.strictSame(res, [], 'no name match')
+ t.end()
})
-test('completion to url', (t) => {
- install.completion({
- partialWord: 'http://path/to/url',
- }, (er, res) => {
- t.equal(er, null)
- t.strictSame(res, [])
- t.end()
- })
+test('completion to url', async t => {
+ const res = await install.completion({ partialWord: 'http://path/to/url' })
+ t.strictSame(res, [])
+ t.end()
})
-test('completion', (t) => {
- install.completion({
- partialWord: 'toto',
- }, (er, res) => {
- t.notOk(er)
- t.notOk(res)
- t.end()
- })
+test('completion', async t => {
+ const res = await install.completion({ partialWord: 'toto' })
+ t.notOk(res)
+ t.end()
})
diff --git a/deps/npm/test/lib/link.js b/deps/npm/test/lib/link.js
index c39026a491..b1048427d7 100644
--- a/deps/npm/test/lib/link.js
+++ b/deps/npm/test/lib/link.js
@@ -317,7 +317,7 @@ t.test('link pkg already in global space when prefix is a symlink', (t) => {
})
})
-t.test('completion', (t) => {
+t.test('completion', async t => {
const testdir = t.testdir({
'global-prefix': {
lib: {
@@ -332,31 +332,30 @@ t.test('completion', (t) => {
})
npm.globalDir = resolve(testdir, 'global-prefix', 'lib', 'node_modules')
- link.completion({}, (err, words) => {
- t.ifError(err, 'should not error out')
- t.deepEqual(
- words,
- ['bar', 'foo', 'ipsum', 'lorem'],
- 'should list all package names available in globalDir'
- )
- t.end()
- })
+ const words = await link.completion({})
+ t.deepEqual(
+ words,
+ ['bar', 'foo', 'ipsum', 'lorem'],
+ 'should list all package names available in globalDir'
+ )
+ t.end()
})
-t.test('--global option', (t) => {
+t.test('--global option', async t => {
const _config = npm.config
npm.config = { get () {
return true
} }
- link([], (err) => {
+ try {
+ await link([])
+ t.fail('should not get here')
+ } catch (err) {
npm.config = _config
-
t.match(
err.message,
/link should never be --global/,
'should throw an useful error'
)
-
- t.end()
- })
+ }
+ t.end()
})
diff --git a/deps/npm/test/lib/load-all-commands.js b/deps/npm/test/lib/load-all-commands.js
index fa73b8a78d..02cb0be650 100644
--- a/deps/npm/test/lib/load-all-commands.js
+++ b/deps/npm/test/lib/load-all-commands.js
@@ -12,11 +12,14 @@ t.test('load each command', t => {
t.plan(cmdList.length)
for (const cmd of cmdList.sort((a, b) => a.localeCompare(b))) {
t.test(cmd, t => {
- t.plan(3)
const impl = npm.commands[cmd]
+ if (impl.completion) {
+ t.plan(3)
+ t.isa(impl.completion, 'function', 'completion, if present, is a function')
+ } else
+ t.plan(2)
t.isa(impl, 'function', 'implementation is a function')
t.isa(impl.usage, 'string', 'usage is a string')
- t.isa(impl.completion, 'function', 'completion is a function')
})
}
})
diff --git a/deps/npm/test/lib/ls.js b/deps/npm/test/lib/ls.js
index a89137b9ef..b1df9067c3 100644
--- a/deps/npm/test/lib/ls.js
+++ b/deps/npm/test/lib/ls.js
@@ -3,6 +3,12 @@ const { resolve } = require('path')
const t = require('tap')
const requireInject = require('require-inject')
+const { utimesSync } = require('fs')
+const touchHiddenPackageLock = prefix => {
+ const later = new Date(Date.now() + 10000)
+ utimesSync(`${prefix}/node_modules/.package-lock.json`, later, later)
+}
+
t.cleanSnapshot = str => str.split(/\r\n/).join('\n')
const simpleNmFixture = {
@@ -1186,6 +1192,7 @@ t.test('ls', (t) => {
},
},
})
+ touchHiddenPackageLock(prefix)
ls([], () => {
t.matchSnapshot(redactCwd(result), 'should output tree containing aliases')
t.end()
@@ -1231,6 +1238,7 @@ t.test('ls', (t) => {
},
},
})
+ touchHiddenPackageLock(prefix)
ls([], (err) => {
t.ifError(err, 'npm ls')
t.matchSnapshot(redactCwd(result), 'should output tree containing git refs')
@@ -1329,6 +1337,7 @@ t.test('ls', (t) => {
},
},
})
+ touchHiddenPackageLock(prefix)
ls([], () => {
t.matchSnapshot(redactCwd(result), 'should not be printed in tree output')
t.end()
@@ -2228,6 +2237,7 @@ t.test('ls --parseable', (t) => {
},
},
})
+ touchHiddenPackageLock(prefix)
ls([], () => {
t.matchSnapshot(redactCwd(result), 'should output tree containing aliases')
t.end()
@@ -2272,6 +2282,7 @@ t.test('ls --parseable', (t) => {
},
},
})
+ touchHiddenPackageLock(prefix)
ls([], () => {
t.matchSnapshot(redactCwd(result), 'should output tree containing git refs')
t.end()
@@ -2325,6 +2336,7 @@ t.test('ls --parseable', (t) => {
},
},
})
+ touchHiddenPackageLock(prefix)
ls([], () => {
t.matchSnapshot(redactCwd(result), 'should not be printed in tree output')
t.end()
@@ -3688,6 +3700,7 @@ t.test('ls --json', (t) => {
},
},
})
+ touchHiddenPackageLock(prefix)
ls([], () => {
t.deepEqual(
jsonParse(result),
@@ -3747,6 +3760,7 @@ t.test('ls --json', (t) => {
},
},
})
+ touchHiddenPackageLock(prefix)
ls([], () => {
t.deepEqual(
jsonParse(result),
@@ -3830,6 +3844,7 @@ t.test('ls --json', (t) => {
},
},
})
+ touchHiddenPackageLock(prefix)
ls([], () => {
t.deepEqual(
jsonParse(result),
diff --git a/deps/npm/test/lib/org.js b/deps/npm/test/lib/org.js
index 68e3c9f0d6..1e8aabc1d7 100644
--- a/deps/npm/test/lib/org.js
+++ b/deps/npm/test/lib/org.js
@@ -49,13 +49,8 @@ const org = requireInject('../../lib/org.js', {
})
test('completion', async t => {
- const completion = (argv) => new Promise((resolve, reject) => {
- org.completion({ conf: { argv: { remain: argv } } }, (err, res) => {
- if (err)
- return reject(err)
- return resolve(res)
- })
- })
+ const completion = (argv) =>
+ org.completion({ conf: { argv: { remain: argv } } })
const assertions = [
[['npm', 'org'], ['set', 'rm', 'ls']],
@@ -66,7 +61,7 @@ test('completion', async t => {
]
for (const [argv, expected] of assertions)
- t.strictSame(await completion(argv), expected, `completion for: ${argv.join(', ')}`)
+ t.resolveMatch(completion(argv), expected, `completion for: ${argv.join(', ')}`)
t.rejects(completion(['npm', 'org', 'flurb']), /flurb not recognized/, 'errors for unknown subcommand')
})
diff --git a/deps/npm/test/lib/owner.js b/deps/npm/test/lib/owner.js
index c5f9d646c2..aa5e3ee637 100644
--- a/deps/npm/test/lib/owner.js
+++ b/deps/npm/test/lib/owner.js
@@ -699,29 +699,25 @@ t.test('owner rm <user> no cwd package', t => {
})
})
-t.test('completion', t => {
+t.test('completion', async t => {
const { completion } = owner
- const testComp = (argv, expect) => {
- completion({ conf: { argv: { remain: argv } } }, (err, res) => {
- t.ifError(err)
- t.strictSame(res, expect, argv.join(' '))
- })
+ const testComp = async (argv, expect) => {
+ const res = await completion({ conf: { argv: { remain: argv } } })
+ t.strictSame(res, expect, argv.join(' '))
}
- testComp(['npm', 'foo'], [])
- testComp(['npm', 'owner'], [
- 'add',
- 'rm',
- 'ls',
+ await Promise.all([
+ testComp(['npm', 'foo'], []),
+ testComp(['npm', 'owner'], ['add', 'rm', 'ls']),
+ testComp(['npm', 'owner', 'add'], []),
+ testComp(['npm', 'owner', 'ls'], []),
+ testComp(['npm', 'owner', 'rm', 'foo'], []),
])
- testComp(['npm', 'owner', 'add'], [])
- testComp(['npm', 'owner', 'ls'], [])
- testComp(['npm', 'owner', 'rm', 'foo'], [])
// npm owner rm completion is async
- t.test('completion npm owner rm', t => {
- t.plan(3)
+ t.test('completion npm owner rm', async t => {
+ t.plan(2)
readLocalPkgResponse = '@npmcli/map-workspaces'
pacote.packument = async spec => {
t.equal(spec.name, readLocalPkgResponse, 'should use package spec')
@@ -734,31 +730,21 @@ t.test('completion', t => {
pacote.packument = noop
})
- completion({ conf: { argv: { remain: ['npm', 'owner', 'rm'] } } }, (err, res) => {
- t.ifError(err, 'npm owner rm completion')
- t.strictSame(
- res,
- [
- 'nlf',
- 'ruyadorno',
- 'darcyclarke',
- 'isaacs',
- ],
- 'should return list of current owners'
- )
- })
+ const res = await completion({ conf: { argv: { remain: ['npm', 'owner', 'rm'] } } })
+ t.strictSame(res,
+ ['nlf', 'ruyadorno', 'darcyclarke', 'isaacs'],
+ 'should return list of current owners'
+ )
})
- t.test('completion npm owner rm no cwd package', t => {
- completion({ conf: { argv: { remain: ['npm', 'owner', 'rm'] } } }, (err, res) => {
- t.ifError(err, 'npm owner rm completion')
- t.strictSame(res, [], 'should have no owners to autocomplete if not cwd package')
- t.end()
- })
+ t.test('completion npm owner rm no cwd package', async t => {
+ const res = await completion({ conf: { argv: { remain: ['npm', 'owner', 'rm'] } } })
+ t.strictSame(res, [], 'should have no owners to autocomplete if not cwd package')
+ t.end()
})
- t.test('completion npm owner rm no owners found', t => {
- t.plan(3)
+ t.test('completion npm owner rm no owners found', async t => {
+ t.plan(2)
readLocalPkgResponse = '@npmcli/map-workspaces'
pacote.packument = async spec => {
t.equal(spec.name, readLocalPkgResponse, 'should use package spec')
@@ -771,10 +757,8 @@ t.test('completion', t => {
pacote.packument = noop
})
- completion({ conf: { argv: { remain: ['npm', 'owner', 'rm'] } } }, (err, res) => {
- t.ifError(err, 'npm owner rm completion')
- t.strictSame(res, [], 'should return no owners if not found')
- })
+ const res = await completion({ conf: { argv: { remain: ['npm', 'owner', 'rm'] } } })
+ t.strictSame(res, [], 'should return no owners if not found')
})
t.end()
diff --git a/deps/npm/test/lib/profile.js b/deps/npm/test/lib/profile.js
index 48a558cace..3b2e140036 100644
--- a/deps/npm/test/lib/profile.js
+++ b/deps/npm/test/lib/profile.js
@@ -1398,17 +1398,16 @@ t.test('unknown subcommand', t => {
t.test('completion', t => {
const { completion } = profile
- const testComp = ({ t, argv, expect, title }) => {
- completion({ conf: { argv: { remain: argv } } }, (err, res) => {
- if (err)
- throw err
-
- t.strictSame(res, expect, title)
- })
+ const testComp = async ({ t, argv, expect, title }) => {
+ t.resolveMatch(
+ completion({ conf: { argv: { remain: argv } } }),
+ expect,
+ title
+ )
}
- t.test('npm profile autocomplete', t => {
- testComp({
+ t.test('npm profile autocomplete', async t => {
+ await testComp({
t,
argv: ['npm', 'profile'],
expect: ['enable-2fa', 'disable-2fa', 'get', 'set'],
@@ -1418,8 +1417,8 @@ t.test('completion', t => {
t.end()
})
- t.test('npm profile enable autocomplete', t => {
- testComp({
+ t.test('npm profile enable autocomplete', async t => {
+ await testComp({
t,
argv: ['npm', 'profile', 'enable-2fa'],
expect: ['auth-and-writes', 'auth-only'],
@@ -1429,10 +1428,10 @@ t.test('completion', t => {
t.end()
})
- t.test('npm profile <subcmd> no autocomplete', t => {
+ t.test('npm profile <subcmd> no autocomplete', async t => {
const noAutocompleteCmds = ['disable-2fa', 'disable-tfa', 'get', 'set']
for (const subcmd of noAutocompleteCmds) {
- testComp({
+ await testComp({
t,
argv: ['npm', 'profile', subcmd],
expect: [],
@@ -1443,22 +1442,12 @@ t.test('completion', t => {
t.end()
})
- t.test('npm profile unknown subcommand autocomplete', t => {
- completion({
- conf: {
- argv: {
- remain: ['npm', 'profile', 'asdf'],
- },
- },
- }, (err, res) => {
- t.match(
- err,
- /asdf not recognized/,
- 'should throw unknown cmd error'
- )
-
- t.end()
- })
+ t.test('npm profile unknown subcommand autocomplete', async t => {
+ t.rejects(
+ completion({ conf: { argv: { remain: ['npm', 'profile', 'asdf'] } } }),
+ { message: 'asdf not recognized' }, 'should throw unknown cmd error'
+ )
+ t.end()
})
t.end()
diff --git a/deps/npm/test/lib/repo.js b/deps/npm/test/lib/repo.js
index c4b1b46e73..3367f7c885 100644
--- a/deps/npm/test/lib/repo.js
+++ b/deps/npm/test/lib/repo.js
@@ -119,14 +119,6 @@ const repo = requireInject('../../lib/repo.js', {
'../../lib/utils/open-url.js': openUrl,
})
-t.test('completion', t => {
- repo.completion({}, (er, res) => {
- t.equal(er, null)
- t.same(res, [])
- t.end()
- })
-})
-
t.test('open repo urls', t => {
const expect = {
hostedgit: 'https://github.com/foo/hostedgit',
diff --git a/deps/npm/test/lib/restart.js b/deps/npm/test/lib/restart.js
index fde7988888..a19bfd0d41 100644
--- a/deps/npm/test/lib/restart.js
+++ b/deps/npm/test/lib/restart.js
@@ -1,5 +1,4 @@
const t = require('tap')
const restart = require('../../lib/restart.js')
t.isa(restart, Function)
-t.equal(restart.completion, require('../../lib/utils/completion/none.js'), 'empty completion')
t.equal(restart.usage, 'npm restart [-- <args>]')
diff --git a/deps/npm/test/lib/run-script.js b/deps/npm/test/lib/run-script.js
index 070f766b44..974202aa8c 100644
--- a/deps/npm/test/lib/run-script.js
+++ b/deps/npm/test/lib/run-script.js
@@ -42,45 +42,29 @@ const { writeFileSync } = require('fs')
t.test('completion', t => {
const dir = t.testdir()
npm.localPrefix = dir
- t.test('already have a script name', t => {
- runScript.completion({conf: {argv: {remain: ['npm', 'run', 'x']}}}, (er, results) => {
- if (er)
- throw er
-
- t.equal(results, undefined)
- t.end()
- })
+ t.test('already have a script name', async t => {
+ const res = await runScript.completion({conf: {argv: {remain: ['npm', 'run', 'x']}}})
+ t.equal(res, undefined)
+ t.end()
})
- t.test('no package.json', t => {
- runScript.completion({conf: {argv: {remain: ['npm', 'run']}}}, (er, results) => {
- if (er)
- throw er
-
- t.strictSame(results, [])
- t.end()
- })
+ t.test('no package.json', async t => {
+ const res = await runScript.completion({conf: {argv: {remain: ['npm', 'run']}}})
+ t.strictSame(res, [])
+ t.end()
})
- t.test('has package.json, no scripts', t => {
+ t.test('has package.json, no scripts', async t => {
writeFileSync(`${dir}/package.json`, JSON.stringify({}))
- runScript.completion({conf: {argv: {remain: ['npm', 'run']}}}, (er, results) => {
- if (er)
- throw er
-
- t.strictSame(results, [])
- t.end()
- })
+ const res = await runScript.completion({conf: {argv: {remain: ['npm', 'run']}}})
+ t.strictSame(res, [])
+ t.end()
})
- t.test('has package.json, with scripts', t => {
+ t.test('has package.json, with scripts', async t => {
writeFileSync(`${dir}/package.json`, JSON.stringify({
scripts: { hello: 'echo hello', world: 'echo world' },
}))
- runScript.completion({conf: {argv: {remain: ['npm', 'run']}}}, (er, results) => {
- if (er)
- throw er
-
- t.strictSame(results, ['hello', 'world'])
- t.end()
- })
+ const res = await runScript.completion({conf: {argv: {remain: ['npm', 'run']}}})
+ t.strictSame(res, ['hello', 'world'])
+ t.end()
})
t.end()
})
diff --git a/deps/npm/test/lib/set-script.js b/deps/npm/test/lib/set-script.js
index ab25ba968a..196fd3d3e6 100644
--- a/deps/npm/test/lib/set-script.js
+++ b/deps/npm/test/lib/set-script.js
@@ -4,7 +4,6 @@ const setScriptDefault = require('../../lib/set-script.js')
const parseJSON = require('json-parse-even-better-errors')
test.type(setScriptDefault, 'function', 'command is function')
-test.equal(setScriptDefault.completion, require('../../lib/utils/completion/none.js'), 'empty completion')
test.equal(setScriptDefault.usage, 'npm set-script [<script>] [<command>]', 'usage matches')
test.test('fails on invalid arguments', (t) => {
const setScript = requireInject('../../lib/set-script.js', {
diff --git a/deps/npm/test/lib/start.js b/deps/npm/test/lib/start.js
index 1277412758..4f599223d7 100644
--- a/deps/npm/test/lib/start.js
+++ b/deps/npm/test/lib/start.js
@@ -1,5 +1,4 @@
const t = require('tap')
const start = require('../../lib/start.js')
t.isa(start, Function)
-t.equal(start.completion, require('../../lib/utils/completion/none.js'), 'empty completion')
t.equal(start.usage, 'npm start [-- <args>]')
diff --git a/deps/npm/test/lib/stop.js b/deps/npm/test/lib/stop.js
index d015161d2f..4e26703c93 100644
--- a/deps/npm/test/lib/stop.js
+++ b/deps/npm/test/lib/stop.js
@@ -1,5 +1,4 @@
const t = require('tap')
const stop = require('../../lib/stop.js')
t.isa(stop, Function)
-t.equal(stop.completion, require('../../lib/utils/completion/none.js'), 'empty completion')
t.equal(stop.usage, 'npm stop [-- <args>]')
diff --git a/deps/npm/test/lib/team.js b/deps/npm/test/lib/team.js
index c534cc8327..9edaf58ee7 100644
--- a/deps/npm/test/lib/team.js
+++ b/deps/npm/test/lib/team.js
@@ -506,66 +506,45 @@ t.test('team rm <scope:team> <user>', t => {
t.test('completion', t => {
const { completion } = team
- t.test('npm team autocomplete', t => {
- completion({
+ t.test('npm team autocomplete', async t => {
+ const res = await completion({
conf: {
argv: {
remain: ['npm', 'team'],
},
},
- }, (err, res) => {
- if (err)
- throw err
-
- t.strictSame(
- res,
- ['create', 'destroy', 'add', 'rm', 'ls'],
- 'should auto complete with subcommands'
- )
-
- t.end()
})
+ t.strictSame(
+ res,
+ ['create', 'destroy', 'add', 'rm', 'ls'],
+ 'should auto complete with subcommands'
+ )
+ t.end()
})
t.test('npm team <subcommand> autocomplete', async t => {
- const check = (subcmd) => new Promise((res, rej) =>
- completion({
+ for (const subcmd of ['create', 'destroy', 'add', 'rm', 'ls']) {
+ const res = await completion({
conf: {
argv: {
remain: ['npm', 'team', subcmd],
},
},
- }, (err, response) => {
- if (err)
- rej(err)
-
- t.strictSame(
- response,
- [],
- `should not autocomplete ${subcmd} subcommand`
- )
- res()
- }))
-
- await ['create', 'destroy', 'add', 'rm', 'ls'].map(check)
+ })
+ t.strictSame(
+ res,
+ [],
+ `should not autocomplete ${subcmd} subcommand`
+ )
+ }
})
- t.test('npm team unknown subcommand autocomplete', t => {
- completion({
- conf: {
- argv: {
- remain: ['npm', 'team', 'missing-subcommand'],
- },
- },
- }, (err, res) => {
- t.match(
- err,
- /missing-subcommand not recognized/,
- 'should throw a a not recognized error'
- )
+ t.test('npm team unknown subcommand autocomplete', async t => {
+ t.rejects(completion({conf: {argv: {remain: ['npm', 'team', 'missing-subcommand'] } } }),
+ {message: 'missing-subcommand not recognized'}, 'should throw a a not recognized error'
+ )
- t.end()
- })
+ t.end()
})
t.end()
diff --git a/deps/npm/test/lib/token.js b/deps/npm/test/lib/token.js
index f988810722..6ab841f499 100644
--- a/deps/npm/test/lib/token.js
+++ b/deps/npm/test/lib/token.js
@@ -48,27 +48,18 @@ test('completion', (t) => {
t.plan(5)
const testComp = (argv, expect) => {
- tokenMock.completion({ conf: { argv: { remain: argv } } }, (err, res) => {
- if (err)
- throw err
-
- t.strictSame(res, expect, argv.join(' '))
- })
+ t.resolveMatch(tokenMock.completion({ conf: { argv: { remain: argv } } }), expect, argv.join(' '))
}
- testComp(['npm', 'token'], [
- 'list',
- 'revoke',
- 'create',
- ])
-
+ testComp(['npm', 'token'], ['list', 'revoke', 'create'])
testComp(['npm', 'token', 'list'], [])
testComp(['npm', 'token', 'revoke'], [])
testComp(['npm', 'token', 'create'], [])
- tokenMock.completion({ conf: { argv: { remain: ['npm', 'token', 'foobar'] } } }, (err) => {
- t.match(err, { message: 'foobar not recognized' })
- })
+ t.rejects(
+ tokenMock.completion({ conf: { argv: { remain: ['npm', 'token', 'foobar'] } } }),
+ { message: 'foobar not recognize' }
+ )
})
test('token foobar', (t) => {
diff --git a/deps/npm/test/lib/unpublish.js b/deps/npm/test/lib/unpublish.js
index 11e24714d8..c1fbed57eb 100644
--- a/deps/npm/test/lib/unpublish.js
+++ b/deps/npm/test/lib/unpublish.js
@@ -310,16 +310,12 @@ t.test('silent', t => {
})
})
-t.test('completion', t => {
- const testComp = (t, { completion, argv, partialWord, expect, title }) =>
- new Promise((resolve, rej) => {
- completion({conf: {argv: {remain: argv}}, partialWord}, (er, res) => {
- if (er)
- rej(er)
- t.strictSame(res, expect, title || argv.join(' '))
- resolve()
- })
- })
+t.test('completion', async t => {
+ const testComp =
+ async (t, { completion, argv, partialWord, expect, title }) => {
+ const res = await completion({conf: {argv: {remain: argv}}, partialWord})
+ t.strictSame(res, expect, title || argv.join(' '))
+ }
t.test('completing with multiple versions from the registry', async t => {
const { completion } = requireInject('../../lib/unpublish.js', {
diff --git a/deps/npm/test/lib/utils/completion/installed-deep.js b/deps/npm/test/lib/utils/completion/installed-deep.js
index a2a3756104..bd61ab4280 100644
--- a/deps/npm/test/lib/utils/completion/installed-deep.js
+++ b/deps/npm/test/lib/utils/completion/installed-deep.js
@@ -11,7 +11,8 @@ const _flatOptions = {
return prefix
},
}
-const installedDeep = requireInject('../../../../lib/utils/completion/installed-deep.js', {
+const p = '../../../../lib/utils/completion/installed-deep.js'
+const installedDeep = requireInject(p, {
'../../../../lib/npm.js': {
flatOptions: _flatOptions,
get prefix () {
@@ -144,7 +145,7 @@ const globalFixture = {
},
}
-test('get list of package names', (t) => {
+test('get list of package names', async t => {
const fix = t.testdir({
local: fixture,
global: globalFixture,
@@ -153,25 +154,23 @@ test('get list of package names', (t) => {
prefix = resolve(fix, 'local')
globalDir = resolve(fix, 'global/node_modules')
- installedDeep(null, (err, res) => {
- t.ifError(err, 'should not error out')
- t.deepEqual(
- res,
- [
- ['bar', '-g'],
- ['foo', '-g'],
- ['a-bar', '-g'],
- 'a', 'b', 'c',
- 'd', 'e', 'f',
- 'g', 'bb',
- ],
- 'should return list of package names and global flag'
- )
- t.end()
- })
+ const res = await installedDeep(null)
+ t.deepEqual(
+ res,
+ [
+ ['bar', '-g'],
+ ['foo', '-g'],
+ ['a-bar', '-g'],
+ 'a', 'b', 'c',
+ 'd', 'e', 'f',
+ 'g', 'bb',
+ ],
+ 'should return list of package names and global flag'
+ )
+ t.end()
})
-test('get list of package names as global', (t) => {
+test('get list of package names as global', async t => {
const fix = t.testdir({
local: fixture,
global: globalFixture,
@@ -182,23 +181,21 @@ test('get list of package names as global', (t) => {
_flatOptions.global = true
- installedDeep(null, (err, res) => {
- t.ifError(err, 'should not error out')
- t.deepEqual(
- res,
- [
- 'bar',
- 'foo',
- 'a-bar',
- ],
- 'should return list of global packages with no extra flags'
- )
- _flatOptions.global = false
- t.end()
- })
+ const res = await installedDeep(null)
+ t.deepEqual(
+ res,
+ [
+ 'bar',
+ 'foo',
+ 'a-bar',
+ ],
+ 'should return list of global packages with no extra flags'
+ )
+ _flatOptions.global = false
+ t.end()
})
-test('limit depth', (t) => {
+test('limit depth', async t => {
const fix = t.testdir({
local: fixture,
global: globalFixture,
@@ -209,26 +206,24 @@ test('limit depth', (t) => {
_flatOptions.depth = 0
- installedDeep(null, (err, res) => {
- t.ifError(err, 'should not error out')
- t.deepEqual(
- res,
- [
- ['bar', '-g'],
- ['foo', '-g'],
- 'a', 'b',
- 'c', 'd',
- 'e', 'f',
- 'g',
- ],
- 'should print only packages up to the specified depth'
- )
- _flatOptions.depth = 0
- t.end()
- })
+ const res = await installedDeep(null)
+ t.deepEqual(
+ res,
+ [
+ ['bar', '-g'],
+ ['foo', '-g'],
+ 'a', 'b',
+ 'c', 'd',
+ 'e', 'f',
+ 'g',
+ ],
+ 'should print only packages up to the specified depth'
+ )
+ _flatOptions.depth = 0
+ t.end()
})
-test('limit depth as global', (t) => {
+test('limit depth as global', async t => {
const fix = t.testdir({
local: fixture,
global: globalFixture,
@@ -240,18 +235,16 @@ test('limit depth as global', (t) => {
_flatOptions.global = true
_flatOptions.depth = 0
- installedDeep(null, (err, res) => {
- t.ifError(err, 'should not error out')
- t.deepEqual(
- res,
- [
- 'bar',
- 'foo',
- ],
- 'should reorder so that packages above that level depth goes last'
- )
- _flatOptions.global = false
- _flatOptions.depth = 0
- t.end()
- })
+ const res = await installedDeep(null)
+ t.deepEqual(
+ res,
+ [
+ 'bar',
+ 'foo',
+ ],
+ 'should reorder so that packages above that level depth goes last'
+ )
+ _flatOptions.global = false
+ _flatOptions.depth = 0
+ t.end()
})
diff --git a/deps/npm/test/lib/utils/completion/installed-shallow.js b/deps/npm/test/lib/utils/completion/installed-shallow.js
index 1d6369bc78..1da68810b5 100644
--- a/deps/npm/test/lib/utils/completion/installed-shallow.js
+++ b/deps/npm/test/lib/utils/completion/installed-shallow.js
@@ -9,7 +9,7 @@ const installed = requireInject(p, {
'../../../../lib/npm.js': npm,
})
-t.test('global not set, include globals with -g', t => {
+t.test('global not set, include globals with -g', async t => {
const dir = t.testdir({
global: {
node_modules: {
@@ -32,21 +32,17 @@ t.test('global not set, include globals with -g', t => {
npm.localDir = resolve(dir, 'local/node_modules')
flatOptions.global = false
const opt = { conf: { argv: { remain: [] } } }
- installed(opt, (er, res) => {
- if (er)
- throw er
-
- t.strictSame(res.sort(), [
- '@scope/y -g',
- 'x -g',
- 'a',
- '@scope/b',
- ].sort())
- t.end()
- })
+ const res = await installed(opt)
+ t.strictSame(res.sort(), [
+ '@scope/y -g',
+ 'x -g',
+ 'a',
+ '@scope/b',
+ ].sort())
+ t.end()
})
-t.test('global set, include globals and not locals', t => {
+t.test('global set, include globals and not locals', async t => {
const dir = t.testdir({
global: {
node_modules: {
@@ -69,16 +65,15 @@ t.test('global set, include globals and not locals', t => {
npm.localDir = resolve(dir, 'local/node_modules')
flatOptions.global = true
const opt = { conf: { argv: { remain: [] } } }
- installed(opt, (er, res) => {
- t.strictSame(res.sort(), [
- '@scope/y',
- 'x',
- ].sort())
- t.end()
- })
+ const res = await installed(opt)
+ t.strictSame(res.sort(), [
+ '@scope/y',
+ 'x',
+ ].sort())
+ t.end()
})
-t.test('more than 3 items in argv, skip it', t => {
+t.test('more than 3 items in argv, skip it', async t => {
const dir = t.testdir({
global: {
node_modules: {
@@ -101,11 +96,7 @@ t.test('more than 3 items in argv, skip it', t => {
npm.localDir = resolve(dir, 'local/node_modules')
flatOptions.global = false
const opt = { conf: { argv: { remain: [1, 2, 3, 4, 5, 6] } } }
- installed(opt, (er, res) => {
- if (er)
- throw er
-
- t.strictSame(res, null)
- t.end()
- })
+ const res = await installed(opt)
+ t.strictSame(res, null)
+ t.end()
})
diff --git a/deps/npm/test/lib/utils/completion/none.js b/deps/npm/test/lib/utils/completion/none.js
deleted file mode 100644
index 70488be07e..0000000000
--- a/deps/npm/test/lib/utils/completion/none.js
+++ /dev/null
@@ -1,6 +0,0 @@
-const t = require('tap')
-const none = require('../../../../lib/utils/completion/none.js')
-none({any: 'thing'}, (er, res) => {
- t.equal(er, null)
- t.strictSame(res, [])
-})
diff --git a/deps/npm/test/lib/utils/explain-dep.js b/deps/npm/test/lib/utils/explain-dep.js
index 28f14477ab..1b8c4ae380 100644
--- a/deps/npm/test/lib/utils/explain-dep.js
+++ b/deps/npm/test/lib/utils/explain-dep.js
@@ -97,6 +97,23 @@ const cases = {
],
},
+ bundled: {
+ name: 'bundle-of-joy',
+ version: '1.0.0',
+ location: 'node_modules/bundle-of-joy',
+ bundled: true,
+ dependents: [
+ {
+ type: 'prod',
+ name: 'prod-dep',
+ spec: '1.x',
+ from: {
+ location: '/path/to/project',
+ },
+ },
+ ],
+ },
+
extraneous: {
name: 'extra-neos',
version: '1337.420.69-lol',
diff --git a/deps/npm/test/lib/utils/lifecycle-cmd.js b/deps/npm/test/lib/utils/lifecycle-cmd.js
index 9e45b15e40..3928c1b26e 100644
--- a/deps/npm/test/lib/utils/lifecycle-cmd.js
+++ b/deps/npm/test/lib/utils/lifecycle-cmd.js
@@ -7,7 +7,6 @@ const npm = {
}
t.test('create a lifecycle command', t => {
const cmd = lifecycleCmd(npm, 'asdf')
- t.equal(cmd.completion, require('../../../lib/utils/completion/none.js'), 'empty completion')
cmd(['some', 'args'], (er, result) => {
t.strictSame(result, 'called npm.commands.run')
t.end()
diff --git a/deps/npm/test/lib/version.js b/deps/npm/test/lib/version.js
index 943e143702..a69953bb8a 100644
--- a/deps/npm/test/lib/version.js
+++ b/deps/npm/test/lib/version.js
@@ -73,17 +73,15 @@ t.test('too many args', t => {
})
})
-t.test('completion', t => {
+t.test('completion', async t => {
const { completion } = version
- const testComp = (argv, expect) => {
- completion({ conf: { argv: { remain: argv } } }, (err, res) => {
- t.ifError(err)
- t.strictSame(res, expect, argv.join(' '))
- })
+ const testComp = async (argv, expect) => {
+ const res = await completion({ conf: { argv: { remain: argv } } })
+ t.strictSame(res, expect, argv.join(' '))
}
- testComp(['npm', 'version'], [
+ await testComp(['npm', 'version'], [
'major',
'minor',
'patch',
@@ -93,7 +91,7 @@ t.test('completion', t => {
'prerelease',
'from-git',
])
- testComp(['npm', 'version', 'major'], [])
+ await testComp(['npm', 'version', 'major'], [])
t.end()
})
diff --git a/deps/npm/test/lib/view.js b/deps/npm/test/lib/view.js
index f3e5d97f33..9419ab7ec8 100644
--- a/deps/npm/test/lib/view.js
+++ b/deps/npm/test/lib/view.js
@@ -553,7 +553,7 @@ t.test('throws when unpublished', (t) => {
})
})
-t.test('completion', (t) => {
+t.test('completion', async t => {
const view = requireInject('../../lib/view.js', {
'../../lib/npm.js': {
flatOptions: {
@@ -565,17 +565,14 @@ t.test('completion', (t) => {
packument,
},
})
- view.completion({
+ const res = await view.completion({
conf: { argv: { remain: ['npm', 'view', 'green@1.0.0'] } },
- }, (err, res) => {
- if (err)
- throw err
- t.ok(res, 'returns back fields')
- t.end()
})
+ t.ok(res, 'returns back fields')
+ t.end()
})
-t.test('no registry completion', (t) => {
+t.test('no registry completion', async t => {
const view = requireInject('../../lib/view.js', {
'../../lib/npm.js': {
flatOptions: {
@@ -583,10 +580,7 @@ t.test('no registry completion', (t) => {
},
},
})
- view.completion({
- conf: { argv: { remain: ['npm', 'view'] } },
- }, (err) => {
- t.notOk(err, 'there is no package completion')
- t.end()
- })
+ const res = await view.completion({conf: { argv: { remain: ['npm', 'view'] } } })
+ t.notOk(res, 'there is no package completion')
+ t.end()
})