source: Dev/trunk/node_modules/mocha/lib/reporters/landing.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 `Landing`.
12 */
13
14exports = module.exports = Landing;
15
16/**
17 * Airplane color.
18 */
19
20Base.colors.plane = 0;
21
22/**
23 * Airplane crash color.
24 */
25
26Base.colors['plane crash'] = 31;
27
28/**
29 * Runway color.
30 */
31
32Base.colors.runway = 90;
33
34/**
35 * Initialize a new `Landing` reporter.
36 *
37 * @param {Runner} runner
38 * @api public
39 */
40
41function Landing(runner) {
42  Base.call(this, runner);
43
44  var self = this
45    , stats = this.stats
46    , width = Base.window.width * .75 | 0
47    , total = runner.total
48    , stream = process.stdout
49    , plane = color('plane', '✈')
50    , crashed = -1
51    , n = 0;
52
53  function runway() {
54    var buf = Array(width).join('-');
55    return '  ' + color('runway', buf);
56  }
57
58  runner.on('start', function(){
59    stream.write('\n  ');
60    cursor.hide();
61  });
62
63  runner.on('test end', function(test){
64    // check if the plane crashed
65    var col = -1 == crashed
66      ? width * ++n / total | 0
67      : crashed;
68
69    // show the crash
70    if ('failed' == test.state) {
71      plane = color('plane crash', '✈');
72      crashed = col;
73    }
74
75    // render landing strip
76    stream.write('\u001b[4F\n\n');
77    stream.write(runway());
78    stream.write('\n  ');
79    stream.write(color('runway', Array(col).join('⋅')));
80    stream.write(plane)
81    stream.write(color('runway', Array(width - col).join('⋅') + '\n'));
82    stream.write(runway());
83    stream.write('\u001b[0m');
84  });
85
86  runner.on('end', function(){
87    cursor.show();
88    console.log();
89    self.epilogue();
90  });
91}
92
93/**
94 * Inherit from `Base.prototype`.
95 */
96
97Landing.prototype.__proto__ = Base.prototype;
Note: See TracBrowser for help on using the repository browser.