node/deps/npm/test/lib/commands/install-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

65 lines
1.3 KiB
JavaScript

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