-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtestrunner.js
More file actions
57 lines (50 loc) · 1.74 KB
/
testrunner.js
File metadata and controls
57 lines (50 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var nodeunit = require('./nodeunit'),
util = require('util');
exports.run = function(files){
var red = function(str){return "\033[31m" + str + "\033[39m"};
var green = function(str){return "\033[32m" + str + "\033[39m"};
var bold = function(str){return "\033[1m" + str + "\033[22m"};
var start = new Date().getTime();
nodeunit.runFiles(files, {
moduleStart: function(name){
util.puts('\n' + bold(name));
},
testDone: function(name, assertions){
if(!assertions.failures){
util.puts('✔ ' + name);
}
else {
util.puts(red('✖ ' + name) + '\n');
assertions.forEach(function(assertion){
if(assertion.failed()){
util.puts(assertion.error.stack + '\n');
}
});
}
},
done: function(assertions){
var end = new Date().getTime();
var duration = end - start;
if(assertions.failures){
util.puts(
'\n' + bold(red('FAILURES: ')) + assertions.failures +
'/' + assertions.length + ' assertions failed (' +
assertions.duration + 'ms)'
);
}
else {
util.puts(
'\n' + bold(green('OK: ')) + assertions.length +
' assertions (' + assertions.duration + 'ms)'
);
}
process.reallyExit(assertions.failures);
}
});
};
// If this is run from the command-line:
if(module.id === '.'){
require.paths.push(process.cwd());
var args = process.ARGV.slice(2);
exports.run(args);
}