[IMP] js testing

- output "error" if any qunit tests failed
- failed js tests are logged as errors
- when running phantomjs considere empty waiting condition or initialisation code as "true"
- lint phantomtest.js file
This commit is contained in:
Christophe Simonis 2014-06-22 11:31:07 +02:00
parent e7ccf52043
commit 4cd699df15
3 changed files with 18 additions and 12 deletions

View File

@ -255,6 +255,8 @@
QUnit.done(function(result) { QUnit.done(function(result) {
if (result.failed === 0) { if (result.failed === 0) {
console.log('ok'); console.log('ok');
} else {
console.log('error');
} }
}); });
openerp.web.qweb.add_template("/web/webclient/qweb"); openerp.web.qweb.add_template("/web/webclient/qweb");

View File

@ -384,11 +384,12 @@ class TestStream(object):
if self.r.match(s): if self.r.match(s):
return return
first = True first = True
for c in s.split('\n'): level = logging.ERROR if s.startswith(('ERROR', 'FAIL', 'Traceback')) else logging.INFO
for c in s.splitlines():
if not first: if not first:
c = '` ' + c c = '` ' + c
first = False first = False
self.logger.info(c) self.logger.log(level, c)
current_test = None current_test = None

View File

@ -1,14 +1,15 @@
// Phantomjs openerp helper // Phantomjs odoo helper
// jshint evil: true, loopfunc: true
function waitFor (ready, callback, timeout, timeoutMessageCallback) { function waitFor (condition, callback, timeout, timeoutMessageCallback) {
timeout = timeout || 10000; timeout = timeout || 10000;
var start = new Date; var start = new Date();
(function waitLoop() { (function waitLoop() {
if(new Date - start > timeout) { if(new Date() - start > timeout) {
console.log('error', timeoutMessageCallback ? timeoutMessageCallback() : "Timeout after "+timeout+" ms"); console.log('error', timeoutMessageCallback ? timeoutMessageCallback() : "Timeout after "+timeout+" ms");
phantom.exit(1); phantom.exit(1);
} else if (ready()) { } else if (condition()) {
callback(); callback();
} else { } else {
setTimeout(waitLoop, 250); setTimeout(waitLoop, 250);
@ -44,7 +45,7 @@ function PhantomTest() {
} }
return result.join(''); return result.join('');
})); }));
msg.push('(leaf frame on top)') msg.push('(leaf frame on top)');
} }
console.log('error', JSON.stringify(msg.join('\n'))); console.log('error', JSON.stringify(msg.join('\n')));
phantom.exit(1); phantom.exit(1);
@ -86,9 +87,9 @@ function PhantomTest() {
}; };
setTimeout(function () { setTimeout(function () {
self.page.evaluate(function () { self.page.evaluate(function () {
var message = ("Timeout\nhref: " + window.location.href var message = ("Timeout\nhref: " + window.location.href +
+ "\nreferrer: " + document.referrer "\nreferrer: " + document.referrer +
+ "\n\n" + (document.body && document.body.innerHTML)).replace(/[^a-z0-9\s~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, "*"); "\n\n" + (document.body && document.body.innerHTML)).replace(/[^a-z0-9\s~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, "*");
console.log('error', message); console.log('error', message);
phantom.exit(1); phantom.exit(1);
}); });
@ -107,6 +108,8 @@ function PhantomTest() {
url_path = "/login?" + qp.join('&'); url_path = "/login?" + qp.join('&');
} }
var url = self.origin + url_path; var url = self.origin + url_path;
code = code || "true";
ready = ready || "true";
self.page.open(url, function(status) { self.page.open(url, function(status) {
if (status !== 'success') { if (status !== 'success') {
console.log('error', "failed to load " + url); console.log('error', "failed to load " + url);
@ -115,7 +118,7 @@ function PhantomTest() {
console.log('loaded', url, status); console.log('loaded', url, status);
// process ready // process ready
waitFor(function() { waitFor(function() {
console.log("PhantomTest.run: wait for condition: " + ready); console.log("PhantomTest.run: wait for condition:", ready);
return self.page.evaluate(function (ready) { return self.page.evaluate(function (ready) {
var r = false; var r = false;
try { try {