summaryrefslogtreecommitdiff
path: root/deps/npm/test/lib/load-all-commands.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/test/lib/load-all-commands.js')
-rw-r--r--deps/npm/test/lib/load-all-commands.js54
1 files changed, 32 insertions, 22 deletions
diff --git a/deps/npm/test/lib/load-all-commands.js b/deps/npm/test/lib/load-all-commands.js
index e31a2b9936..d7eb2eae0a 100644
--- a/deps/npm/test/lib/load-all-commands.js
+++ b/deps/npm/test/lib/load-all-commands.js
@@ -1,27 +1,37 @@
-// Thanks to nyc not working properly with proxies this
-// doesn't affect coverage. but it does ensure that every command has a usage
-// that contains its name, and if it has completion it is a function
-const npm = require('../../lib/npm.js')
+// Thanks to nyc not working properly with proxies this doesn't affect
+// coverage. but it does ensure that every command has a usage that renders,
+// contains its name, a description, and if it has completion it is a function.
+// That it renders also ensures that any params we've defined in our commands
+// work.
+const requireInject = require('require-inject')
+const npm = requireInject('../../lib/npm.js')
const t = require('tap')
const { cmdList } = require('../../lib/utils/cmd-list.js')
-t.test('load npm', t => npm.load(er => {
- if (er)
- throw er
-}))
-
+let npmOutput = []
+npm.output = (msg) => {
+ npmOutput = msg
+}
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 => {
- 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.match(impl.usage, cmd, 'usage contains the command')
- })
- }
+ t.plan(cmdList.length + 1)
+ npm.load((er) => {
+ t.notOk(er)
+ npm.config.set('usage', true)
+ for (const cmd of cmdList.sort((a, b) => a.localeCompare(b))) {
+ t.test(cmd, t => {
+ const impl = npm.commands[cmd]
+ if (impl.completion)
+ t.isa(impl.completion, 'function', 'completion, if present, is a function')
+ t.isa(impl, 'function', 'implementation is a function')
+ t.ok(impl.description, 'implementation has a description')
+ t.ok(impl.name, 'implementation has a name')
+ t.match(impl.usage, cmd, 'usage contains the command')
+ impl([], (err) => {
+ t.notOk(err)
+ t.match(npmOutput, impl.usage, 'usage is output')
+ t.end()
+ })
+ })
+ }
+ })
})