UNPKG

mocha

Version:

Classic, reliable, trusted test framework for Node.js and the browser

78 lines (65 loc) 1.91 kB
/** * @typedef {import('../runner.cjs')} Runner */ /** * @module Dot */ /** * Module dependencies. */ import { Base } from "./base.js"; import Runner from "../runner.cjs"; var { constants } = Runner; var EVENT_TEST_PASS = constants.EVENT_TEST_PASS; var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL; var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN; var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING; var EVENT_RUN_END = constants.EVENT_RUN_END; class Dot extends Base { static description = "dot matrix representation"; /** * Constructs a new `Dot` reporter instance. * * @public * @memberof Mocha.reporters * @extends Mocha.reporters.Base * @param {Runner} runner - Instance triggers reporter actions. * @param {Object} [options] - runner options */ constructor(runner, options) { super(runner, options); var self = this; var width = (Base.window.width * 0.75) | 0; var n = -1; runner.on(EVENT_RUN_BEGIN, function () { process.stdout.write("\n"); }); runner.on(EVENT_TEST_PENDING, function () { if (++n % width === 0) { process.stdout.write("\n "); } process.stdout.write(Base.color("pending", Base.symbols.comma)); }); runner.on(EVENT_TEST_PASS, function (test) { if (++n % width === 0) { process.stdout.write("\n "); } if (test.speed === "slow") { process.stdout.write(Base.color("bright yellow", Base.symbols.dot)); } else { process.stdout.write(Base.color(test.speed, Base.symbols.dot)); } }); runner.on(EVENT_TEST_FAIL, function () { if (++n % width === 0) { process.stdout.write("\n "); } process.stdout.write(Base.color("fail", Base.symbols.bang)); }); runner.once(EVENT_RUN_END, function () { process.stdout.write("\n"); self.epilogue(); }); } } export { Dot };