11cb0ef41Sopenharmony_ciconst t = require('tap')
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst InstallCITest = require('../../../lib/commands/install-ci-test.js')
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_cilet ciArgs = null
61cb0ef41Sopenharmony_cilet ciCalled = false
71cb0ef41Sopenharmony_cilet testArgs = null
81cb0ef41Sopenharmony_cilet testCalled = false
91cb0ef41Sopenharmony_cilet ciError = null
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst installCITest = new InstallCITest({
121cb0ef41Sopenharmony_ci  exec: (cmd, args) => {
131cb0ef41Sopenharmony_ci    if (cmd === 'ci') {
141cb0ef41Sopenharmony_ci      ciArgs = args
151cb0ef41Sopenharmony_ci      ciCalled = true
161cb0ef41Sopenharmony_ci    }
171cb0ef41Sopenharmony_ci    if (ciError) {
181cb0ef41Sopenharmony_ci      throw ciError
191cb0ef41Sopenharmony_ci    }
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci    if (cmd === 'test') {
221cb0ef41Sopenharmony_ci      testArgs = args
231cb0ef41Sopenharmony_ci      testCalled = true
241cb0ef41Sopenharmony_ci    }
251cb0ef41Sopenharmony_ci  },
261cb0ef41Sopenharmony_ci  config: {
271cb0ef41Sopenharmony_ci    validate: () => {},
281cb0ef41Sopenharmony_ci    get: (key) => {
291cb0ef41Sopenharmony_ci      if (key === 'location') {
301cb0ef41Sopenharmony_ci        return 'project'
311cb0ef41Sopenharmony_ci      }
321cb0ef41Sopenharmony_ci    },
331cb0ef41Sopenharmony_ci    isDefault: () => {},
341cb0ef41Sopenharmony_ci  },
351cb0ef41Sopenharmony_ci})
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_cit.test('the install-ci-test command', t => {
381cb0ef41Sopenharmony_ci  t.afterEach(() => {
391cb0ef41Sopenharmony_ci    ciArgs = null
401cb0ef41Sopenharmony_ci    ciCalled = false
411cb0ef41Sopenharmony_ci    testArgs = null
421cb0ef41Sopenharmony_ci    testCalled = false
431cb0ef41Sopenharmony_ci    ciError = null
441cb0ef41Sopenharmony_ci  })
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ci  t.test('ci and test', async t => {
471cb0ef41Sopenharmony_ci    await installCITest.exec(['extra'])
481cb0ef41Sopenharmony_ci    t.equal(ciCalled, true)
491cb0ef41Sopenharmony_ci    t.equal(testCalled, true)
501cb0ef41Sopenharmony_ci    t.match(ciArgs, ['extra'])
511cb0ef41Sopenharmony_ci    t.match(testArgs, [])
521cb0ef41Sopenharmony_ci  })
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_ci  t.test('ci fails', async t => {
551cb0ef41Sopenharmony_ci    ciError = new Error('test fail')
561cb0ef41Sopenharmony_ci    await t.rejects(
571cb0ef41Sopenharmony_ci      installCITest.exec(['extra']),
581cb0ef41Sopenharmony_ci      'test fail'
591cb0ef41Sopenharmony_ci    )
601cb0ef41Sopenharmony_ci    t.equal(ciCalled, true)
611cb0ef41Sopenharmony_ci    t.equal(testCalled, false)
621cb0ef41Sopenharmony_ci    t.match(ciArgs, ['extra'])
631cb0ef41Sopenharmony_ci  })
641cb0ef41Sopenharmony_ci  t.end()
651cb0ef41Sopenharmony_ci})
66