UNPKG

1.9 kBJavaScriptView Raw
1'use strict';
2/**
3 * @module List
4 */
5/**
6 * Module dependencies.
7 */
8
9var Base = require('./base');
10var inherits = require('../utils').inherits;
11var constants = require('../runner').constants;
12var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
13var EVENT_RUN_END = constants.EVENT_RUN_END;
14var EVENT_TEST_BEGIN = constants.EVENT_TEST_BEGIN;
15var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
16var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
17var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
18var color = Base.color;
19var cursor = Base.cursor;
20
21/**
22 * Expose `List`.
23 */
24
25exports = module.exports = List;
26
27/**
28 * Constructs a new `List` reporter instance.
29 *
30 * @public
31 * @class
32 * @memberof Mocha.reporters
33 * @extends Mocha.reporters.Base
34 * @param {Runner} runner - Instance triggers reporter actions.
35 * @param {Object} [options] - runner options
36 */
37function List(runner, options) {
38 Base.call(this, runner, options);
39
40 var self = this;
41 var n = 0;
42
43 runner.on(EVENT_RUN_BEGIN, function() {
44 Base.consoleLog();
45 });
46
47 runner.on(EVENT_TEST_BEGIN, function(test) {
48 process.stdout.write(color('pass', ' ' + test.fullTitle() + ': '));
49 });
50
51 runner.on(EVENT_TEST_PENDING, function(test) {
52 var fmt = color('checkmark', ' -') + color('pending', ' %s');
53 Base.consoleLog(fmt, test.fullTitle());
54 });
55
56 runner.on(EVENT_TEST_PASS, function(test) {
57 var fmt =
58 color('checkmark', ' ' + Base.symbols.ok) +
59 color('pass', ' %s: ') +
60 color(test.speed, '%dms');
61 cursor.CR();
62 Base.consoleLog(fmt, test.fullTitle(), test.duration);
63 });
64
65 runner.on(EVENT_TEST_FAIL, function(test) {
66 cursor.CR();
67 Base.consoleLog(color('fail', ' %d) %s'), ++n, test.fullTitle());
68 });
69
70 runner.once(EVENT_RUN_END, self.epilogue.bind(self));
71}
72
73/**
74 * Inherit from `Base.prototype`.
75 */
76inherits(List, Base);
77
78List.description = 'like "spec" reporter but flat';