[FIX] correctly display JS stack frames in phantomjs runner

altered reporting to handle and deserialize JSON if JSON-deserializable. Can't
just send multiple lines as driver currently does not handle multiple lines of
message... Yeah turns out having a JSON-based protocol between phantomjs and
the python runner allowed multiple lines in messages, who'd have thought eh?

bzr revid: xmo@openerp.com-20140219123850-0h0upb3x33j7leqk
This commit is contained in:
Xavier Morel 2014-02-19 13:38:50 +01:00
parent f9993774f1
commit d5cb5c2a14
2 changed files with 30 additions and 19 deletions

View File

@ -210,11 +210,18 @@ class HttpCase(TransactionCase):
# process lines
if '\n' in buf:
line, buf = buf.split('\n', 1)
line = str(line)
if line == "ok":
break
if line.startswith("error"):
# 'error $message' or use generic message
self.fail(line[6:] or "phantomjs test failed")
line_ = line[6:]
try: line_ = json.loads(line_)
except ValueError: pass
self.fail(line_ or "phantomjs test failed")
try: line = json.loads(line)
except ValueError: pass
_logger.info("phantomjs: %s", line)
def phantom_run(self, cmd, timeout):

View File

@ -10,10 +10,8 @@ function waitFor (ready, callback, timeout, timeoutMessageCallback) {
} else {
if(!condition) {
var message = timeoutMessageCallback ? timeoutMessageCallback() : "Timeout after "+timeout+" ms";
console.log(message);
console.log("Waiting for " + ready);
console.log("error");
phantom.exit(1);
error(message);
} else {
clearInterval(interval);
callback();
@ -22,6 +20,10 @@ function waitFor (ready, callback, timeout, timeoutMessageCallback) {
}, 250);
}
function error(message) {
console.log('error', message);
phantom.exit(1);
}
function PhantomTest() {
var self = this;
this.options = JSON.parse(phantom.args[phantom.args.length-1]);
@ -30,15 +32,6 @@ function PhantomTest() {
this.origin = 'http://localhost';
this.origin += this.options.port ? ':' + this.options.port : '';
// ----------------------------------------------------
// test reporting
// ----------------------------------------------------
this.error = function(message) {
console.log(message);
console.log("error");
phantom.exit(1);
};
// ----------------------------------------------------
// configure phantom and page
// ----------------------------------------------------
@ -50,10 +43,21 @@ function PhantomTest() {
this.page = require('webpage').create();
this.page.viewportSize = { width: 1366, height: 768 };
this.page.onError = function(message, trace) {
self.error(message + " " + trace);
var msg = [message];
if (trace && trace.length) {
msg.push.apply(msg, trace.map(function (frame) {
var result = [' at ', frame.file, ':', frame.line];
if (frame.function) {
result.push(' (in ', frame.function, ')');
}
return result.join('');
}));
msg.push('(leaf frame on top)')
}
error(JSON.stringify(msg.join('\n')));
};
this.page.onAlert = function(message) {
self.error(message);
error(message);
};
this.page.onConsoleMessage = function(message) {
console.log(message);
@ -79,7 +83,7 @@ function PhantomTest() {
if(!found) {
console.log('Injecting', src, 'needed for', need);
if(!self.page.injectJs(src)) {
self.error("Cannot inject " + src);
error("Cannot inject " + src);
}
}
}
@ -90,7 +94,7 @@ function PhantomTest() {
var message = ("Timeout\nhref: " + window.location.href
+ "\nreferrer: " + document.referrer
+ "\n\n" + document.body.innerHTML).replace(/[^a-z0-9\s~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, "*");
self.error(message);
error(message);
});
}, self.timeout);
@ -109,7 +113,7 @@ function PhantomTest() {
var url = self.origin + url_path;
self.page.open(url, function(status) {
if (status !== 'success') {
self.error("failed to load " + url)
error("failed to load " + url)
} else {
console.log('loaded', url, status);
// process ready