Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80684 views
1
2
var EventEmitter = require('events').EventEmitter,
3
assert = require('assert'),
4
tests = {};
5
6
module.exports = test;
7
test.run = run;
8
9
// ## Test helpers
10
11
function test(msg, handler) {
12
tests[msg] = handler;
13
}
14
15
function run() {
16
var specs = Object.keys(tests),
17
specsRemaining = specs.length;
18
19
specs.forEach(function(spec) {
20
var handler = tests[spec];
21
22
// grab the set of asserts for this spec
23
var shoulds = handler(),
24
keys = Object.keys(shoulds),
25
remaining = keys.length;
26
27
keys.forEach(function(should) {
28
var em = new EventEmitter(),
29
to = setTimeout(function() {
30
assert.fail('never ended');
31
}, 5000);
32
33
em
34
.on('error', function assertFail(err) { assert.fail(err) })
35
.on('end', function assertOk() {
36
clearTimeout(to);
37
shoulds[should].status = true;
38
39
// till we get to 0
40
if(!(--remaining)) {
41
console.log([
42
'',
43
'» ' + spec,
44
keys.map(function(k) { return ' » ' + k; }).join('\n'),
45
'',
46
' Total: ' + keys.length,
47
' Failed: ' + keys.map(function(item) { return shoulds[should].status; }).filter(function(status) { return !status; }).length,
48
''
49
].join('\n'));
50
51
if(!(--specsRemaining)) {
52
console.log('All done');
53
}
54
55
}
56
});
57
58
shoulds[should](em);
59
});
60
});
61
}
62
63