     connectClient client, (err, def) ->
       return callback err, client, def, state, httpServer
 
-# FIXME: move to protocol
+runAllComponentTests = (ru, callback) ->
+  state = null
+  onUpdate = (s) ->
+    state = s
+  ru.connect (err) ->
+    return done err if err
+    runner.getComponentSuites ru, (err, suites) ->
+      return done err if err
+      runner.runAll ru, suites, onUpdate, (err) ->
+        return callback err, state
 
 describe 'Mocha compatibility runner', ->
   httpServer = null

  test = path.join __dirname, 'fixtures/mochacases', name
  return test

connectClient = (client, callback) ->
  onStatus = (status) =>
    return if not status.online # ignore, might get false before getting a true

      mochacompat.setup options, (err, state, server) ->
        httpServer = server

        ru = new runner.Runner runtimeDefinition(options)
        runAllComponentTests ru, (err, state) ->
          return done err if err
          chai.expect(state).to.have.length 1
          cases = state[0].cases
          chai.expect(cases).to.have.length 1
          chai.expect(cases[0].passed, 'testcase did not pass').to.equal true
          done()

  describe 'running a failing test', ->
    testcase = null
    it 'should recorded 1 failed test', (done) ->
      options =
        files: [ testPath('bdd-simple-failing.coffee') ]
      mochacompat.setup options, (err, state, server) ->
        httpServer = server
        ru = new runner.Runner runtimeDefinition(options)
        runAllComponentTests ru, (err, state) ->
          return done err if err
          chai.expect(state).to.have.length 1
          cases = state[0].cases
          chai.expect(cases).to.have.length 1
          testcase = cases[0]
          chai.expect(testcase.passed, 'failing testcase passed').to.equal false
          done()
    it 'has error message of the Chai assertion', ->
      chai.expect(testcase?.error).to.contain 'expected 42 to equal 41'
