/* 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)
    })
  })
})

@@ -481,21 +481,23 @@
 rm js', 
-(done
+async (
 ) =%3E %7B%0A 
@@ -503,33 +503,40 @@
       const 
+%5B
 result
-s
+%5D
  =
+ await
  build(%7B%0A   
@@ -613,48 +613,29 @@
     
-results%5B0%5D%0A        .then((buf) =%3E %7B%0A    
+console.log(result)%0A%0A
     
@@ -647,11 +647,14 @@
 ect(
-buf
+result
 .toS
@@ -705,72 +705,19 @@
 ')).
-to.
 not.
-equal(-1)%0A          done()%0A        %7D)%0A        .catch(done
+toBe(-1
 )%0A  
@@ -775,33 +775,40 @@
       const 
+%5B
 result
-s
+%5D
  =
+ await
  build(%7B%0A   
@@ -880,46 +880,8 @@
 %7D)%0A%0A
-      const result = await results%5B0%5D%0A
     
@@ -1085,17 +1085,22 @@
 nst 
-results =
+output = await
  bui
@@ -1270,16 +1270,16 @@
 y: true%0A
+
       %7D)
@@ -1284,57 +1284,8 @@
 %7D)%0A%0A
-      const output = await Promise.all(results)%0A%0A
     

Update build tests to use new api