• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1const t = require('tap')
2
3const InstallTest = require('../../../lib/commands/install-test.js')
4
5let installArgs = null
6let installCalled = false
7let testArgs = null
8let testCalled = false
9let installError = null
10
11const installTest = new InstallTest({
12  exec: (cmd, args) => {
13    if (cmd === 'install') {
14      installArgs = args
15      installCalled = true
16    }
17    if (installError) {
18      throw installError
19    }
20
21    if (cmd === 'test') {
22      testArgs = args
23      testCalled = true
24    }
25  },
26  config: {
27    validate: () => {},
28    get: (key) => {
29      if (key === 'location') {
30        return 'project'
31      }
32    },
33    isDefault: () => {},
34  },
35})
36
37t.test('the install-test command', t => {
38  t.afterEach(() => {
39    installArgs = null
40    installCalled = false
41    testArgs = null
42    testCalled = false
43    installError = null
44  })
45
46  t.test('install and test', async t => {
47    await installTest.exec(['extra'])
48    t.equal(installCalled, true)
49    t.equal(testCalled, true)
50    t.match(installArgs, ['extra'])
51    t.match(testArgs, [])
52  })
53
54  t.test('install fails', async t => {
55    installError = new Error('test fail')
56    await t.rejects(
57      installTest.exec(['extra']),
58      'test fail'
59    )
60    t.equal(installCalled, true)
61    t.equal(testCalled, false)
62    t.match(installArgs, ['extra'])
63  })
64  t.end()
65})
66