| 1 | "use strict"; |
| 2 | |
| 3 | /** |
| 4 | * @typedef {import('../runner.js')} Runner |
| 5 | * @typedef {import('../test.js')} Test |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * @module TAP |
| 10 | */ |
| 11 | /** |
| 12 | * Module dependencies. |
| 13 | */ |
| 14 | |
| 15 | var utilscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/util. = require("node:util"); |
| 16 | var Basescip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/Base. = require("./base"scip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/); |
| 17 | var constantsscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/constants. = require("../runner"scip-typescript npm mocha 11.7.7 lib/`runner.js`/).constants; |
| 18 | var EVENT_TEST_PASSscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/EVENT_TEST_PASS. = constants.EVENT_TEST_PASS; |
| 19 | var EVENT_TEST_FAILscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/EVENT_TEST_FAIL. = constants.EVENT_TEST_FAIL; |
| 20 | var EVENT_RUN_BEGINscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/EVENT_RUN_BEGIN. = constants.EVENT_RUN_BEGIN; |
| 21 | var EVENT_RUN_ENDscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/EVENT_RUN_END. = constants.EVENT_RUN_END; |
| 22 | var EVENT_TEST_PENDINGscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/EVENT_TEST_PENDING. = constants.EVENT_TEST_PENDING; |
| 23 | var EVENT_TEST_ENDscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/EVENT_TEST_END. = constants.EVENT_TEST_END; |
| 24 | var inheritsscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/inherits. = require("../utils"scip-typescript npm mocha 11.7.7 lib/`utils.js`/).inherits; |
| 25 | var sprintfscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/sprintf. = utilscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/util..format; |
| 26 | |
| 27 | /** |
| 28 | * Expose `TAP`. |
| 29 | */ |
| 30 | |
| 31 | exportsscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/ = module.exports = TAPscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAP().; |
| 32 | |
| 33 | /** |
| 34 | * Constructs a new `TAP` reporter instance. |
| 35 | * |
| 36 | * @public |
| 37 | * @class |
| 38 | * @memberof Mocha.reporters |
| 39 | * @extends Mocha.reporters.Base |
| 40 | * @param {Runner} runner - Instance triggers reporter actions. |
| 41 | * @param {Object} [options] - runner options |
| 42 | */ |
| 43 | function TAPscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAP().(runnerscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAP().(runner), optionsscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAP().(options)) { |
| 44 | Basescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base()..callscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Function#call().(this, runnerscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAP().(runner), optionsscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAP().(options)); |
| 45 | |
| 46 | var self = this; |
| 47 | var n = 1; |
| 48 | |
| 49 | var tapVersion = "12"; |
| 50 | if (optionsscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAP().(options) && optionsscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAP().(options).reporterOptions) { |
| 51 | if (optionsscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAP().(options).reporterOptions.tapVersion) { |
| 52 | tapVersion = optionsscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAP().(options).reporterOptions.tapVersion.toString(); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | this._producer = createProducerscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/createProducer().(tapVersion); |
| 57 | |
| 58 | runnerscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAP().(runner).once(EVENT_RUN_BEGINscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/EVENT_RUN_BEGIN., function () { |
| 59 | self._producer.writeVersion(); |
| 60 | }); |
| 61 | |
| 62 | runnerscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAP().(runner).on(EVENT_TEST_ENDscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/EVENT_TEST_END., function () { |
| 63 | ++n; |
| 64 | }); |
| 65 | |
| 66 | runnerscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAP().(runner).on(EVENT_TEST_PENDINGscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/EVENT_TEST_PENDING., function (test) { |
| 67 | self._producer.writePending(n, test); |
| 68 | }); |
| 69 | |
| 70 | runnerscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAP().(runner).on(EVENT_TEST_PASSscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/EVENT_TEST_PASS., function (test) { |
| 71 | self._producer.writePass(n, test); |
| 72 | }); |
| 73 | |
| 74 | runnerscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAP().(runner).on(EVENT_TEST_FAILscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/EVENT_TEST_FAIL., function (test, err) { |
| 75 | self._producer.writeFail(n, test, err); |
| 76 | }); |
| 77 | |
| 78 | runnerscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAP().(runner).once(EVENT_RUN_ENDscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/EVENT_RUN_END., function () { |
| 79 | self._producer.writeEpilogue(runnerscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAP().(runner).stats); |
| 80 | }); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Inherit from `Base.prototype`. |
| 85 | */ |
| 86 | inheritsscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/inherits.(TAPscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAP()., Basescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base().); |
| 87 | |
| 88 | /** |
| 89 | * Returns a TAP-safe title of `test`. |
| 90 | * |
| 91 | * @private |
| 92 | * @param {Test} test - Test instance. |
| 93 | * @return {String} title with any hash character removed |
| 94 | */ |
| 95 | function titlescip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/title().(testscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/title().(test)) { |
| 96 | return testscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/title().(test).fullTitle().replace(/#/g, ""); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Writes newline-terminated formatted string to reporter output stream. |
| 101 | * |
| 102 | * @private |
| 103 | * @param {string} format - `printf`-like format string |
| 104 | * @param {...*} [varArgs] - Format string arguments |
| 105 | */ |
| 106 | function printlnscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/println().() { |
| 107 | var vargs = Arrayscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#.fromscip-typescript npm typescript 5.9.3 lib/`lib.es2015.core.d.ts`/ArrayConstructor#from().(arguments); |
| 108 | vargs[0] += "\n"; |
| 109 | process.stdout.write(sprintfscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/sprintf..apply(null, vargs)); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Returns a `tapVersion`-appropriate TAP producer instance, if possible. |
| 114 | * |
| 115 | * @private |
| 116 | * @param {string} tapVersion - Version of TAP specification to produce. |
| 117 | * @returns {TAPProducer} specification-appropriate instance |
| 118 | * @throws {Error} if specification version has no associated producer. |
| 119 | */ |
| 120 | function createProducerscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/createProducer().(tapVersionscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/createProducer().(tapVersion)) { |
| 121 | var producers = { |
| 122 | 12: new TAP12Producerscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAP12Producer().(), |
| 123 | 13: new TAP13Producerscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAP13Producer().(), |
| 124 | }; |
| 125 | var producer = producers[tapVersionscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/createProducer().(tapVersion)]; |
| 126 | |
| 127 | if (!producer) { |
| 128 | throw new Errorscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Error#( |
| 129 | "invalid or unsupported TAP version: " + JSONscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/JSON#.stringifyscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/JSON#stringify().(tapVersionscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/createProducer().(tapVersion)), |
| 130 | ); |
| 131 | } |
| 132 | |
| 133 | return producer; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * @summary |
| 138 | * Constructs a new TAPProducer. |
| 139 | * |
| 140 | * @description |
| 141 | * <em>Only</em> to be used as an abstract base class. |
| 142 | * |
| 143 | * @private |
| 144 | * @constructor |
| 145 | */ |
| 146 | function TAPProducerscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAPProducer().() {} |
| 147 | |
| 148 | /** |
| 149 | * Writes the TAP version to reporter output stream. |
| 150 | * |
| 151 | * @abstract |
| 152 | */ |
| 153 | TAPProducerscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAPProducer()..prototypescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Function#prototype..writeVersion = function () {}; |
| 154 | |
| 155 | /** |
| 156 | * Writes the plan to reporter output stream. |
| 157 | * |
| 158 | * @abstract |
| 159 | * @param {number} ntests - Number of tests that are planned to run. |
| 160 | */ |
| 161 | TAPProducerscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAPProducer()..prototypescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Function#prototype..writePlan = function (ntests) { |
| 162 | printlnscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/println().("%d..%d", 1, ntests); |
| 163 | }; |
| 164 | |
| 165 | /** |
| 166 | * Writes that test passed to reporter output stream. |
| 167 | * |
| 168 | * @abstract |
| 169 | * @param {number} n - Index of test that passed. |
| 170 | * @param {Test} test - Instance containing test information. |
| 171 | */ |
| 172 | TAPProducerscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAPProducer()..prototypescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Function#prototype..writePass = function (n, test) { |
| 173 | printlnscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/println().("ok %d %s", n, titlescip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/title().(test)); |
| 174 | }; |
| 175 | |
| 176 | /** |
| 177 | * Writes that test was skipped to reporter output stream. |
| 178 | * |
| 179 | * @abstract |
| 180 | * @param {number} n - Index of test that was skipped. |
| 181 | * @param {Test} test - Instance containing test information. |
| 182 | */ |
| 183 | TAPProducerscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAPProducer()..prototypescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Function#prototype..writePending = function (n, test) { |
| 184 | printlnscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/println().("ok %d %s # SKIP -", n, titlescip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/title().(test)); |
| 185 | }; |
| 186 | |
| 187 | /** |
| 188 | * Writes that test failed to reporter output stream. |
| 189 | * |
| 190 | * @abstract |
| 191 | * @param {number} n - Index of test that failed. |
| 192 | * @param {Test} test - Instance containing test information. |
| 193 | */ |
| 194 | TAPProducerscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAPProducer()..prototypescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Function#prototype..writeFail = function (n, test) { |
| 195 | printlnscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/println().("not ok %d %s", n, titlescip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/title().(test)); |
| 196 | }; |
| 197 | |
| 198 | /** |
| 199 | * Writes the summary epilogue to reporter output stream. |
| 200 | * |
| 201 | * @abstract |
| 202 | * @param {Object} stats - Object containing run statistics. |
| 203 | */ |
| 204 | TAPProducerscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAPProducer()..prototypescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Function#prototype..writeEpilogue = function (stats) { |
| 205 | // :TBD: Why is this not counting pending tests? |
| 206 | printlnscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/println().("# tests " + (stats.passes + stats.failures)); |
| 207 | printlnscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/println().("# pass " + stats.passes); |
| 208 | // :TBD: Why are we not showing pending results? |
| 209 | printlnscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/println().("# fail " + stats.failures); |
| 210 | this.writePlan(stats.passes + stats.failures + stats.pending); |
| 211 | }; |
| 212 | |
| 213 | /** |
| 214 | * @summary |
| 215 | * Constructs a new TAP12Producer. |
| 216 | * |
| 217 | * @description |
| 218 | * Produces output conforming to the TAP12 specification. |
| 219 | * |
| 220 | * @private |
| 221 | * @constructor |
| 222 | * @extends TAPProducer |
| 223 | * @see {@link https://testanything.org/tap-specification.html|Specification} |
| 224 | */ |
| 225 | function TAP12Producerscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAP12Producer().() { |
| 226 | /** |
| 227 | * Writes that test failed to reporter output stream, with error formatting. |
| 228 | * @override |
| 229 | */ |
| 230 | this.writeFail = function (n, test, err) { |
| 231 | TAPProducerscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAPProducer()..prototypescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Function#prototype..writeFail.call(this, n, test, err); |
| 232 | if (err.message) { |
| 233 | printlnscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/println().(err.message.replace(/^/gm, " ")); |
| 234 | } |
| 235 | if (err.stack) { |
| 236 | printlnscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/println().(err.stack.replace(/^/gm, " ")); |
| 237 | } |
| 238 | }; |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * Inherit from `TAPProducer.prototype`. |
| 243 | */ |
| 244 | inheritsscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/inherits.(TAP12Producerscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAP12Producer()., TAPProducerscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAPProducer().); |
| 245 | |
| 246 | /** |
| 247 | * @summary |
| 248 | * Constructs a new TAP13Producer. |
| 249 | * |
| 250 | * @description |
| 251 | * Produces output conforming to the TAP13 specification. |
| 252 | * |
| 253 | * @private |
| 254 | * @constructor |
| 255 | * @extends TAPProducer |
| 256 | * @see {@link https://testanything.org/tap-version-13-specification.html|Specification} |
| 257 | */ |
| 258 | function TAP13Producerscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAP13Producer().() { |
| 259 | /** |
| 260 | * Writes the TAP version to reporter output stream. |
| 261 | * @override |
| 262 | */ |
| 263 | this.writeVersion = function () { |
| 264 | printlnscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/println().("TAP version 13"); |
| 265 | }; |
| 266 | |
| 267 | /** |
| 268 | * Writes that test failed to reporter output stream, with error formatting. |
| 269 | * @override |
| 270 | */ |
| 271 | this.writeFail = function (n, test, err) { |
| 272 | TAPProducerscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAPProducer()..prototypescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Function#prototype..writeFail.call(this, n, test, err); |
| 273 | var emitYamlBlock = err.message != null || err.stack != null; |
| 274 | if (emitYamlBlock) { |
| 275 | printlnscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/println().(indent(1) + "---"); |
| 276 | if (err.message) { |
| 277 | printlnscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/println().(indent(2) + "message: |-"); |
| 278 | printlnscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/println().(err.message.replace(/^/gm, indent(3))); |
| 279 | } |
| 280 | if (err.stack) { |
| 281 | printlnscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/println().(indent(2) + "stack: |-"); |
| 282 | printlnscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/println().(err.stack.replace(/^/gm, indent(3))); |
| 283 | } |
| 284 | printlnscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/println().(indent(1) + "..."); |
| 285 | } |
| 286 | }; |
| 287 | |
| 288 | function indent(level) { |
| 289 | return Arrayscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#(level + 1).joinscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#join().(" "); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * Inherit from `TAPProducer.prototype`. |
| 295 | */ |
| 296 | inheritsscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/inherits.(TAP13Producerscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAP13Producer()., TAPProducerscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAPProducer().); |
| 297 | |
| 298 | TAPscip-typescript npm mocha 11.7.7 lib/reporters/`tap.js`/TAP()..description = "TAP-compatible output"; |