source: Dev/trunk/node_modules/mocha/lib/reporters/spec.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.7 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 `Spec`.
12 */
13
14exports = module.exports = Spec;
15
16/**
17 * Initialize a new `Spec` test reporter.
18 *
19 * @param {Runner} runner
20 * @api public
21 */
22
23function Spec(runner) {
24  Base.call(this, runner);
25
26  var self = this
27    , stats = this.stats
28    , indents = 0
29    , n = 0;
30
31  function indent() {
32    return Array(indents).join('  ')
33  }
34
35  runner.on('start', function(){
36    console.log();
37  });
38
39  runner.on('suite', function(suite){
40    ++indents;
41    console.log(color('suite', '%s%s'), indent(), suite.title);
42  });
43
44  runner.on('suite end', function(suite){
45    --indents;
46    if (1 == indents) console.log();
47  });
48
49  runner.on('test', function(test){
50    process.stdout.write(indent() + color('pass', '  ◩ ' + test.title + ': '));
51  });
52
53  runner.on('pending', function(test){
54    var fmt = indent() + color('pending', '  - %s');
55    console.log(fmt, test.title);
56  });
57
58  runner.on('pass', function(test){
59    if ('fast' == test.speed) {
60      var fmt = indent()
61        + color('checkmark', '  ' + Base.symbols.ok)
62        + color('pass', ' %s ');
63      cursor.CR();
64      console.log(fmt, test.title);
65    } else {
66      var fmt = indent()
67        + color('checkmark', '  ' + Base.symbols.ok)
68        + color('pass', ' %s ')
69        + color(test.speed, '(%dms)');
70      cursor.CR();
71      console.log(fmt, test.title, test.duration);
72    }
73  });
74
75  runner.on('fail', function(test, err){
76    cursor.CR();
77    console.log(indent() + color('fail', '  %d) %s'), ++n, test.title);
78  });
79
80  runner.on('end', self.epilogue.bind(self));
81}
82
83/**
84 * Inherit from `Base.prototype`.
85 */
86
87Spec.prototype.__proto__ = Base.prototype;
Note: See TracBrowser for help on using the repository browser.