tap.js
1.23 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
58
59
60
61
62
63
64
65
66
67
68
69
70
'use strict';
/**
* Module dependencies.
*/
var Base = require('./base');
/**
* Expose `TAP`.
*/
exports = module.exports = TAP;
/**
* Initialize a new `TAP` reporter.
*
* @api public
* @param {Runner} runner
*/
function TAP (runner) {
Base.call(this, runner);
var n = 1;
var passes = 0;
var failures = 0;
runner.on('start', function () {
var total = runner.grepTotal(runner.suite);
console.log('%d..%d', 1, total);
});
runner.on('test end', function () {
++n;
});
runner.on('pending', function (test) {
console.log('ok %d %s # SKIP -', n, title(test));
});
runner.on('pass', function (test) {
passes++;
console.log('ok %d %s', n, title(test));
});
runner.on('fail', function (test, err) {
failures++;
console.log('not ok %d %s', n, title(test));
if (err.stack) {
console.log(err.stack.replace(/^/gm, ' '));
}
});
runner.on('end', function () {
console.log('# tests ' + (passes + failures));
console.log('# pass ' + passes);
console.log('# fail ' + failures);
});
}
/**
* Return a TAP-safe title of `test`
*
* @api private
* @param {Object} test
* @return {String}
*/
function title (test) {
return test.fullTitle().replace(/#/g, '');
}