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

const exec = require('child_process').exec
const fs = require('fs')
const path = require('path')

const rimraf = require('rimraf')

const mastarm = path.resolve('./bin/mastarm')

describe('mastarm cli', () => {
  it('should display usage with no args', (done) => {
    exec(`node ${mastarm} --help`, (err, stdout, stderr) => {
      expect(err).toBeNull()
      expect(stdout).toContain('Usage: mastarm [options] [command]')
      expect(stderr).toBe('')
      done()
    })
  })

  describe('build', function () {
    const clean = (done) => {
      rimraf('tests/mocks/built.*', done)
    }

    beforeEach(clean)
    afterEach(clean)

    it('should build a project', (done) => {
      exec(`node ${mastarm} build tests/mocks/mockComponent.js:tests/mocks/built.js tests/mocks/mock.css:tests/mocks/built.css`,
        (err, stdout, stderr) => {
          expect(err).toBeNull()
          expect(stdout).toBe('')
          expect(stderr).toBe('')
          const expectedBuiltFiles = ['tests/mocks/built.js', 'tests/mocks/built.css']
          expectedBuiltFiles.forEach((file) => {
            expect(fs.existsSync(file)).toBeTruthy()
          })
          done()
        }
      )
    })
  })

  it('should run lint on a project', (done) => {
    exec(`node ${mastarm} lint`, (err, stdout, stderr) => {
      expect(err).toBeNull()
      expect(stdout).toBe('')
      expect(stderr).toBe('')
      done()
    })
  })
})

@@ -1014,136 +1014,67 @@
     
-const expectedBuiltFiles = %5B'tests/mocks/built.js', 'tests/mocks/built.css'%5D%0A          expectedBuiltFiles.forEach((file) =%3E %7B%0A  
+expect(fs.existsSync('tests/mocks/built.js')).toBeTruthy()%0A
     
@@ -1104,12 +1104,31 @@
 ync(
-file
+'tests/mocks/built.css'
 )).t
@@ -1143,21 +1143,8 @@
 y()%0A
-          %7D)%0A
     

Refactor mastarm build test