2021-11-04 20:42:47 +00:00
|
|
|
const t = require('tap')
|
2023-01-16 22:38:23 -05:00
|
|
|
const mockNpm = require('../fixtures/mock-npm')
|
2021-11-04 20:42:47 +00:00
|
|
|
const LifecycleCmd = require('../../lib/lifecycle-cmd.js')
|
2023-01-16 22:38:23 -05:00
|
|
|
|
|
|
|
t.test('create a lifecycle command', async t => {
|
|
|
|
let runArgs = null
|
|
|
|
const { npm } = await mockNpm(t)
|
|
|
|
npm.exec = async (cmd, args) => {
|
2021-11-04 20:42:47 +00:00
|
|
|
if (cmd === 'run-script') {
|
|
|
|
runArgs = args
|
|
|
|
return 'called the right thing'
|
|
|
|
}
|
2023-01-16 22:38:23 -05:00
|
|
|
}
|
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
class TestStage extends LifecycleCmd {
|
|
|
|
static get name () {
|
|
|
|
return 'test-stage'
|
|
|
|
}
|
|
|
|
}
|
2023-01-16 22:38:23 -05:00
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
const cmd = new TestStage(npm)
|
|
|
|
t.match(cmd.usage, /test-stage/)
|
2023-01-16 22:38:23 -05:00
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
let result
|
|
|
|
result = await cmd.exec(['some', 'args'])
|
|
|
|
t.same(runArgs, ['test-stage', 'some', 'args'])
|
|
|
|
t.strictSame(result, 'called the right thing')
|
2023-01-16 22:38:23 -05:00
|
|
|
|
|
|
|
result = await cmd.execWorkspaces(['some', 'args'])
|
2021-11-04 20:42:47 +00:00
|
|
|
t.same(runArgs, ['test-stage', 'some', 'args'])
|
|
|
|
t.strictSame(result, 'called the right thing')
|
|
|
|
})
|