diff options
author | Gar <gar+gh@danger.computer> | 2021-03-11 03:11:34 +0300 |
---|---|---|
committer | Ruy Adorno <ruyadorno@hotmail.com> | 2021-03-18 22:54:36 +0300 |
commit | 41facf6435ced4e416d74111d9c3ff00ee19ab7d (patch) | |
tree | 1a6644f756670ee6fad67a9a59d135dc0f3e00ef /test/lib/load-all-commands.js | |
parent | a8d0751e4b7c7d8b808c8a49f288fc7272f729b0 (diff) |
feat(help): refactor npm help/help-search
Lots of dead code removed thanks to streamlining of logic.
`npm help` `npm <command>` and `npm help-search` are all now separated
concerns, handling their own use cases. `help` calls `help-search` as a
last resort, but `npm <command>` no longer tries to wind its way through
to `help-search` just to get the basic npm usage displayed.
The `did you mean` output has been expanded. It now always suggests top
level commands, scripts, and bins, and suggests them in the way they
should be called.
PR-URL: https://github.com/npm/cli/pull/2859
Credit: @wraithgar
Close: #2859
Reviewed-by: @ruyadorno
Diffstat (limited to 'test/lib/load-all-commands.js')
-rw-r--r-- | test/lib/load-all-commands.js | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/test/lib/load-all-commands.js b/test/lib/load-all-commands.js index e31a2b993..2a2d41818 100644 --- a/test/lib/load-all-commands.js +++ b/test/lib/load-all-commands.js @@ -1,27 +1,35 @@ -// 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 contains +// its name, a description, and if it has completion it is a function +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() + }) + }) + } + }) }) |