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