source: Dev/trunk/node_modules/mocha/lib/reporters/progress.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.8 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 `Progress`.
12 */
13
14exports = module.exports = Progress;
15
16/**
17 * General progress bar color.
18 */
19
20Base.colors.progress = 90;
21
22/**
23 * Initialize a new `Progress` bar test reporter.
24 *
25 * @param {Runner} runner
26 * @param {Object} options
27 * @api public
28 */
29
30function Progress(runner, options) {
31  Base.call(this, runner);
32
33  var self = this
34    , options = options || {}
35    , stats = this.stats
36    , width = Base.window.width * .50 | 0
37    , total = runner.total
38    , complete = 0
39    , max = Math.max;
40
41  // default chars
42  options.open = options.open || '[';
43  options.complete = options.complete || '▬';
44  options.incomplete = options.incomplete || Base.symbols.dot;
45  options.close = options.close || ']';
46  options.verbose = false;
47
48  // tests started
49  runner.on('start', function(){
50    console.log();
51    cursor.hide();
52  });
53
54  // tests complete
55  runner.on('test end', function(){
56    complete++;
57    var incomplete = total - complete
58      , percent = complete / total
59      , n = width * percent | 0
60      , i = width - n;
61
62    cursor.CR();
63    process.stdout.write('\u001b[J');
64    process.stdout.write(color('progress', '  ' + options.open));
65    process.stdout.write(Array(n).join(options.complete));
66    process.stdout.write(Array(i).join(options.incomplete));
67    process.stdout.write(color('progress', options.close));
68    if (options.verbose) {
69      process.stdout.write(color('progress', ' ' + complete + ' of ' + total));
70    }
71  });
72
73  // tests are complete, output some stats
74  // and the failures if any
75  runner.on('end', function(){
76    cursor.show();
77    console.log();
78    self.epilogue();
79  });
80}
81
82/**
83 * Inherit from `Base.prototype`.
84 */
85
86Progress.prototype.__proto__ = Base.prototype;
Note: See TracBrowser for help on using the repository browser.