1const t = require('tap') 2const mockNpm = require('../fixtures/mock-npm') 3const LifecycleCmd = require('../../lib/lifecycle-cmd.js') 4 5t.test('create a lifecycle command', async t => { 6 let runArgs = null 7 const { npm } = await mockNpm(t) 8 npm.exec = async (cmd, args) => { 9 if (cmd === 'run-script') { 10 runArgs = args 11 return 'called the right thing' 12 } 13 } 14 15 class TestStage extends LifecycleCmd { 16 static get name () { 17 return 'test-stage' 18 } 19 } 20 21 const cmd = new TestStage(npm) 22 t.match(cmd.usage, /test-stage/) 23 24 let result 25 result = await cmd.exec(['some', 'args']) 26 t.same(runArgs, ['test-stage', 'some', 'args']) 27 t.strictSame(result, 'called the right thing') 28 29 result = await cmd.execWorkspaces(['some', 'args']) 30 t.same(runArgs, ['test-stage', 'some', 'args']) 31 t.strictSame(result, 'called the right thing') 32}) 33