         exitSpy = sinon.spy()
 
       it 'should kill all running processe', ->
-        l.launch ['Chrome', 'ChromeCanary'], 'localhost', 1234
+        l.launch ['Fake', 'Fake'], 'localhost', 1234
         l.kill()
 
-        expect(mockSpawn._processes.length).to.equal 2
-        expect(mockSpawn._processes[0].kill).to.have.been.called
-        expect(mockSpawn._processes[1].kill).to.have.been.called
+        browser = FakeBrowser._instances.pop()
+        expect(browser.kill).to.have.been.called
+
+        browser = FakeBrowser._instances.pop()
+        expect(browser.kill).to.have.been.called
 
 
       it 'should call callback when all processes killed', ->
-        l.launch ['Chrome', 'ChromeCanary'], 'localhost', 1234
+        l.launch ['Fake', 'Fake'], 'localhost', 1234
         l.kill exitSpy
 
         expect(exitSpy).not.to.have.been.called
-        mockSpawn._processes[0].emit 'close'
-        expect(exitSpy).not.to.have.been.called
-        mockSpawn._processes[1].emit 'close'
+
+        # finish the first browser
+        browser = FakeBrowser._instances.pop()
+        browser.kill.invokeCallback()
         expect(exitSpy).not.to.have.been.called
 
-        # rm temp dirs
-        expect(mockRimraf).to.have.been.calledTwice
-        mockRimraf._callbacks[0]()
-        mockRimraf._callbacks[1]()
+        # finish the second browser
+        browser = FakeBrowser._instances.pop()
+        browser.kill.invokeCallback()
         expect(exitSpy).to.have.been.called
-
-
-      it 'should call callback even if a process had already been killed', (done) ->
-        l.launch ['Chrome', 'ChromeCanary'], 'localhost', 1234, '/', 0, 1 # disable retry
-        mockSpawn._processes[0].emit 'close', 1
-        mockSpawn._processes[1].emit 'close', 1
-
-        l.kill done
+        # expect(browser.lastCall)
 
 
       it 'should call callback even if no browsers lanunched', (done) ->

# lib/launcher.js module
#==============================================================================
describe 'launcher', ->
  events = require '../../lib/events'
  logger = require '../../lib/logger'
  loadFile = require('mocks').loadFile

  mockSpawn = sinon.spy (cmd, args) ->
    process = new events.EventEmitter
    process.stderr = new events.EventEmitter
    process.kill = sinon.spy()
    process.exitCode = null
    mockSpawn._processes.push process
    process

  mockRimraf = sinon.spy (p, fn) ->
    mockRimraf._callbacks.push fn

  mocks =
    child_process:
      spawn: mockSpawn
    './logger': logger
    '../logger': logger
    rimraf: mockRimraf

  timeouts = [];

  globals =
    global: global
    process:
      nextTick: process.nextTick
      platform: 'linux'
      env: TMPDIR: '/temp'
    setTimeout: timer.setTimeout

  m = loadFile __dirname + '/../../lib/launcher.js', mocks, globals, true
  e = m.exports

  beforeEach ->
    mockSpawn.reset()
    mockSpawn._processes = []
    mockRimraf.reset()
    mockRimraf._callbacks = []
    timeouts = []

    # mock out id generator
    lastGeneratedId = 0
    e.Launcher.generateId = ->
      ++lastGeneratedId

    # disable logger
    logger.setup 'OFF'

    describe 'onExit', ->

      it 'should kill all browsers', (done) ->
        l.launch ['Fake', 'Fake'], 'localhost', 1234, '/', 0, 1

        emitter.emitAsync('exit').then done

        browser = FakeBrowser._instances.pop()
        browser.kill.invokeCallback()

        browser = FakeBrowser._instances.pop()
        browser.kill.invokeCallback()
