nodejs/deps/npm/test/lib/commands/install-ci-test.js
npm CLI robot 3bef54918b
deps: upgrade npm to 9.1.3
PR-URL: https://github.com/nodejs/node/pull/45693
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruy Adorno <ruyadorno@google.com>
2022-12-07 03:18:33 +00:00

66 lines
1.2 KiB
JavaScript

const t = require('tap')
const InstallCITest = require('../../../lib/commands/install-ci-test.js')
let ciArgs = null
let ciCalled = false
let testArgs = null
let testCalled = false
let ciError = null
const installCITest = new InstallCITest({
exec: (cmd, args) => {
if (cmd === 'ci') {
ciArgs = args
ciCalled = true
}
if (ciError) {
throw ciError
}
if (cmd === 'test') {
testArgs = args
testCalled = true
}
},
config: {
validate: () => {},
get: (key) => {
if (key === 'location') {
return 'project'
}
},
isDefault: () => {},
},
})
t.test('the install-ci-test command', t => {
t.afterEach(() => {
ciArgs = null
ciCalled = false
testArgs = null
testCalled = false
ciError = null
})
t.test('ci and test', async t => {
await installCITest.exec(['extra'])
t.equal(ciCalled, true)
t.equal(testCalled, true)
t.match(ciArgs, ['extra'])
t.match(testArgs, [])
})
t.test('ci fails', async t => {
ciError = new Error('test fail')
await t.rejects(
installCITest.exec(['extra']),
'test fail'
)
t.equal(ciCalled, true)
t.equal(testCalled, false)
t.match(ciArgs, ['extra'])
})
t.end()
})