[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:
parent
f9993774f1
commit
d5cb5c2a14
|
@ -210,11 +210,18 @@ class HttpCase(TransactionCase):
|
||||||
# process lines
|
# process lines
|
||||||
if '\n' in buf:
|
if '\n' in buf:
|
||||||
line, buf = buf.split('\n', 1)
|
line, buf = buf.split('\n', 1)
|
||||||
|
|
||||||
|
line = str(line)
|
||||||
if line == "ok":
|
if line == "ok":
|
||||||
break
|
break
|
||||||
if line.startswith("error"):
|
if line.startswith("error"):
|
||||||
# 'error $message' or use generic message
|
line_ = line[6:]
|
||||||
self.fail(line[6:] or "phantomjs test failed")
|
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)
|
_logger.info("phantomjs: %s", line)
|
||||||
|
|
||||||
def phantom_run(self, cmd, timeout):
|
def phantom_run(self, cmd, timeout):
|
||||||
|
|
|
@ -10,10 +10,8 @@ function waitFor (ready, callback, timeout, timeoutMessageCallback) {
|
||||||
} else {
|
} else {
|
||||||
if(!condition) {
|
if(!condition) {
|
||||||
var message = timeoutMessageCallback ? timeoutMessageCallback() : "Timeout after "+timeout+" ms";
|
var message = timeoutMessageCallback ? timeoutMessageCallback() : "Timeout after "+timeout+" ms";
|
||||||
console.log(message);
|
|
||||||
console.log("Waiting for " + ready);
|
console.log("Waiting for " + ready);
|
||||||
console.log("error");
|
error(message);
|
||||||
phantom.exit(1);
|
|
||||||
} else {
|
} else {
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
callback();
|
callback();
|
||||||
|
@ -22,6 +20,10 @@ function waitFor (ready, callback, timeout, timeoutMessageCallback) {
|
||||||
}, 250);
|
}, 250);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function error(message) {
|
||||||
|
console.log('error', message);
|
||||||
|
phantom.exit(1);
|
||||||
|
}
|
||||||
function PhantomTest() {
|
function PhantomTest() {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.options = JSON.parse(phantom.args[phantom.args.length-1]);
|
this.options = JSON.parse(phantom.args[phantom.args.length-1]);
|
||||||
|
@ -30,15 +32,6 @@ function PhantomTest() {
|
||||||
this.origin = 'http://localhost';
|
this.origin = 'http://localhost';
|
||||||
this.origin += this.options.port ? ':' + this.options.port : '';
|
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
|
// configure phantom and page
|
||||||
// ----------------------------------------------------
|
// ----------------------------------------------------
|
||||||
|
@ -50,10 +43,21 @@ function PhantomTest() {
|
||||||
this.page = require('webpage').create();
|
this.page = require('webpage').create();
|
||||||
this.page.viewportSize = { width: 1366, height: 768 };
|
this.page.viewportSize = { width: 1366, height: 768 };
|
||||||
this.page.onError = function(message, trace) {
|
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) {
|
this.page.onAlert = function(message) {
|
||||||
self.error(message);
|
error(message);
|
||||||
};
|
};
|
||||||
this.page.onConsoleMessage = function(message) {
|
this.page.onConsoleMessage = function(message) {
|
||||||
console.log(message);
|
console.log(message);
|
||||||
|
@ -79,7 +83,7 @@ function PhantomTest() {
|
||||||
if(!found) {
|
if(!found) {
|
||||||
console.log('Injecting', src, 'needed for', need);
|
console.log('Injecting', src, 'needed for', need);
|
||||||
if(!self.page.injectJs(src)) {
|
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
|
var message = ("Timeout\nhref: " + window.location.href
|
||||||
+ "\nreferrer: " + document.referrer
|
+ "\nreferrer: " + document.referrer
|
||||||
+ "\n\n" + document.body.innerHTML).replace(/[^a-z0-9\s~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, "*");
|
+ "\n\n" + document.body.innerHTML).replace(/[^a-z0-9\s~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, "*");
|
||||||
self.error(message);
|
error(message);
|
||||||
});
|
});
|
||||||
}, self.timeout);
|
}, self.timeout);
|
||||||
|
|
||||||
|
@ -109,7 +113,7 @@ function PhantomTest() {
|
||||||
var url = self.origin + url_path;
|
var url = self.origin + url_path;
|
||||||
self.page.open(url, function(status) {
|
self.page.open(url, function(status) {
|
||||||
if (status !== 'success') {
|
if (status !== 'success') {
|
||||||
self.error("failed to load " + url)
|
error("failed to load " + url)
|
||||||
} else {
|
} else {
|
||||||
console.log('loaded', url, status);
|
console.log('loaded', url, status);
|
||||||
// process ready
|
// process ready
|
||||||
|
|
Loading…
Reference in New Issue