var di = require('di')
var mocks = require('mocks')

describe('launcher', function () {
  var EventEmitter, IELauncher, injector, launcher, module

  beforeEach(function () {
    EventEmitter = require('../node_modules/karma/lib/events').EventEmitter
    IELauncher = mocks.loadFile(__dirname + '/../index').module.exports
    module = {
      baseBrowserDecorator: ['value', function () {}],
      emitter: ['value', new EventEmitter()],
      logger: [
        'value', {
          create: function () {
            return {
              error: function () {},
              debug: function () {}
            }
          }
        }
      ],
      args: ['value', []]
    }
  })

  afterEach(function () {
    injector = null
    launcher = null
  })

  describe('exports', function () {
    it('should export launcher:IE', function (done) {
      expect(IELauncher['launcher:IE']).to.defined
      done()
    })
  })

  describe('initialization', function () {
    beforeEach(function () {
      injector = new di.Injector([module, IELauncher])
      launcher = injector.get('launcher:IE')
    })

    it('should initialize name', function (done) {
      expect(launcher.name).to.equal('IE')
      done()
    })

    it('should initialize ENV_CMD', function (done) {
      expect(launcher.ENV_CMD).to.equal('IE_BIN')
      done()
    })

    it('should initialize DEFAULT_CMD.win32', function (done) {
      expect(launcher.DEFAULT_CMD.win32).to.beDefined
      done()
    })
  })

  describe('_getOptions', function () {
    var getOptions

    beforeEach(function () {
      getOptions = function (url, module) {
        injector = new di.Injector([module, IELauncher])
        launcher = injector.get('launcher:IE')
        return launcher._getOptions('url')
      }
    })

    it('should include args.flags', function (done) {
      var options
      module.args[1] = {
        flags: ['-flag1', '-flag2']
      }
      options = getOptions('url', module)
      expect(options[0]).to.equal('-flag1')
      expect(options[1]).to.equal('-flag2')
      done()
    })

    it('should return url as the last flag', function (done) {
      var options = getOptions('url', module)
      expect(options[options.length - 1]).to.equal('url')
      done()
    })
  })

  describe('locating iexplore.exe', function () {
    var fsMock, win32Location

    beforeEach(function () {
      process.env['PROGRAMW6432'] = '\\fake\\PROGRAMW6432'
      process.env['PROGRAMFILES(X86)'] = '\\fake\\PROGRAMFILES(X86)'
      process.env['PROGRAMFILES'] = '\\fake\\PROGRAMFILES'
      fsMock = mocks.fs.create({
        'folder1': {
          'Internet Explorer': {
            'iexplore.exe': 1
          }
        }
      })

      IELauncher = mocks.loadFile(__dirname + '/../index', {
        fs: fsMock
      }).module.exports

      win32Location = function () {
        injector = new di.Injector([module, IELauncher])
        launcher = injector.get('launcher:IE')
        return launcher._getInternetExplorerExe()
      }
    })

    it('should locate in PROGRAMW6432', function (done) {
      process.env['' + 'PROGRAMW6432'] = '\\folder1'
      expect(win32Location()).to.equal('\\folder1\\Internet Explorer\\iexplore.exe')
      done()
    })

    it('should locate in PROGRAMFILES(X86)', function (done) {
      process.env['' + 'PROGRAMFILES(X86)'] = '\\folder1'
      expect(win32Location()).to.equal('\\folder1\\Internet Explorer\\iexplore.exe')
      done()
    })

    it('should locate in PROGRAMFILES', function (done) {
      process.env['' + 'PROGRAMFILES'] = '\\folder1'
      expect(win32Location()).to.equal('\\folder1\\Internet Explorer\\iexplore.exe')
      done()
    })

    it('should return undefined when not found', function (done) {
      expect(win32Location()).to.equal(void 0)
      done()
    })
  })

  describe('_onProcessExit', function () {
    var child_processCmd, onProcessExit

    beforeEach(function () {
      onProcessExit = function () {
        var child_processMock
        child_processMock = {
          exec: function (cmd, cb) {
            child_processCmd = cmd
            cb()
          }
        }

        IELauncher = mocks.loadFile(__dirname + '/../index', {
          child_process: child_processMock
        }).module.exports
        injector = new di.Injector([module, IELauncher])
        launcher = injector.get('launcher:IE')
        launcher._process = {
          pid: 10
        }
        launcher._onProcessExit(1, 2)
      }
    })

    it('should call wmic with process ID', function (done) {
      onProcessExit()
      expect(child_processCmd).to.equal(
        'wmic.exe Path win32_Process where ' +
        '"Name=\'iexplore.exe\' and CommandLine Like \'%SCODEF:10%\'" call Terminate'
      )
      done()
    })
  })
})

