UNPKG

1.89 kBJavaScriptView Raw
1'use strict';
2/**
3 * @module Dot
4 */
5/**
6 * Module dependencies.
7 */
8
9var Base = require('./base');
10var inherits = require('../utils').inherits;
11var constants = require('../runner').constants;
12var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
13var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
14var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
15var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
16var EVENT_RUN_END = constants.EVENT_RUN_END;
17
18/**
19 * Expose `Dot`.
20 */
21
22exports = module.exports = Dot;
23
24/**
25 * Constructs a new `Dot` reporter instance.
26 *
27 * @public
28 * @class
29 * @memberof Mocha.reporters
30 * @extends Mocha.reporters.Base
31 * @param {Runner} runner - Instance triggers reporter actions.
32 * @param {Object} [options] - runner options
33 */
34function Dot(runner, options) {
35 Base.call(this, runner, options);
36
37 var self = this;
38 var width = (Base.window.width * 0.75) | 0;
39 var n = -1;
40
41 runner.on(EVENT_RUN_BEGIN, function() {
42 process.stdout.write('\n');
43 });
44
45 runner.on(EVENT_TEST_PENDING, function() {
46 if (++n % width === 0) {
47 process.stdout.write('\n ');
48 }
49 process.stdout.write(Base.color('pending', Base.symbols.comma));
50 });
51
52 runner.on(EVENT_TEST_PASS, function(test) {
53 if (++n % width === 0) {
54 process.stdout.write('\n ');
55 }
56 if (test.speed === 'slow') {
57 process.stdout.write(Base.color('bright yellow', Base.symbols.dot));
58 } else {
59 process.stdout.write(Base.color(test.speed, Base.symbols.dot));
60 }
61 });
62
63 runner.on(EVENT_TEST_FAIL, function() {
64 if (++n % width === 0) {
65 process.stdout.write('\n ');
66 }
67 process.stdout.write(Base.color('fail', Base.symbols.bang));
68 });
69
70 runner.once(EVENT_RUN_END, function() {
71 process.stdout.write('\n');
72 self.epilogue();
73 });
74}
75
76/**
77 * Inherit from `Base.prototype`.
78 */
79inherits(Dot, Base);
80
81Dot.description = 'dot matrix representation';