UNPKG

1.26 kBJavaScriptView Raw
1'use strict';
2
3/**
4 * Module dependencies.
5 */
6
7var Base = require('./base');
8
9/**
10 * Expose `TAP`.
11 */
12
13exports = module.exports = TAP;
14
15/**
16 * Initialize a new `TAP` reporter.
17 *
18 * @api public
19 * @param {Runner} runner
20 */
21function TAP (runner) {
22 Base.call(this, runner);
23
24 var n = 1;
25 var passes = 0;
26 var failures = 0;
27
28 runner.on('start', function () {
29 var total = runner.grepTotal(runner.suite);
30 console.log('%d..%d', 1, total);
31 });
32
33 runner.on('test end', function () {
34 ++n;
35 });
36
37 runner.on('pending', function (test) {
38 console.log('ok %d %s # SKIP -', n, title(test));
39 });
40
41 runner.on('pass', function (test) {
42 passes++;
43 console.log('ok %d %s', n, title(test));
44 });
45
46 runner.on('fail', function (test, err) {
47 failures++;
48 console.log('not ok %d %s', n, title(test));
49 if (err.stack) {
50 console.log(err.stack.replace(/^/gm, ' '));
51 }
52 });
53
54 runner.on('end', function () {
55 console.log('# tests ' + (passes + failures));
56 console.log('# pass ' + passes);
57 console.log('# fail ' + failures);
58 });
59}
60
61/**
62 * Return a TAP-safe title of `test`
63 *
64 * @api private
65 * @param {Object} test
66 * @return {String}
67 */
68function title (test) {
69 return test.fullTitle().replace(/#/g, '');
70}