@@ -1802,125 +1802,101 @@
 ude 
+3 
 arg
-s.flags', function (done) %7B%0A      var options%0A      module.args%5B1%5D = %7B%0A        flags: %5B'-flag1', '-flag2'%5D%0A      %7D
+uments (2 from the Edge command and 1 for the url)', function (done) %7B%0A      var options
 %0A   
@@ -1958,74 +1958,26 @@
 ions
-%5B0%5D
 ).to.
-equal('-flag1')%0A      expect(options%5B1%5D).to.equal('-flag2'
+have.length(3
 )%0A  
@@ -2192,1566 +2192,8 @@
 %7D)%0A%0A
-  describe('locating iexplore.exe', function () %7B%0A    var fsMock, win32Location%0A%0A    beforeEach(function () %7B%0A      process.env%5B'PROGRAMW6432'%5D = '%5C%5Cfake%5C%5CPROGRAMW6432'%0A      process.env%5B'PROGRAMFILES(X86)'%5D = '%5C%5Cfake%5C%5CPROGRAMFILES(X86)'%0A      process.env%5B'PROGRAMFILES'%5D = '%5C%5Cfake%5C%5CPROGRAMFILES'%0A      fsMock = mocks.fs.create(%7B%0A        'folder1': %7B%0A          'Internet Explorer': %7B%0A            'iexplore.exe': 1%0A          %7D%0A        %7D%0A      %7D)%0A%0A      IELauncher = mocks.loadFile(__dirname + '/../index', %7B%0A        fs: fsMock%0A      %7D).module.exports%0A%0A      win32Location = function () %7B%0A        injector = new di.Injector(%5Bmodule, IELauncher%5D)%0A        launcher = injector.get('launcher:IE')%0A        return launcher._getInternetExplorerExe()%0A      %7D%0A    %7D)%0A%0A    it('should locate in PROGRAMW6432', function (done) %7B%0A      process.env%5B'' + 'PROGRAMW6432'%5D = '%5C%5Cfolder1'%0A      expect(win32Location()).to.equal('%5C%5Cfolder1%5C%5CInternet Explorer%5C%5Ciexplore.exe')%0A      done()%0A    %7D)%0A%0A    it('should locate in PROGRAMFILES(X86)', function (done) %7B%0A      process.env%5B'' + 'PROGRAMFILES(X86)'%5D = '%5C%5Cfolder1'%0A      expect(win32Location()).to.equal('%5C%5Cfolder1%5C%5CInternet Explorer%5C%5Ciexplore.exe')%0A      done()%0A    %7D)%0A%0A    it('should locate in PROGRAMFILES', function (done) %7B%0A      process.env%5B'' + 'PROGRAMFILES'%5D = '%5C%5Cfolder1'%0A      expect(win32Location()).to.equal('%5C%5Cfolder1%5C%5CInternet Explorer%5C%5Ciexplore.exe')%0A      done()%0A    %7D)%0A%0A    it('should return undefined when not found', function (done) %7B%0A      expect(win32Location()).to.equal(void 0)%0A      done()%0A    %7D)%0A  %7D)%0A%0A
   de

Update tests so they pass