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')
|
2023-03-31 06:38:48 -07:00
|
|
|
const { commands } = require('../../lib/utils/cmd-list.js')
|
2020-10-02 17:52:19 -04:00
|
|
|
|
2023-01-16 22:38:23 -05:00
|
|
|
const isAsyncFn = (v) => typeof v === 'function' && /^\[AsyncFunction:/.test(util.inspect(v))
|
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
t.test('load each command', async t => {
|
2023-03-31 06:38:48 -07:00
|
|
|
for (const cmd of commands) {
|
2021-11-04 20:42:47 +00:00
|
|
|
t.test(cmd, async t => {
|
2023-01-16 22:38:23 -05:00
|
|
|
const { npm, outputs, cmd: impl } = await loadMockNpm(t, {
|
|
|
|
command: cmd,
|
2021-12-02 22:04:46 +00:00
|
|
|
config: { usage: true },
|
|
|
|
})
|
2023-01-16 22:38:23 -05:00
|
|
|
const ctor = impl.constructor
|
|
|
|
|
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
|
|
|
}
|
2023-01-16 22:38:23 -05:00
|
|
|
|
|
|
|
// exec fn
|
|
|
|
t.ok(isAsyncFn(impl.exec), 'exec is async')
|
|
|
|
t.ok(impl.exec.length <= 1, 'exec fn has 0 or 1 args')
|
|
|
|
|
|
|
|
// workspaces
|
|
|
|
t.type(ctor.ignoreImplicitWorkspace, 'boolean', 'ctor has ignoreImplictWorkspace boolean')
|
|
|
|
t.type(ctor.workspaces, 'boolean', 'ctor has workspaces boolean')
|
|
|
|
if (ctor.workspaces) {
|
|
|
|
t.ok(isAsyncFn(impl.execWorkspaces), 'execWorkspaces is async')
|
|
|
|
t.ok(impl.exec.length <= 1, 'execWorkspaces fn has 0 or 1 args')
|
|
|
|
} else {
|
|
|
|
t.notOk(impl.execWorkspaces, 'has no execWorkspaces fn')
|
|
|
|
}
|
|
|
|
|
|
|
|
// name/desc
|
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-12-06 22:18:33 -05:00
|
|
|
t.equal(cmd, impl.name, 'command list and name are the same')
|
2023-01-16 22:38:23 -05:00
|
|
|
|
|
|
|
// usage
|
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
|
|
|
})
|