Skip to content
This repository was archived by the owner on Dec 27, 2018. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/Meteor.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ class Meteor extends EventEmitter
else
delete env.MONGO_URL if env.MONGO_URL?

if @options["coverage"]?
env.COVERAGE = "1"
env.COVERAGE_APP_FOLDER = path.join(cwd, './')
if @options["loglevel"]?
env.COVERAGE_VERBOSE = "1"

options = {
cwd: cwd,
env: env,
Expand Down
2 changes: 2 additions & 0 deletions lib/Spacejam.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class Spacejam extends EventEmitter
expect(@meteor, "Meteor is already running").to.be.null

@options = _.extend @defaultOptions(), options
if @options.coverage? && @options.coverage
@options['phantomjs-script'] = "phantomjs-test-in-console-with-coverage.js";
log.debug @options

try
Expand Down
70 changes: 70 additions & 0 deletions lib/phantomjs-test-in-console-with-coverage.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
page = require('webpage').create()
system = require('system')

console.log("phantomjs: Running tests at #{system.env.ROOT_URL} using test-in-console and coverage")

page.onConsoleMessage = (message) ->
console.log(message)

page.open(system.env.ROOT_URL)

page.onError = (msg, trace) ->

mochaIsRunning = page.evaluate ->
return window.mochaIsRunning

# Mocha will handle and report the uncaught errors for us
if mochaIsRunning
return

console.log("phantomjs: #{msg}")

trace.forEach((item) ->
console.log(" #{item.file}: #{item.line}")
)
phantom.exit(0)

page.onCallback = (data) ->
## Callback when sending and saving coverage
if data && data.err
console.log("coverage error: #{data.err}")
phantom.exit(7)
else
phantom.exit(0)


checkingStatus = setInterval ->
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite a lot of cyclomatic complexity here.

done = page.evaluate ->
return TEST_STATUS.DONE if TEST_STATUS?
return DONE if DONE?
return false

if done
failures = page.evaluate ->
return TEST_STATUS.FAILURES if TEST_STATUS?
return FAILURES if FAILURES?
return false
if failures
phantom.exit(2)
else
## tests are ok, save coverage
clearInterval checkingStatus
page.evaluate ->
if ! Package || ! Package['meteor'] || ! Package['meteor']['Meteor'] || ! Package['meteor']['Meteor'].sendCoverage || ! Package['meteor']['Meteor'].exportCoverage
window.callPhantom
err: "Coverage package missing or not correclty launched"
else
Package['meteor']['Meteor'].sendCoverage (stats,err) ->
console.log("tests are ok and some js on the client side have been covered. Report: ", JSON.stringify(stats))
if err
window.callPhantom
err: "Failed to send client coverage"
else
Package['meteor']['Meteor'].exportCoverage 'lcovonly', (err) ->
if err
window.callPhantom
err: "Failed to save lcovonly coverage"
else
window.callPhantom
success: "true"
, 500
98 changes: 98 additions & 0 deletions lib/phantomjs-test-in-console-with-coverage.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.