source: Dev/trunk/node_modules/mocha/lib/reporters/tap.js

Last change on this file was 484, checked in by hendrikvanantwerpen, 11 years ago

Commit node_modules, to make checkouts and builds more deterministic.

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