/* global describe it beforeEach */
'use strict'

const chai = require('chai')
const chaiAsPromised = require('chai-as-promised')
const requireInject = require('require-inject')
const sinon = require('sinon')
const sinonChai = require('sinon-chai')
require('sinon-as-promised')

chai.use(chaiAsPromised)
chai.use(sinonChai)

const expect = chai.expect

describe('travis.parse', function () {
  let stubs
  let logger
  let util

  beforeEach(function () {
    stubs = {
      path: {
        join: sinon.stub().returns('<travis-file>')
      }
    }
    logger = {
      error: sinon.spy()
    }
    stubs[require.resolve('../lib/logging')] = {logger}

    util = {}
    stubs[require.resolve('../lib/util')] = util
  })

  it('rejects if file is not found', function () {
    util.exists = sinon.stub().rejects()

    const parse = requireInject('../lib/travis', stubs)
    return expect(parse()).to.be.eventually.rejected.then(function () {
      expect(logger.error).to.have.been.calledWith(
        'Travis file not found: %s', '<travis-file>')
    })
  })

  it('rejects if language field is not found', function () {
    util.exists = sinon.stub().resolves()
    util.readFile = sinon.stub().resolves('value: 42')

    const parse = requireInject('../lib/travis', stubs)
    return expect(parse()).to.be.eventually.rejected.then(function () {
      expect(logger.error).to.have.been.calledWith(
        'language field not found in travis configuration')
    })
  })

  it('rejects if language field is not nodejs', function () {
    util.exists = sinon.stub().resolves()
    util.readFile = sinon.stub().resolves('language: some-other-language')

    const parse = requireInject('../lib/travis', stubs)
    return expect(parse()).to.be.eventually.rejected.then(function () {
      expect(logger.error).to.have.been.calledWith(
        'Unexpected language in travis configuration: %s',
        'some-other-language'
      )
    })
  })
})

@@ -1510,16 +1510,17 @@
 not node
+_
 js', fun
@@ -1936,12 +1936,430 @@
  %7D)%0A  %7D)
+%0A%0A  it('rejects if node_js field is not found', function () %7B%0A    util.exists = sinon.stub().resolves()%0A    util.readFile = sinon.stub().resolves('language: node_js')%0A%0A    const parse = requireInject('../lib/travis', stubs)%0A    return expect(parse()).to.be.eventually.rejected.then(function () %7B%0A      expect(logger.error).to.have.been.calledWith(%0A        'node_js field not found in travis configuration')%0A    %7D)%0A  %7D)
 %0A%7D)%0A

Add node_js field not found test case