Skip to content

Commit

Permalink
Merge pull request #68 from alexgorbatchev/master
Browse files Browse the repository at this point in the history
Should fail when there is a page error
  • Loading branch information
metaskills committed Jun 6, 2013
2 parents f30affe + 5cb72d4 commit 1d1c4ab
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/mocha-phantomjs.coffee
Expand Up @@ -49,6 +49,10 @@ class Reporter
@page.addCookie(cookie) for cookie in @config.cookies
@page.viewportSize = @config.viewportSize if @config.viewportSize
@page.onConsoleMessage = (msg) -> console.log msg
@page.onError = (msg, traces) =>
for {line, file}, index in traces
traces[index] = " #{file}:#{line}"
@fail "#{msg}\n\n#{traces.join '\n'}"
@page.onInitialized = =>
@page.evaluate ->
window.mochaPhantomJS =
Expand Down
25 changes: 25 additions & 0 deletions test/error.html
@@ -0,0 +1,25 @@
<html>
<head>
<title>Tests Cookie</title>
<meta charset="utf-8">
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
</head>
<body>
<div id="mocha"></div>
<script src="../node_modules/mocha/mocha.js"></script>
<script>
mocha.ui('bdd');
mocha.reporter('html');
</script>
<script>
unknownFunctionCall();

if (window.mochaPhantomJS) {
mochaPhantomJS.run();
} else {
mocha.run();
}
</script>
</body>
</html>

6 changes: 6 additions & 0 deletions test/lib/mocha-phantomjs.js

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

5 changes: 5 additions & 0 deletions test/src/mocha-phantomjs.coffee
Expand Up @@ -55,6 +55,11 @@ describe 'mocha-phantomjs', ->
expect(code).to.equal 255
expect(stdout).to.match /Failed to start mocha: Init timeout/

it 'returns a failure code when there is a page error', (done) ->
@runner done, [fileURL('error')], (code, stdout, stderr) ->
expect(code).to.equal 1
expect(stdout).to.match /ReferenceError/

it 'does not fail when an iframe is used', (done) ->
@runner done, [fileURL('iframe')], (code, stdout, stderr) ->
expect(stdout).to.not.match /Failed to load the page\./m
Expand Down

0 comments on commit 1d1c4ab

Please sign in to comment.