/* globals afterEach, beforeEach, describe, it, expect, jasmine */

const build = require('../../lib/build')
const util = require('../test-utils/util.js')

const originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL

describe('build', () => {
  const mockDir = util.mockDir

  beforeEach(() => {
    jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000
  })
  afterEach(() => {
    jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout
  })

  describe('development', () => {
    it('should transform js', (done) => {
      const results = build({
        config: {},
        files: [[`${mockDir}/index.js`]]
      })

      results[0]
        .then((buf) => {
          expect(buf.toString().indexOf('MockTestComponentUniqueName')).to.not.equal(-1)
          done()
        })
        .catch(done)
    })

    it('should transform css', async () => {
      const results = build({
        config: {},
        files: [[`${mockDir}/index.css`]]
      })

      const result = await results[0]
      const css = result.css
      expect(css.indexOf('criticalClass')).toBeGreaterThan(-1)
    })
  })

  describe('production', () => {
    it('should transform and minify js', async () => {
      const results = build({
        config: {},
        env: 'production',
        files: [
          [`${mockDir}/index.js`],
          [`${mockDir}/index.css`]
        ],
        minify: true
      })

      const output = await Promise.all(results)

      expect(output[0].toString().indexOf('MockTestComponentUniqueName')).not.toBe(-1)
      expect(output[1].css.indexOf('criticalClass')).not.toBe(-1)
    })
  })
})

/* globals afterEach, beforeEach, describe, it, expect, jasmine */

const build = require('../../lib/build')
const util = require('../test-utils/util.js')

const originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL

describe('build', () => {
  const mockDir = util.mockDir

  beforeEach(() => {
    jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000
  })
  afterEach(() => {
    jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout
  })

  describe('development', () => {
    it('should transform js', async () => {
      const [result] = await build({
        config: {},
        files: [[`${mockDir}/index.js`]]
      })

      console.log(result)

      expect(result.toString().indexOf('MockTestComponentUniqueName')).not.toBe(-1)
    })

    it('should transform css', async () => {
      const [result] = await build({
        config: {},
        files: [[`${mockDir}/index.css`]]
      })

      const css = result.css
      expect(css.indexOf('criticalClass')).toBeGreaterThan(-1)
    })
  })

  describe('production', () => {
    it('should transform and minify js', async () => {
      const output = await build({
        config: {},
        env: 'production',
        files: [
          [`${mockDir}/index.js`],
          [`${mockDir}/index.css`]
        ],
        minify: true
      })

      expect(output[0].toString().indexOf('MockTestComponentUniqueName')).not.toBe(-1)
      expect(output[1].css.indexOf('criticalClass')).not.toBe(-1)
    })
  })
})

Update build tests to use new api