• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1const t = require('tap')
2
3const InstallCITest = require('../../../lib/commands/install-ci-test.js')
4
5let ciArgs = null
6let ciCalled = false
7let testArgs = null
8let testCalled = false
9let ciError = null
10
11const installCITest = new InstallCITest({
12  exec: (cmd, args) => {
13    if (cmd === 'ci') {
14      ciArgs = args
15      ciCalled = true
16    }
17    if (ciError) {
18      throw ciError
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-ci-test command', t => {
38  t.afterEach(() => {
39    ciArgs = null
40    ciCalled = false
41    testArgs = null
42    testCalled = false
43    ciError = null
44  })
45
46  t.test('ci and test', async t => {
47    await installCITest.exec(['extra'])
48    t.equal(ciCalled, true)
49    t.equal(testCalled, true)
50    t.match(ciArgs, ['extra'])
51    t.match(testArgs, [])
52  })
53
54  t.test('ci fails', async t => {
55    ciError = new Error('test fail')
56    await t.rejects(
57      installCITest.exec(['extra']),
58      'test fail'
59    )
60    t.equal(ciCalled, true)
61    t.equal(testCalled, false)
62    t.match(ciArgs, ['extra'])
63  })
64  t.end()
65})
66