     phantom.exit 1
 
   finish: ->
-    phantom.exit @page.evaluate -> mocha.phantomjs?.failures
+    phantom.exit @page.evaluate -> mochaPhantomJS.failures
 
   initPage: ->
     @page = webpage.create()
     @page.onConsoleMessage = (msg) -> console.log msg
-    @page.onInitialized = => 
-      @page.evaluate -> window.mochaPhantomJS = true
+    @page.onInitialized = =>
+      @page.evaluate ->
+        window.mochaPhantomJS =
+          failures: 0
+          ended: false
+          started: false
+          run: ->
+            mochaPhantomJS.started = true
 
   loadPage: ->
     @page.open @url

  injectJS: ->
    if @page.evaluate(-> window.mocha?)
      @page.injectJs 'mocha-phantomjs/core_extensions.js'
      @page.evaluate ->
        mocha.phantomjs =
          failures: 0
          ended: false
          started: false
          run: ->
            mocha.phantomjs.started = true
      @page.evaluate @customizeProcessStdout, @customizeOptions()
      @page.evaluate @customizeConsole, @customizeOptions()
    else

  customizeRunner: (options) ->
    undefined

  customizeProcessStdout: (options) ->
    undefined

  customizeConsole: (options) ->
