 #
 page.open url, (status) ->
   if status isnt 'success'
-    console.log JSON.stringify({ error: "Unable to access Jasmine specs at #{ url }" })
+    console.log JSON.stringify({ 'error': "Unable to access Jasmine specs at #{ url }" })
     phantom.exit()
   else
     waitFor specsReady, -> phantom.exit()

#
page = require('webpage').create()

# Capture console.log output to wrap the output
# from the specs into a JSON message.
#
page.onConsoleMessage = (msg, line, source) ->
  if /^ConsoleReporter: ([\s\S]*)$/.test(msg)
    console.log RegExp.$1
  else
    console.log JSON.stringify({ log: msg, line: line, source: source })

# Initialize the page before the JavaScript is run.
#
page.onInitialized = ->
  page.evaluate ->

    # Jasmine Reporter that logs reporter steps.
    #
    class ConsoleReporter

      reportSpecResults: (spec) ->
        @report { spec: spec.description, failed: spec.results().failedCount, skiped: spec.results().skipped }

      reportSuiteResults: (suite) ->
        @report { suite: suite.getFullName(), failed: suite.results().failedCount, skiped: suite.results().skipped  }

      reportRunnerResults: (runner) ->
        @report { finish: runner.description, total: runner.results().totalCount, failed: runner.results().failedCount }

      reportRunnerStarting: (runner) ->
      reportSpecStarting: (spec) ->
      log: (str) ->

      report: (response) ->
        console.log "ConsoleReporter: #{ JSON.stringify(response) }"

    # Attach the console reporter when the document is ready.
    #

# This file is the script that runs within PhantomJS, requests the Jasmine specs
# and waits until they are ready.

# Wait until the test condition is true or a timeout occurs.
#
