| 1 | "use strict"; |
| 2 | |
| 3 | /** |
| 4 | * @typedef {import('../runner.js')} Runner |
| 5 | * @typedef {import('../test.js')} Test |
| 6 | * @typedef {import('../types.d.ts').FullErrorStack} FullErrorStack |
| 7 | */ |
| 8 | |
| 9 | /** |
| 10 | * @module Base |
| 11 | */ |
| 12 | /** |
| 13 | * Module dependencies. |
| 14 | */ |
| 15 | |
| 16 | var diffscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/diff. = require("diff"); |
| 17 | var millisecondsscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/milliseconds. = require("ms"); |
| 18 | var utilsscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/utils. = require("../utils"scip-typescript npm mocha 11.7.7 lib/`utils.js`/); |
| 19 | var supportsColorscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/supportsColor. = require("supports-color"); |
| 20 | var symbolsscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/symbols. = require("log-symbols"); |
| 21 | var constantsscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/constants. = require("../runner"scip-typescript npm mocha 11.7.7 lib/`runner.js`/).constants; |
| 22 | var EVENT_TEST_PASSscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/EVENT_TEST_PASS. = constants.EVENT_TEST_PASS; |
| 23 | var EVENT_TEST_FAILscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/EVENT_TEST_FAIL. = constants.EVENT_TEST_FAIL; |
| 24 | |
| 25 | const isBrowserscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/isBrowser. = utilsscip-typescript npm mocha 11.7.7 lib/`utils.js`/.isBrowser(); |
| 26 | |
| 27 | function getBrowserWindowSizescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/getBrowserWindowSize().() { |
| 28 | if ("innerHeight" in global) { |
| 29 | return [global.innerHeight, global.innerWidth]; |
| 30 | } |
| 31 | // In a Web Worker, the DOM Window is not available. |
| 32 | return [640, 480]; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Expose `Base`. |
| 37 | */ |
| 38 | |
| 39 | exportsscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/ = module.exports = Basescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base().; |
| 40 | |
| 41 | /** |
| 42 | * Check if both stdio streams are associated with a tty. |
| 43 | */ |
| 44 | |
| 45 | var isattyscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/isatty. = isBrowserscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/isBrowser. || (process.stdout.isTTY && process.stderr.isTTY); |
| 46 | |
| 47 | /** |
| 48 | * Save log references to avoid tests interfering (see GH-3604). |
| 49 | */ |
| 50 | var consoleLogscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/consoleLog. = consolescip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/console..logscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Console#log().; |
| 51 | |
| 52 | /** |
| 53 | * Enable coloring by default, except in the browser interface. |
| 54 | */ |
| 55 | |
| 56 | exports.useColors = |
| 57 | !isBrowserscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/isBrowser. && |
| 58 | (supportsColorscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/supportsColor..stdout || process.env.MOCHA_COLORS !== undefined); |
| 59 | |
| 60 | /** |
| 61 | * Inline diffs instead of +/- |
| 62 | */ |
| 63 | |
| 64 | exports.inlineDiffs = false; |
| 65 | |
| 66 | /** |
| 67 | * Truncate diffs longer than this value to avoid slow performance |
| 68 | */ |
| 69 | exports.maxDiffSize = 8192; |
| 70 | |
| 71 | /** |
| 72 | * Default color map. |
| 73 | */ |
| 74 | |
| 75 | exports.colors = { |
| 76 | passscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/pass0:: 90, |
| 77 | failscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/fail0:: 31, |
| 78 | "bright pass"scip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/`"bright pass"0`:: 92, |
| 79 | "bright fail"scip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/`"bright fail"0`:: 91, |
| 80 | "bright yellow"scip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/`"bright yellow"0`:: 93, |
| 81 | pendingscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/pending0:: 36, |
| 82 | suitescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/suite0:: 0, |
| 83 | "error title"scip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/`"error title"0`:: 0, |
| 84 | "error message"scip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/`"error message"0`:: 31, |
| 85 | "error stack"scip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/`"error stack"0`:: 90, |
| 86 | checkmarkscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/checkmark0:: 32, |
| 87 | fastscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/fast0:: 90, |
| 88 | mediumscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/medium0:: 33, |
| 89 | slowscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/slow0:: 31, |
| 90 | greenscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/green0:: 32, |
| 91 | lightscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/light0:: 90, |
| 92 | "diff gutter"scip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/`"diff gutter"0`:: 90, |
| 93 | "diff added"scip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/`"diff added"0`:: 32, |
| 94 | "diff removed"scip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/`"diff removed"0`:: 31, |
| 95 | "diff added inline"scip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/`"diff added inline"0`:: "30;42", |
| 96 | "diff removed inline"scip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/`"diff removed inline"0`:: "30;41", |
| 97 | }; |
| 98 | |
| 99 | /** |
| 100 | * Default symbol map. |
| 101 | */ |
| 102 | |
| 103 | exports.symbols = { |
| 104 | okscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/ok0:: symbolsscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/symbols..success, |
| 105 | errscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/err0:: symbolsscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/symbols..error, |
| 106 | dotscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/dot0:: ".", |
| 107 | commascip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/comma0:: ",", |
| 108 | bangscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/bang0:: "!", |
| 109 | }; |
| 110 | |
| 111 | /** |
| 112 | * Color `str` with the given `type`, |
| 113 | * allowing colors to be disabled, |
| 114 | * as well as user-defined color |
| 115 | * schemes. |
| 116 | * |
| 117 | * @private |
| 118 | * @param {string} type |
| 119 | * @param {string} str |
| 120 | * @return {string} |
| 121 | */ |
| 122 | var colorscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/color. = (exports.color = function (type, str) { |
| 123 | if (!exportsscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/.useColors) { |
| 124 | return Stringscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/String#(str); |
| 125 | } |
| 126 | return "\u001b[" + exportsscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/.colors[type] + "m" + str + "\u001b[0m"; |
| 127 | }); |
| 128 | |
| 129 | /** |
| 130 | * Expose term window size, with some defaults for when stderr is not a tty. |
| 131 | */ |
| 132 | |
| 133 | exports.window = { |
| 134 | widthscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/width0:: 75, |
| 135 | }; |
| 136 | |
| 137 | if (isattyscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/isatty.) { |
| 138 | if (isBrowserscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/isBrowser.) { |
| 139 | exportsscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/.window.width = getBrowserWindowSizescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/getBrowserWindowSize().()[1]; |
| 140 | } else { |
| 141 | exportsscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/.window.width = process.stdout.getWindowSize(1)[0]; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Expose some basic cursor interactions that are common among reporters. |
| 147 | */ |
| 148 | |
| 149 | exports.cursor = { |
| 150 | hidescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/hide0:: function () { |
| 151 | isattyscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/isatty. && process.stdout.write("\u001b[?25l"); |
| 152 | }, |
| 153 | |
| 154 | showscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/show0:: function () { |
| 155 | isattyscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/isatty. && process.stdout.write("\u001b[?25h"); |
| 156 | }, |
| 157 | |
| 158 | deleteLinescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/deleteLine0:: function () { |
| 159 | isattyscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/isatty. && process.stdout.write("\u001b[2K"); |
| 160 | }, |
| 161 | |
| 162 | beginningOfLinescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/beginningOfLine0:: function () { |
| 163 | isattyscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/isatty. && process.stdout.write("\u001b[0G"); |
| 164 | }, |
| 165 | |
| 166 | CRscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/CR0:: function () { |
| 167 | if (isattyscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/isatty.) { |
| 168 | exportsscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/.cursor.deleteLinescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/deleteLine0:(); |
| 169 | exportsscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/.cursor.beginningOfLinescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/beginningOfLine0:(); |
| 170 | } else { |
| 171 | process.stdout.write("\r"); |
| 172 | } |
| 173 | }, |
| 174 | }; |
| 175 | |
| 176 | var showDiffscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/showDiff. = (exports.showDiff = function (err) { |
| 177 | return ( |
| 178 | err && |
| 179 | err.showDiff !== false && |
| 180 | sameTypescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/sameType().(err.actual, err.expected) && |
| 181 | err.expected !== undefined |
| 182 | ); |
| 183 | }); |
| 184 | |
| 185 | function stringifyDiffObjsscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/stringifyDiffObjs().(errscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/stringifyDiffObjs().(err)) { |
| 186 | if (!utilsscip-typescript npm mocha 11.7.7 lib/`utils.js`/.isString(errscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/stringifyDiffObjs().(err).actual) || !utilsscip-typescript npm mocha 11.7.7 lib/`utils.js`/.isString(errscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/stringifyDiffObjs().(err).expected)) { |
| 187 | errscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/stringifyDiffObjs().(err).actual = utilsscip-typescript npm mocha 11.7.7 lib/`utils.js`/.stringify(errscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/stringifyDiffObjs().(err).actual); |
| 188 | errscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/stringifyDiffObjs().(err).expected = utilsscip-typescript npm mocha 11.7.7 lib/`utils.js`/.stringify(errscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/stringifyDiffObjs().(err).expected); |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Returns a diff between 2 strings with coloured ANSI output. |
| 194 | * |
| 195 | * @description |
| 196 | * The diff will be either inline or unified dependent on the value |
| 197 | * of `Base.inlineDiff`. |
| 198 | * |
| 199 | * @param {string} actual |
| 200 | * @param {string} expected |
| 201 | * @return {string} Diff |
| 202 | */ |
| 203 | |
| 204 | var generateDiffscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/generateDiff. = (exports.generateDiff = function (actual, expected) { |
| 205 | try { |
| 206 | var maxLen = exportsscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/.maxDiffSize; |
| 207 | var skipped = 0; |
| 208 | if (maxLen > 0) { |
| 209 | skipped = Mathscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Math#.maxscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Math#max().(actual.lengthscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/String#length. - maxLen, expected.lengthscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/String#length. - maxLen); |
| 210 | actual = actual.slicescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/String#slice().(0, maxLen); |
| 211 | expected = expected.slicescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/String#slice().(0, maxLen); |
| 212 | } |
| 213 | let result = exportsscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/.inlineDiffs |
| 214 | ? inlineDiffscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/inlineDiff().(actual, expected) |
| 215 | : unifiedDiffscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/unifiedDiff().(actual, expected); |
| 216 | if (skipped > 0) { |
| 217 | result = `${result}\n [mocha] output truncated to ${maxLen} characters, see "maxDiffSize" reporter-option\n`; |
| 218 | } |
| 219 | return result; |
| 220 | } catch (err) { |
| 221 | var msg = |
| 222 | "\n " + |
| 223 | colorscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/color.("diff added", "+ expected") + |
| 224 | " " + |
| 225 | colorscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/color.("diff removed", "- actual: failed to generate Mocha diff") + |
| 226 | "\n"; |
| 227 | return msg; |
| 228 | } |
| 229 | }); |
| 230 | |
| 231 | /** |
| 232 | * Traverses err.cause and returns all stack traces |
| 233 | * |
| 234 | * @private |
| 235 | * @param {Error} err |
| 236 | * @param {Set<Error>} [seen] |
| 237 | * @return {FullErrorStack} |
| 238 | */ |
| 239 | var getFullErrorStackscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/getFullErrorStack. = function (err, seen) { |
| 240 | if (seen && seen.hasscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Set#has().(err)) { |
| 241 | return { messagescip-typescript npm mocha 11.7.7 lib/`types.d.ts`/FullErrorStack#message.: "", msgscip-typescript npm mocha 11.7.7 lib/`types.d.ts`/FullErrorStack#msg.: "<circular>", stackscip-typescript npm mocha 11.7.7 lib/`types.d.ts`/FullErrorStack#stack.: "" }; |
| 242 | } |
| 243 | |
| 244 | var message; |
| 245 | |
| 246 | if (typeof err.inspect === "function") { |
| 247 | message = err.inspect() + ""; |
| 248 | } else if (err.messagescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Error#message. && typeof err.messagescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Error#message..toStringscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/String#toString(). === "function") { |
| 249 | message = err.messagescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Error#message. + ""; |
| 250 | } else { |
| 251 | message = ""; |
| 252 | } |
| 253 | |
| 254 | var msg; |
| 255 | var stack = err.stackscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Error#stack. || message; |
| 256 | var index = message ? stack.indexOfscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/String#indexOf().(message) : -1; |
| 257 | |
| 258 | if (index === -1) { |
| 259 | msg = message; |
| 260 | } else { |
| 261 | index += message.lengthscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/String#length.; |
| 262 | msg = stack.slicescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/String#slice().(0, index); |
| 263 | // remove msg from stack |
| 264 | stack = stack.slicescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/String#slice().(index + 1); |
| 265 | |
| 266 | if (err.causescip-typescript npm typescript 5.9.3 lib/`lib.es2022.error.d.ts`/Error#cause.) { |
| 267 | seen = seen || new Setscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Set#(); |
| 268 | seen.addscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Set#add().(err); |
| 269 | const causeStack = getFullErrorStackscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/getFullErrorStack.(err.causescip-typescript npm typescript 5.9.3 lib/`lib.es2022.error.d.ts`/Error#cause., seen); |
| 270 | stack += |
| 271 | "\n Caused by: " + |
| 272 | causeStack.msgscip-typescript npm mocha 11.7.7 lib/`types.d.ts`/FullErrorStack#msg. + |
| 273 | (causeStack.stackscip-typescript npm mocha 11.7.7 lib/`types.d.ts`/FullErrorStack#stack. ? "\n" + causeStack.stackscip-typescript npm mocha 11.7.7 lib/`types.d.ts`/FullErrorStack#stack. : ""); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | return { |
| 278 | messagescip-typescript npm mocha 11.7.7 lib/`types.d.ts`/FullErrorStack#message., |
| 279 | msgscip-typescript npm mocha 11.7.7 lib/`types.d.ts`/FullErrorStack#msg., |
| 280 | stackscip-typescript npm mocha 11.7.7 lib/`types.d.ts`/FullErrorStack#stack., |
| 281 | }; |
| 282 | }; |
| 283 | |
| 284 | /** |
| 285 | * Outputs the given `failures` as a list. |
| 286 | * |
| 287 | * @public |
| 288 | * @memberof Mocha.reporters.Base |
| 289 | * @variation 1 |
| 290 | * @param {Object[]} failures - Each is Test instance with corresponding |
| 291 | * Error property |
| 292 | */ |
| 293 | exports.list = function (failures) { |
| 294 | var multipleErr, multipleTest; |
| 295 | Basescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base()..consoleLog(); |
| 296 | failures.forEachscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#forEach().(function (test, i) { |
| 297 | // format |
| 298 | var fmt = |
| 299 | colorscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/color.("error title", " %s) %s:\n") + |
| 300 | colorscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/color.("error message", " %s") + |
| 301 | colorscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/color.("error stack", "\n%s\n"); |
| 302 | |
| 303 | // msg |
| 304 | var err; |
| 305 | if (test.err && test.err.multiple) { |
| 306 | if (multipleTest !== test) { |
| 307 | multipleTest = test; |
| 308 | multipleErr = [test.err].concatscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#concat().(test.err.multiple); |
| 309 | } |
| 310 | err = multipleErr.shift(); |
| 311 | } else { |
| 312 | err = test.err; |
| 313 | } |
| 314 | |
| 315 | var { messagescip-typescript npm mocha 11.7.7 lib/`types.d.ts`/FullErrorStack#message., msgscip-typescript npm mocha 11.7.7 lib/`types.d.ts`/FullErrorStack#msg., stackscip-typescript npm mocha 11.7.7 lib/`types.d.ts`/FullErrorStack#stack. } = getFullErrorStackscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/getFullErrorStack.(err); |
| 316 | |
| 317 | // uncaught |
| 318 | if (err.uncaught) { |
| 319 | msg = "Uncaught " + msg; |
| 320 | } |
| 321 | // explicitly show diff |
| 322 | if (!exportsscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/.hideDiff && showDiffscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/showDiff.(err)) { |
| 323 | stringifyDiffObjsscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/stringifyDiffObjs().(err); |
| 324 | fmt = |
| 325 | colorscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/color.("error title", " %s) %s:\n%s") + colorscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/color.("error stack", "\n%s\n"); |
| 326 | var match = message.matchscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/String#match().(/^([^:]+): expected/); |
| 327 | msg = "\n " + colorscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/color.("error message", match ? match[1] : msg); |
| 328 | |
| 329 | msg += generateDiffscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/generateDiff.(err.actual, err.expected); |
| 330 | } |
| 331 | |
| 332 | // indent stack trace |
| 333 | stack = stack.replacescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/String#replace().(/^/gm, " "); |
| 334 | |
| 335 | // indented test title |
| 336 | var testTitle = ""; |
| 337 | test.titlePath().forEach(function (str, index) { |
| 338 | if (index !== 0) { |
| 339 | testTitle += "\n "; |
| 340 | } |
| 341 | for (var i = 0; i < index; i++) { |
| 342 | testTitle += " "; |
| 343 | } |
| 344 | testTitle += str; |
| 345 | }); |
| 346 | |
| 347 | Basescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base()..consoleLog(fmt, i + 1, testTitle, msg, stack); |
| 348 | }); |
| 349 | }; |
| 350 | |
| 351 | /** |
| 352 | * Constructs a new `Base` reporter instance. |
| 353 | * |
| 354 | * @description |
| 355 | * All other reporters generally inherit from this reporter. |
| 356 | * |
| 357 | * @public |
| 358 | * @class |
| 359 | * @memberof Mocha.reporters |
| 360 | * @param {Runner} runner - Instance triggers reporter actions. |
| 361 | * @param {Object} [options] - runner options |
| 362 | */ |
| 363 | function Basescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base().(runnerscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base().(runner), optionsscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base().(options)) { |
| 364 | var failures = (this.failures = []); |
| 365 | |
| 366 | if (!runnerscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base().(runner)) { |
| 367 | throw new TypeErrorscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/TypeError#("Missing runner argument"); |
| 368 | } |
| 369 | this.options = optionsscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base().(options) || {}; |
| 370 | this.runner = runnerscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base().(runner); |
| 371 | this.stats = runnerscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base().(runner).stats; // assigned so Reporters keep a closer reference |
| 372 | |
| 373 | var maxDiffSizeOpt = |
| 374 | this.options.reporterOption && this.options.reporterOption.maxDiffSize; |
| 375 | if (maxDiffSizeOpt !== undefined && !isNaNscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/isNaN().(Numberscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Number#(maxDiffSizeOpt))) { |
| 376 | exports.maxDiffSize = Numberscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Number#(maxDiffSizeOpt); |
| 377 | } |
| 378 | |
| 379 | runnerscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base().(runner).on(EVENT_TEST_PASSscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/EVENT_TEST_PASS., function (test) { |
| 380 | if (test.duration > test.slow()) { |
| 381 | test.speed = "slow"; |
| 382 | } else if (test.duration > test.slow() / 2) { |
| 383 | test.speed = "medium"; |
| 384 | } else { |
| 385 | test.speed = "fast"; |
| 386 | } |
| 387 | }); |
| 388 | |
| 389 | runnerscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base().(runner).on(EVENT_TEST_FAILscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/EVENT_TEST_FAIL., function (test, err) { |
| 390 | if (showDiffscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/showDiff.(err)) { |
| 391 | stringifyDiffObjsscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/stringifyDiffObjs().(err); |
| 392 | } |
| 393 | // more than one error per test |
| 394 | if (test.err && err instanceof Errorscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Error#) { |
| 395 | test.err.multiple = (test.err.multiple || []).concat(err); |
| 396 | } else { |
| 397 | test.err = err; |
| 398 | } |
| 399 | failures.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(test); |
| 400 | }); |
| 401 | } |
| 402 | |
| 403 | /** |
| 404 | * Outputs common epilogue used by many of the bundled reporters. |
| 405 | * |
| 406 | * @public |
| 407 | * @memberof Mocha.reporters |
| 408 | */ |
| 409 | Basescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base()..prototypescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Function#prototype..epilogue = function () { |
| 410 | var stats = this.stats; |
| 411 | var fmt; |
| 412 | |
| 413 | Basescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base()..consoleLog(); |
| 414 | |
| 415 | // passes |
| 416 | fmt = |
| 417 | colorscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/color.("bright pass", " ") + |
| 418 | colorscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/color.("green", " %d passing") + |
| 419 | colorscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/color.("light", " (%s)"); |
| 420 | |
| 421 | Basescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base()..consoleLog(fmt, stats.passes || 0, millisecondsscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/milliseconds.(stats.duration)); |
| 422 | |
| 423 | // pending |
| 424 | if (stats.pending) { |
| 425 | fmt = colorscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/color.("pending", " ") + colorscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/color.("pending", " %d pending"); |
| 426 | |
| 427 | Basescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base()..consoleLog(fmt, stats.pending); |
| 428 | } |
| 429 | |
| 430 | // failures |
| 431 | if (stats.failures) { |
| 432 | fmt = colorscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/color.("fail", " %d failing"); |
| 433 | |
| 434 | Basescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base()..consoleLog(fmt, stats.failures); |
| 435 | |
| 436 | Basescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base()..list(this.failures); |
| 437 | Basescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base()..consoleLog(); |
| 438 | } |
| 439 | |
| 440 | Basescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base()..consoleLog(); |
| 441 | }; |
| 442 | |
| 443 | /** |
| 444 | * Pads the given `str` to `len`. |
| 445 | * |
| 446 | * @private |
| 447 | * @param {string} str |
| 448 | * @param {string} len |
| 449 | * @return {string} |
| 450 | */ |
| 451 | function padscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/pad().(strscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/pad().(str), lenscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/pad().(len)) { |
| 452 | strscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/pad().(str) = Stringscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/String#(strscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/pad().(str)); |
| 453 | return Arrayscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#(lenscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/pad().(len) - strscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/pad().(str).lengthscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/String#length. + 1).joinscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#join().(" ") + strscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/pad().(str); |
| 454 | } |
| 455 | |
| 456 | /** |
| 457 | * Returns inline diff between 2 strings with coloured ANSI output. |
| 458 | * |
| 459 | * @private |
| 460 | * @param {String} actual |
| 461 | * @param {String} expected |
| 462 | * @return {string} Diff |
| 463 | */ |
| 464 | function inlineDiffscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/inlineDiff().(actualscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/inlineDiff().(actual), expectedscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/inlineDiff().(expected)) { |
| 465 | var msg = errorDiffscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/errorDiff().(actualscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/inlineDiff().(actual), expectedscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/inlineDiff().(expected)); |
| 466 | |
| 467 | // linenos |
| 468 | var lines = msg.splitscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/String#split().("\n"); |
| 469 | if (lines.lengthscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#length. > 4) { |
| 470 | var width = Stringscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/String#(lines.lengthscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#length.).lengthscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/String#length.; |
| 471 | msg = lines |
| 472 | .mapscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#map().(function (str, i) { |
| 473 | return padscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/pad().(++i, width) + " |" + " " + str; |
| 474 | }) |
| 475 | .joinscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#join().("\n"); |
| 476 | } |
| 477 | |
| 478 | // legend |
| 479 | msg = |
| 480 | "\n" + |
| 481 | colorscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/color.("diff removed inline", "actual") + |
| 482 | " " + |
| 483 | colorscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/color.("diff added inline", "expected") + |
| 484 | "\n\n" + |
| 485 | msg + |
| 486 | "\n"; |
| 487 | |
| 488 | // indent |
| 489 | msg = msg.replacescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/String#replace().(/^/gm, " "); |
| 490 | return msg; |
| 491 | } |
| 492 | |
| 493 | /** |
| 494 | * Returns unified diff between two strings with coloured ANSI output. |
| 495 | * |
| 496 | * @private |
| 497 | * @param {String} actual |
| 498 | * @param {String} expected |
| 499 | * @return {string} The diff. |
| 500 | */ |
| 501 | function unifiedDiffscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/unifiedDiff().(actualscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/unifiedDiff().(actual), expectedscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/unifiedDiff().(expected)) { |
| 502 | var indent = " "; |
| 503 | function cleanUp(line) { |
| 504 | if (line[0] === "+") { |
| 505 | return indent + colorLinesscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/colorLines().("diff added", line); |
| 506 | } |
| 507 | if (line[0] === "-") { |
| 508 | return indent + colorLinesscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/colorLines().("diff removed", line); |
| 509 | } |
| 510 | if (line.match(/@@/)) { |
| 511 | return "--"; |
| 512 | } |
| 513 | if (line.match(/\\ No newline/)) { |
| 514 | return null; |
| 515 | } |
| 516 | return indent + line; |
| 517 | } |
| 518 | function notBlank(line) { |
| 519 | return typeof line !== "undefined" && line !== null; |
| 520 | } |
| 521 | var msg = diffscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/diff..createPatch("string", actualscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/unifiedDiff().(actual), expectedscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/unifiedDiff().(expected)); |
| 522 | var lines = msg.split("\n").splice(5); |
| 523 | return ( |
| 524 | "\n " + |
| 525 | colorLinesscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/colorLines().("diff added", "+ expected") + |
| 526 | " " + |
| 527 | colorLinesscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/colorLines().("diff removed", "- actual") + |
| 528 | "\n\n" + |
| 529 | lines.map(cleanUp).filter(notBlank).join("\n") |
| 530 | ); |
| 531 | } |
| 532 | |
| 533 | /** |
| 534 | * Returns character diff for `err`. |
| 535 | * |
| 536 | * @private |
| 537 | * @param {String} actual |
| 538 | * @param {String} expected |
| 539 | * @return {string} the diff |
| 540 | */ |
| 541 | function errorDiffscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/errorDiff().(actualscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/errorDiff().(actual), expectedscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/errorDiff().(expected)) { |
| 542 | return diffscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/diff. |
| 543 | .diffWordsWithSpace(actualscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/errorDiff().(actual), expectedscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/errorDiff().(expected)) |
| 544 | .map(function (str) { |
| 545 | if (str.added) { |
| 546 | return colorLinesscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/colorLines().("diff added inline", str.value); |
| 547 | } |
| 548 | if (str.removed) { |
| 549 | return colorLinesscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/colorLines().("diff removed inline", str.value); |
| 550 | } |
| 551 | return str.value; |
| 552 | }) |
| 553 | .join(""); |
| 554 | } |
| 555 | |
| 556 | /** |
| 557 | * Colors lines for `str`, using the color `name`. |
| 558 | * |
| 559 | * @private |
| 560 | * @param {string} name |
| 561 | * @param {string} str |
| 562 | * @return {string} |
| 563 | */ |
| 564 | function colorLinesscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/colorLines().(namescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/colorLines().(name), strscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/colorLines().(str)) { |
| 565 | return strscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/colorLines().(str) |
| 566 | .splitscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/String#split().("\n") |
| 567 | .mapscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#map().(function (str) { |
| 568 | return colorscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/color.(namescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/colorLines().(name), str); |
| 569 | }) |
| 570 | .joinscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#join().("\n"); |
| 571 | } |
| 572 | |
| 573 | /** |
| 574 | * Object#toString reference. |
| 575 | */ |
| 576 | var objToStringscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/objToString. = Objectscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Object#.prototypescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/ObjectConstructor#prototype..toStringscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Object#toString().; |
| 577 | |
| 578 | /** |
| 579 | * Checks that a / b have the same type. |
| 580 | * |
| 581 | * @private |
| 582 | * @param {Object} a |
| 583 | * @param {Object} b |
| 584 | * @return {boolean} |
| 585 | */ |
| 586 | function sameTypescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/sameType().(ascip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/sameType().(a), bscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/sameType().(b)) { |
| 587 | return objToStringscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/objToString..callscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Function#call().(ascip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/sameType().(a)) === objToStringscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/objToString..callscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Function#call().(bscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/sameType().(b)); |
| 588 | } |
| 589 | |
| 590 | Basescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base()..consoleLog = consoleLogscip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/consoleLog.; |
| 591 | |
| 592 | Basescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base()..abstract = true; |