2021-04-01 17:27:18 -04:00
|
|
|
// Our coverage mapping means that stuff like this doen't count for coverage.
|
|
|
|
// 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.
|
2020-10-02 17:52:19 -04:00
|
|
|
const t = require('tap')
|
2021-11-04 20:42:47 +00:00
|
|
|
const util = require('util')
|
2021-12-02 22:04:46 +00:00
|
|
|
const { load: loadMockNpm } = require('../fixtures/mock-npm.js')
|
2022-11-07 13:02:05 -05:00
|
|
|
const { allCommands } = require('../../lib/utils/cmd-list.js')
|
2020-10-02 17:52:19 -04:00
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
t.test('load each command', async t => {
|
2022-11-07 13:02:05 -05:00
|
|
|
for (const cmd of allCommands) {
|
2021-11-04 20:42:47 +00:00
|
|
|
t.test(cmd, async t => {
|
2021-12-02 22:04:46 +00:00
|
|
|
const { npm, outputs } = await loadMockNpm(t, {
|
|
|
|
config: { usage: true },
|
|
|
|
})
|
2021-11-04 20:42:47 +00:00
|
|
|
const impl = await npm.cmd(cmd)
|
2021-11-18 20:58:02 +00:00
|
|
|
if (impl.completion) {
|
2021-11-04 20:42:47 +00:00
|
|
|
t.type(impl.completion, 'function', 'completion, if present, is a function')
|
2021-11-18 20:58:02 +00:00
|
|
|
}
|
2021-11-04 20:42:47 +00:00
|
|
|
t.type(impl.exec, 'function', 'implementation has an exec function')
|
|
|
|
t.type(impl.execWorkspaces, 'function', 'implementation has an execWorkspaces function')
|
|
|
|
t.equal(util.inspect(impl.exec), '[AsyncFunction: exec]', 'exec function is async')
|
2021-11-18 20:58:02 +00:00
|
|
|
t.equal(
|
|
|
|
util.inspect(impl.execWorkspaces),
|
|
|
|
'[AsyncFunction: execWorkspaces]',
|
|
|
|
'execWorkspaces function is async'
|
|
|
|
)
|
2021-11-04 20:42:47 +00:00
|
|
|
t.ok(impl.description, 'implementation has a description')
|
|
|
|
t.ok(impl.name, 'implementation has a name')
|
2022-03-03 21:38:08 +00:00
|
|
|
t.ok(impl.ignoreImplicitWorkspace !== undefined, 'implementation has ignoreImplictWorkspace')
|
2021-11-04 20:42:47 +00:00
|
|
|
t.match(impl.usage, cmd, 'usage contains the command')
|
|
|
|
await npm.exec(cmd, [])
|
|
|
|
t.match(outputs[0][0], impl.usage, 'usage is what is output')
|
|
|
|
})
|
|
|
|
}
|
2020-10-02 17:52:19 -04:00
|
|
|
})
|