Permalink
Browse files

update browser test reporter to add test results to the page as they …

…complete
  • Loading branch information...
1 parent 0d91ab4 commit 8b1e409eae682ef48fdb62a3d65a3392cb6b0a8f @caolan caolan committed Nov 22, 2010
Showing with 25 additions and 14 deletions.
  1. +25 −14 lib/reporters/browser.js
View
@@ -58,18 +58,29 @@ exports.run = function (modules, options) {
var start = new Date().getTime();
exports.addStyles();
- var html = '';
+ var results, module;
+
+ results = document.createElement('div');
+ results.id = 'results';
+ document.body.appendChild(results);
+
nodeunit.runModules(modules, {
moduleStart: function (name) {
- html += '<h2>' + name + '</h2>';
- html += '<ol>';
+ var mheading = document.createElement('h2');
+ mheading.innerText = name;
+ results.appendChild(mheading);
+ module = document.createElement('ol');
+ results.appendChild(module);
},
testDone: function (name, assertions) {
+ var test = document.createElement('li');
if (!assertions.failures()) {
- html += '<li class="pass">' + name + '</li>';
+ test.className = 'pass';
+ test.innerText = name;
}
else {
- html += '<li class="fail">' + name;
+ test.className = 'fail';
+ var html = name;
for (var i=0; i<assertions.length; i++) {
var a = assertions[i];
if (a.failed()) {
@@ -83,25 +94,25 @@ exports.run = function (modules, options) {
html += '</pre>';
}
};
- html += '</li>';
+ test.innerHTML = html;
}
- },
- moduleDone: function () {
- html += '</ol>';
+ module.appendChild(test);
},
done: function (assertions) {
var end = new Date().getTime();
var duration = end - start;
+
+ var summary = document.createElement('h3');
if (assertions.failures()) {
- html += '<h3>FAILURES: ' + assertions.failures() +
+ summary.innerText = 'FAILURES: ' + assertions.failures() +
'/' + assertions.length + ' assertions failed (' +
- assertions.duration + 'ms)</h3>';
+ assertions.duration + 'ms)';
}
else {
- html += '<h3>OK: ' + assertions.length +
- ' assertions (' + assertions.duration + 'ms)</h3>';
+ summary.innerText = 'OK: ' + assertions.length +
+ ' assertions (' + assertions.duration + 'ms)';
}
- document.body.innerHTML += html;
+ document.body.appendChild(summary);
}
});
};

0 comments on commit 8b1e409

Please sign in to comment.