Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should fail when there is a page error #68

Merged
merged 1 commit into from Jun 6, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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