Skip to content

Commit

Permalink
Faster Jasmine runner exception detection. (See #112)
Browse files Browse the repository at this point in the history
This adds a check to see if  Jasmine is available by looking
at `window.jasmine`. If so, the normal waiting for the spec
results happens until the given timeout is reached. If Jasmine
is missing, then it's very likely that an exception is show by
the Rails error page (which of course doesn't include Jasmine).
In that case fail the specs with the body text as error message,
so that diagnosis directly in the console is possible.
  • Loading branch information
netzpirat committed Feb 19, 2013
1 parent 6d337ad commit 136a239
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
21 changes: 19 additions & 2 deletions lib/guard/jasmine/phantomjs/guard-jasmine.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,25 @@ page.open options.url, (status) ->
console.log JSON.stringify({ error: "Unable to access Jasmine specs at #{ options.url }" })
phantom.exit()
else
done = -> phantom.exit()
waitFor specsReady, done, options.timeout
runnerAvailable = page.evaluate -> window.jasmine

if runnerAvailable
done = -> phantom.exit()
waitFor specsReady, done, options.timeout
else
text = page.evaluate -> document.getElementsByTagName('body')[0]?.innerText

if text
error = """
The Jasmine reporter is not available!
#{ text }
"""
console.log JSON.stringify({ error: error })
else
console.log JSON.stringify({ error: 'The Jasmine reporter is not available!' })

phantom.exit(1)

# Test if the specs have finished.
#
Expand Down
31 changes: 26 additions & 5 deletions lib/guard/jasmine/phantomjs/guard-jasmine.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,39 @@
};

page.open(options.url, function(status) {
var done;
var done, error, runnerAvailable, text;
page.onLoadFinished = function() {};
if (status !== 'success') {
console.log(JSON.stringify({
error: "Unable to access Jasmine specs at " + options.url
}));
return phantom.exit();
} else {
done = function() {
return phantom.exit();
};
return waitFor(specsReady, done, options.timeout);
runnerAvailable = page.evaluate(function() {
return window.jasmine;
});
if (runnerAvailable) {
done = function() {
return phantom.exit();
};
return waitFor(specsReady, done, options.timeout);
} else {
text = page.evaluate(function() {
var _ref;
return (_ref = document.getElementsByTagName('body')[0]) != null ? _ref.innerText : void 0;
});
if (text) {
error = "The Jasmine reporter is not available!\n\n" + text;
console.log(JSON.stringify({
error: error
}));
} else {
console.log(JSON.stringify({
error: 'The Jasmine reporter is not available!'
}));
}
return phantom.exit(1);
}
}
});

Expand Down

0 comments on commit 136a239

Please sign in to comment.