mirror of
https://github.com/codedread/bitjs
synced 2025-10-04 10:09:16 +02:00
Add support for asynchronous tests to test harness
This commit is contained in:
parent
9305f4e11b
commit
0061459c95
2 changed files with 34 additions and 22 deletions
34
muther.js
34
muther.js
|
@ -6,23 +6,35 @@
|
|||
*/
|
||||
var muther = muther || {};
|
||||
|
||||
var $ = function(s) { return document.querySelector(s) || {}; }
|
||||
muther.assert = function(cond, err) { if (!cond) { throw err; } };
|
||||
muther.assertEquals = function(a, b, err) { muther.assert(a === b, err); };
|
||||
|
||||
muther.addResult_ = function(innerHTML, pass) {
|
||||
document.body.innerHTML += '<div style="' +
|
||||
(pass ? 'color:#090' : 'color:#900') + '">' + innerHTML + '</div>';
|
||||
muther.set_ = function(id, style, innerHTML) {
|
||||
$('#' + id).innerHTML = '';
|
||||
document.body.innerHTML += '<div id="' + id + '" style="' + style + '">' + innerHTML + '</div>';
|
||||
};
|
||||
|
||||
muther.go = function(spec) {
|
||||
var setup = spec['setUp'] || function(){};
|
||||
var tearDown = spec['tearDown'] || function(){};
|
||||
spec['tests'].forEach(function(test) {
|
||||
try {
|
||||
setup(); test(); tearDown();
|
||||
muther.addResult_('PASS: ' + test.name, true);
|
||||
} catch(e) {
|
||||
muther.addResult_('FAIL: ' + test.name + ': ' + e, false);
|
||||
Object.keys(spec['tests']).forEach(function(testName) {
|
||||
var test = spec['tests'][testName];
|
||||
if (test instanceof Promise) {
|
||||
muther.set_(testName, 'color:#F90', 'RUNNING: ' + testName);
|
||||
// TODO: What if we want setup() and tearDown()?
|
||||
test.then(function() {
|
||||
muther.set_(testName, 'color:#090', 'PASS: ' + testName);
|
||||
}, function(err) {
|
||||
muther.set_(testName, 'color:#900', 'FAIL: ' + testName + ': ' + err);
|
||||
});
|
||||
} else if (test instanceof Function) {
|
||||
var setup = spec['setUp'] || function(){};
|
||||
var tearDown = spec['tearDown'] || function(){};
|
||||
try {
|
||||
setup(); test(); tearDown();
|
||||
muther.set_(testName, 'color:#090', 'PASS: ' + testName);
|
||||
} catch (err) {
|
||||
muther.set_(testName, 'color:#900', 'FAIL: ' + testName + ': ' + err);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue