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