mocha 11.7.4 → 11.7.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/_mocha +2 -2
- package/bin/mocha.js +46 -44
- package/browser-entry.js +20 -20
- package/index.js +2 -2
- package/lib/browser/highlight-tags.js +6 -6
- package/lib/browser/parse-query.js +5 -5
- package/lib/browser/template.html +2 -2
- package/lib/cli/cli.js +32 -27
- package/lib/cli/collect-files.js +25 -25
- package/lib/cli/commands.js +4 -4
- package/lib/cli/config.js +26 -25
- package/lib/cli/index.js +2 -2
- package/lib/cli/init.js +19 -19
- package/lib/cli/lookup-files.js +20 -20
- package/lib/cli/node-flags.js +12 -12
- package/lib/cli/one-and-dones.js +12 -11
- package/lib/cli/options.js +49 -49
- package/lib/cli/run-helpers.js +52 -54
- package/lib/cli/run-option-metadata.js +75 -75
- package/lib/cli/run.js +164 -159
- package/lib/cli/watch-run.js +75 -75
- package/lib/context.js +1 -1
- package/lib/error-constants.js +17 -17
- package/lib/errors.js +26 -26
- package/lib/hook.js +9 -9
- package/lib/interfaces/bdd.js +8 -8
- package/lib/interfaces/common.js +12 -12
- package/lib/interfaces/exports.js +8 -8
- package/lib/interfaces/index.js +5 -5
- package/lib/interfaces/qunit.js +7 -7
- package/lib/interfaces/tdd.js +7 -7
- package/lib/mocha.js +97 -97
- package/lib/nodejs/buffered-worker-pool.js +30 -30
- package/lib/nodejs/esm-utils.js +24 -21
- package/lib/nodejs/file-unloader.js +2 -2
- package/lib/nodejs/parallel-buffered-runner.js +67 -67
- package/lib/nodejs/reporters/parallel-buffered.js +13 -10
- package/lib/nodejs/serializer.js +47 -47
- package/lib/nodejs/worker.js +38 -38
- package/lib/pending.js +1 -1
- package/lib/plugin-loader.js +48 -48
- package/lib/reporters/base.js +97 -94
- package/lib/reporters/doc.js +17 -17
- package/lib/reporters/dot.js +14 -14
- package/lib/reporters/html.js +73 -67
- package/lib/reporters/index.js +16 -16
- package/lib/reporters/json-stream.js +10 -10
- package/lib/reporters/json.js +16 -16
- package/lib/reporters/landing.js +20 -20
- package/lib/reporters/list.js +10 -10
- package/lib/reporters/markdown.js +21 -21
- package/lib/reporters/min.js +7 -7
- package/lib/reporters/nyan.js +35 -35
- package/lib/reporters/progress.js +14 -14
- package/lib/reporters/spec.js +15 -15
- package/lib/reporters/tap.js +26 -26
- package/lib/reporters/xunit.js +38 -34
- package/lib/runnable.js +41 -41
- package/lib/runner.js +105 -105
- package/lib/stats-collector.js +4 -4
- package/lib/suite.js +56 -46
- package/lib/test.js +10 -10
- package/lib/utils.js +122 -122
- package/mocha.css +68 -50
- package/mocha.js +826 -803
- package/mocha.js.map +1 -1
- package/package.json +8 -13
package/lib/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Various utility functions used throughout Mocha's codebase.
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
/**
|
|
9
9
|
* Module dependencies.
|
|
10
10
|
*/
|
|
11
|
-
var path = require(
|
|
12
|
-
var util = require(
|
|
13
|
-
var he = require(
|
|
11
|
+
var path = require("node:path");
|
|
12
|
+
var util = require("node:util");
|
|
13
|
+
var he = require("he");
|
|
14
14
|
|
|
15
|
-
const MOCHA_ID_PROP_NAME =
|
|
15
|
+
const MOCHA_ID_PROP_NAME = "__mocha_id__";
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Inherit the prototype methods from one constructor into another.
|
|
@@ -33,7 +33,7 @@ exports.inherits = util.inherits;
|
|
|
33
33
|
* @return {string}
|
|
34
34
|
*/
|
|
35
35
|
exports.escape = function (html) {
|
|
36
|
-
return he.encode(String(html), {useNamedReferences: false});
|
|
36
|
+
return he.encode(String(html), { useNamedReferences: false });
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
/**
|
|
@@ -44,7 +44,7 @@ exports.escape = function (html) {
|
|
|
44
44
|
* @return {boolean}
|
|
45
45
|
*/
|
|
46
46
|
exports.isString = function (obj) {
|
|
47
|
-
return typeof obj ===
|
|
47
|
+
return typeof obj === "string";
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
/**
|
|
@@ -57,9 +57,9 @@ exports.isString = function (obj) {
|
|
|
57
57
|
exports.slug = function (str) {
|
|
58
58
|
return str
|
|
59
59
|
.toLowerCase()
|
|
60
|
-
.replace(/\s+/g,
|
|
61
|
-
.replace(/[^-\w]/g,
|
|
62
|
-
.replace(/-{2,}/g,
|
|
60
|
+
.replace(/\s+/g, "-")
|
|
61
|
+
.replace(/[^-\w]/g, "")
|
|
62
|
+
.replace(/-{2,}/g, "-");
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
/**
|
|
@@ -70,22 +70,22 @@ exports.slug = function (str) {
|
|
|
70
70
|
*/
|
|
71
71
|
exports.clean = function (str) {
|
|
72
72
|
str = str
|
|
73
|
-
.replace(/\r\n?|[\n\u2028\u2029]/g,
|
|
74
|
-
.replace(/^\uFEFF/,
|
|
73
|
+
.replace(/\r\n?|[\n\u2028\u2029]/g, "\n")
|
|
74
|
+
.replace(/^\uFEFF/, "")
|
|
75
75
|
// (traditional)-> space/name parameters body (lambda)-> parameters body multi-statement/single keep body content
|
|
76
76
|
.replace(
|
|
77
77
|
/^function(?:\s*|\s[^(]*)\([^)]*\)\s*\{((?:.|\n)*?)\}$|^\([^)]*\)\s*=>\s*(?:\{((?:.|\n)*?)\}|((?:.|\n)*))$/,
|
|
78
|
-
|
|
78
|
+
"$1$2$3",
|
|
79
79
|
);
|
|
80
80
|
|
|
81
81
|
var spaces = str.match(/^\n?( *)/)[1].length;
|
|
82
82
|
var tabs = str.match(/^\n?(\t*)/)[1].length;
|
|
83
83
|
var re = new RegExp(
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
"^\n?" + (tabs ? "\t" : " ") + "{" + (tabs || spaces) + "}",
|
|
85
|
+
"gm",
|
|
86
86
|
);
|
|
87
87
|
|
|
88
|
-
str = str.replace(re,
|
|
88
|
+
str = str.replace(re, "");
|
|
89
89
|
|
|
90
90
|
return str.trim();
|
|
91
91
|
};
|
|
@@ -106,12 +106,12 @@ exports.clean = function (str) {
|
|
|
106
106
|
*/
|
|
107
107
|
function emptyRepresentation(value, typeHint) {
|
|
108
108
|
switch (typeHint) {
|
|
109
|
-
case
|
|
110
|
-
return
|
|
111
|
-
case
|
|
112
|
-
return
|
|
113
|
-
case
|
|
114
|
-
return
|
|
109
|
+
case "function":
|
|
110
|
+
return "[Function]";
|
|
111
|
+
case "object":
|
|
112
|
+
return "{}";
|
|
113
|
+
case "array":
|
|
114
|
+
return "[]";
|
|
115
115
|
default:
|
|
116
116
|
return value.toString();
|
|
117
117
|
}
|
|
@@ -142,18 +142,18 @@ function emptyRepresentation(value, typeHint) {
|
|
|
142
142
|
*/
|
|
143
143
|
var canonicalType = (exports.canonicalType = function canonicalType(value) {
|
|
144
144
|
if (value === undefined) {
|
|
145
|
-
return
|
|
145
|
+
return "undefined";
|
|
146
146
|
} else if (value === null) {
|
|
147
|
-
return
|
|
147
|
+
return "null";
|
|
148
148
|
} else if (Buffer.isBuffer(value)) {
|
|
149
|
-
return
|
|
149
|
+
return "buffer";
|
|
150
150
|
} else if (Object.getPrototypeOf(value) === null) {
|
|
151
|
-
return
|
|
151
|
+
return "null-prototype";
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
return Object.prototype.toString
|
|
155
155
|
.call(value)
|
|
156
|
-
.replace(/^\[.+\s(.+?)]$/,
|
|
156
|
+
.replace(/^\[.+\s(.+?)]$/, "$1")
|
|
157
157
|
.toLowerCase();
|
|
158
158
|
});
|
|
159
159
|
|
|
@@ -179,21 +179,21 @@ var canonicalType = (exports.canonicalType = function canonicalType(value) {
|
|
|
179
179
|
*/
|
|
180
180
|
exports.type = function type(value) {
|
|
181
181
|
// Null is special
|
|
182
|
-
if (value === null) return
|
|
182
|
+
if (value === null) return "null";
|
|
183
183
|
const primitives = new Set([
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
184
|
+
"undefined",
|
|
185
|
+
"boolean",
|
|
186
|
+
"number",
|
|
187
|
+
"string",
|
|
188
|
+
"bigint",
|
|
189
|
+
"symbol",
|
|
190
190
|
]);
|
|
191
191
|
const _type = typeof value;
|
|
192
|
-
if (_type ===
|
|
192
|
+
if (_type === "function") return _type;
|
|
193
193
|
if (primitives.has(_type)) return _type;
|
|
194
|
-
if (value instanceof String) return
|
|
195
|
-
if (value instanceof Error) return
|
|
196
|
-
if (Array.isArray(value)) return
|
|
194
|
+
if (value instanceof String) return "string";
|
|
195
|
+
if (value instanceof Error) return "error";
|
|
196
|
+
if (Array.isArray(value)) return "array";
|
|
197
197
|
|
|
198
198
|
return _type;
|
|
199
199
|
};
|
|
@@ -216,24 +216,24 @@ exports.type = function type(value) {
|
|
|
216
216
|
exports.stringify = function (value) {
|
|
217
217
|
var typeHint = canonicalType(value);
|
|
218
218
|
|
|
219
|
-
if (!~[
|
|
220
|
-
if (typeHint ===
|
|
219
|
+
if (!~["object", "array", "function", "null-prototype"].indexOf(typeHint)) {
|
|
220
|
+
if (typeHint === "buffer") {
|
|
221
221
|
var json = Buffer.prototype.toJSON.call(value);
|
|
222
222
|
// Based on the toJSON result
|
|
223
223
|
return jsonStringify(
|
|
224
224
|
json.data && json.type ? json.data : json,
|
|
225
|
-
2
|
|
226
|
-
).replace(/,(\n|$)/g,
|
|
225
|
+
2,
|
|
226
|
+
).replace(/,(\n|$)/g, "$1");
|
|
227
227
|
}
|
|
228
228
|
|
|
229
229
|
// IE7/IE8 has a bizarre String constructor; needs to be coerced
|
|
230
230
|
// into an array and back to obj.
|
|
231
|
-
if (typeHint ===
|
|
232
|
-
value = value.split(
|
|
231
|
+
if (typeHint === "string" && typeof value === "object") {
|
|
232
|
+
value = value.split("").reduce(function (acc, char, idx) {
|
|
233
233
|
acc[idx] = char;
|
|
234
234
|
return acc;
|
|
235
235
|
}, {});
|
|
236
|
-
typeHint =
|
|
236
|
+
typeHint = "object";
|
|
237
237
|
} else {
|
|
238
238
|
return jsonStringify(value);
|
|
239
239
|
}
|
|
@@ -243,8 +243,8 @@ exports.stringify = function (value) {
|
|
|
243
243
|
if (Object.prototype.hasOwnProperty.call(value, prop)) {
|
|
244
244
|
return jsonStringify(
|
|
245
245
|
exports.canonicalize(value, null, typeHint),
|
|
246
|
-
2
|
|
247
|
-
).replace(/,(\n|$)/g,
|
|
246
|
+
2,
|
|
247
|
+
).replace(/,(\n|$)/g, "$1");
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
250
|
|
|
@@ -261,17 +261,17 @@ exports.stringify = function (value) {
|
|
|
261
261
|
* @returns {*}
|
|
262
262
|
*/
|
|
263
263
|
function jsonStringify(object, spaces, depth) {
|
|
264
|
-
if (typeof spaces ===
|
|
264
|
+
if (typeof spaces === "undefined") {
|
|
265
265
|
// primitive types
|
|
266
266
|
return _stringify(object);
|
|
267
267
|
}
|
|
268
268
|
|
|
269
269
|
depth = depth || 1;
|
|
270
270
|
var space = spaces * depth;
|
|
271
|
-
var str = Array.isArray(object) ?
|
|
272
|
-
var end = Array.isArray(object) ?
|
|
271
|
+
var str = Array.isArray(object) ? "[" : "{";
|
|
272
|
+
var end = Array.isArray(object) ? "]" : "}";
|
|
273
273
|
var length =
|
|
274
|
-
typeof object.length ===
|
|
274
|
+
typeof object.length === "number"
|
|
275
275
|
? object.length
|
|
276
276
|
: Object.keys(object).length;
|
|
277
277
|
// `.repeat()` polyfill
|
|
@@ -281,39 +281,39 @@ function jsonStringify(object, spaces, depth) {
|
|
|
281
281
|
|
|
282
282
|
function _stringify(val) {
|
|
283
283
|
switch (canonicalType(val)) {
|
|
284
|
-
case
|
|
285
|
-
case
|
|
286
|
-
val =
|
|
284
|
+
case "null":
|
|
285
|
+
case "undefined":
|
|
286
|
+
val = "[" + val + "]";
|
|
287
287
|
break;
|
|
288
|
-
case
|
|
289
|
-
case
|
|
288
|
+
case "array":
|
|
289
|
+
case "object":
|
|
290
290
|
val = jsonStringify(val, spaces, depth + 1);
|
|
291
291
|
break;
|
|
292
|
-
case
|
|
293
|
-
case
|
|
294
|
-
case
|
|
295
|
-
case
|
|
292
|
+
case "boolean":
|
|
293
|
+
case "regexp":
|
|
294
|
+
case "symbol":
|
|
295
|
+
case "number":
|
|
296
296
|
val =
|
|
297
297
|
val === 0 && 1 / val === -Infinity // `-0`
|
|
298
|
-
?
|
|
298
|
+
? "-0"
|
|
299
299
|
: val.toString();
|
|
300
300
|
break;
|
|
301
|
-
case
|
|
302
|
-
val = val.toString() +
|
|
301
|
+
case "bigint":
|
|
302
|
+
val = val.toString() + "n";
|
|
303
303
|
break;
|
|
304
|
-
case
|
|
304
|
+
case "date":
|
|
305
305
|
var sDate = isNaN(val.getTime()) ? val.toString() : val.toISOString();
|
|
306
|
-
val =
|
|
306
|
+
val = "[Date: " + sDate + "]";
|
|
307
307
|
break;
|
|
308
|
-
case
|
|
308
|
+
case "buffer":
|
|
309
309
|
var json = val.toJSON();
|
|
310
310
|
// Based on the toJSON result
|
|
311
311
|
json = json.data && json.type ? json.data : json;
|
|
312
|
-
val =
|
|
312
|
+
val = "[Buffer: " + jsonStringify(json, 2, depth + 1) + "]";
|
|
313
313
|
break;
|
|
314
314
|
default:
|
|
315
315
|
val =
|
|
316
|
-
val ===
|
|
316
|
+
val === "[Function]" || val === "[Circular]"
|
|
317
317
|
? val
|
|
318
318
|
: JSON.stringify(val); // string
|
|
319
319
|
}
|
|
@@ -326,17 +326,17 @@ function jsonStringify(object, spaces, depth) {
|
|
|
326
326
|
}
|
|
327
327
|
--length;
|
|
328
328
|
str +=
|
|
329
|
-
|
|
330
|
-
repeat(
|
|
331
|
-
(Array.isArray(object) ?
|
|
329
|
+
"\n " +
|
|
330
|
+
repeat(" ", space) +
|
|
331
|
+
(Array.isArray(object) ? "" : '"' + i + '": ') + // key
|
|
332
332
|
_stringify(object[i]) + // value
|
|
333
|
-
(length ?
|
|
333
|
+
(length ? "," : ""); // comma
|
|
334
334
|
}
|
|
335
335
|
|
|
336
336
|
return (
|
|
337
337
|
str +
|
|
338
338
|
// [], {}
|
|
339
|
-
(str.length !== 1 ?
|
|
339
|
+
(str.length !== 1 ? "\n" + repeat(" ", --space) + end : end)
|
|
340
340
|
);
|
|
341
341
|
}
|
|
342
342
|
|
|
@@ -374,23 +374,23 @@ exports.canonicalize = function canonicalize(value, stack, typeHint) {
|
|
|
374
374
|
stack = stack || [];
|
|
375
375
|
|
|
376
376
|
if (stack.indexOf(value) !== -1) {
|
|
377
|
-
return
|
|
377
|
+
return "[Circular]";
|
|
378
378
|
}
|
|
379
379
|
|
|
380
380
|
switch (typeHint) {
|
|
381
|
-
case
|
|
382
|
-
case
|
|
383
|
-
case
|
|
381
|
+
case "undefined":
|
|
382
|
+
case "buffer":
|
|
383
|
+
case "null":
|
|
384
384
|
canonicalizedObj = value;
|
|
385
385
|
break;
|
|
386
|
-
case
|
|
386
|
+
case "array":
|
|
387
387
|
withStack(value, function () {
|
|
388
388
|
canonicalizedObj = value.map(function (item) {
|
|
389
389
|
return exports.canonicalize(item, stack);
|
|
390
390
|
});
|
|
391
391
|
});
|
|
392
392
|
break;
|
|
393
|
-
case
|
|
393
|
+
case "function":
|
|
394
394
|
/* eslint-disable-next-line no-unused-vars, no-unreachable-loop */
|
|
395
395
|
for (prop in value) {
|
|
396
396
|
canonicalizedObj = {};
|
|
@@ -402,11 +402,11 @@ exports.canonicalize = function canonicalize(value, stack, typeHint) {
|
|
|
402
402
|
break;
|
|
403
403
|
}
|
|
404
404
|
/* falls through */
|
|
405
|
-
case
|
|
406
|
-
case
|
|
405
|
+
case "null-prototype":
|
|
406
|
+
case "object":
|
|
407
407
|
canonicalizedObj = canonicalizedObj || {};
|
|
408
|
-
if (typeHint ===
|
|
409
|
-
canonicalizedObj[
|
|
408
|
+
if (typeHint === "null-prototype" && Symbol.toStringTag in value) {
|
|
409
|
+
canonicalizedObj["[Symbol.toStringTag]"] = value[Symbol.toStringTag];
|
|
410
410
|
}
|
|
411
411
|
withStack(value, function () {
|
|
412
412
|
Object.keys(value)
|
|
@@ -416,15 +416,15 @@ exports.canonicalize = function canonicalize(value, stack, typeHint) {
|
|
|
416
416
|
});
|
|
417
417
|
});
|
|
418
418
|
break;
|
|
419
|
-
case
|
|
420
|
-
case
|
|
421
|
-
case
|
|
422
|
-
case
|
|
423
|
-
case
|
|
419
|
+
case "date":
|
|
420
|
+
case "number":
|
|
421
|
+
case "regexp":
|
|
422
|
+
case "boolean":
|
|
423
|
+
case "symbol":
|
|
424
424
|
canonicalizedObj = value;
|
|
425
425
|
break;
|
|
426
426
|
default:
|
|
427
|
-
canonicalizedObj = value +
|
|
427
|
+
canonicalizedObj = value + "";
|
|
428
428
|
}
|
|
429
429
|
|
|
430
430
|
return canonicalizedObj;
|
|
@@ -441,39 +441,39 @@ exports.canonicalize = function canonicalize(value, stack, typeHint) {
|
|
|
441
441
|
*/
|
|
442
442
|
exports.stackTraceFilter = function () {
|
|
443
443
|
// TODO: Replace with `process.browser`
|
|
444
|
-
var is = typeof document ===
|
|
444
|
+
var is = typeof document === "undefined" ? { node: true } : { browser: true };
|
|
445
445
|
var slash = path.sep;
|
|
446
446
|
var cwd;
|
|
447
447
|
if (is.node) {
|
|
448
448
|
cwd = exports.cwd() + slash;
|
|
449
449
|
} else {
|
|
450
450
|
cwd = (
|
|
451
|
-
typeof location ===
|
|
452
|
-
).href.replace(/\/[^/]*$/,
|
|
453
|
-
slash =
|
|
451
|
+
typeof location === "undefined" ? window.location : location
|
|
452
|
+
).href.replace(/\/[^/]*$/, "/");
|
|
453
|
+
slash = "/";
|
|
454
454
|
}
|
|
455
455
|
|
|
456
456
|
function isMochaInternal(line) {
|
|
457
457
|
return (
|
|
458
|
-
~line.indexOf(
|
|
459
|
-
~line.indexOf(slash +
|
|
460
|
-
~line.indexOf(slash +
|
|
458
|
+
~line.indexOf("node_modules" + slash + "mocha" + slash) ||
|
|
459
|
+
~line.indexOf(slash + "mocha.js") ||
|
|
460
|
+
~line.indexOf(slash + "mocha.min.js")
|
|
461
461
|
);
|
|
462
462
|
}
|
|
463
463
|
|
|
464
464
|
function isNodeInternal(line) {
|
|
465
465
|
return (
|
|
466
|
-
~line.indexOf(
|
|
467
|
-
~line.indexOf(
|
|
468
|
-
~line.indexOf(
|
|
469
|
-
~line.indexOf(
|
|
470
|
-
~line.indexOf(
|
|
466
|
+
~line.indexOf("(timers.js:") ||
|
|
467
|
+
~line.indexOf("(events.js:") ||
|
|
468
|
+
~line.indexOf("(node.js:") ||
|
|
469
|
+
~line.indexOf("(module.js:") ||
|
|
470
|
+
~line.indexOf("GeneratorFunctionPrototype.next (native)") ||
|
|
471
471
|
false
|
|
472
472
|
);
|
|
473
473
|
}
|
|
474
474
|
|
|
475
475
|
return function (stack) {
|
|
476
|
-
stack = stack.split(
|
|
476
|
+
stack = stack.split("\n");
|
|
477
477
|
|
|
478
478
|
stack = stack.reduce(function (list, line) {
|
|
479
479
|
if (isMochaInternal(line)) {
|
|
@@ -486,14 +486,14 @@ exports.stackTraceFilter = function () {
|
|
|
486
486
|
|
|
487
487
|
// Clean up cwd(absolute)
|
|
488
488
|
if (/:\d+:\d+\)?$/.test(line)) {
|
|
489
|
-
line = line.replace(
|
|
489
|
+
line = line.replace("(" + cwd, "(");
|
|
490
490
|
}
|
|
491
491
|
|
|
492
492
|
list.push(line);
|
|
493
493
|
return list;
|
|
494
494
|
}, []);
|
|
495
495
|
|
|
496
|
-
return stack.join(
|
|
496
|
+
return stack.join("\n");
|
|
497
497
|
};
|
|
498
498
|
};
|
|
499
499
|
|
|
@@ -505,9 +505,9 @@ exports.stackTraceFilter = function () {
|
|
|
505
505
|
*/
|
|
506
506
|
exports.isPromise = function isPromise(value) {
|
|
507
507
|
return (
|
|
508
|
-
typeof value ===
|
|
508
|
+
typeof value === "object" &&
|
|
509
509
|
value !== null &&
|
|
510
|
-
typeof value.then ===
|
|
510
|
+
typeof value.then === "function"
|
|
511
511
|
);
|
|
512
512
|
};
|
|
513
513
|
|
|
@@ -546,7 +546,7 @@ exports.noop = function () {};
|
|
|
546
546
|
exports.createMap = function () {
|
|
547
547
|
return Object.assign.apply(
|
|
548
548
|
null,
|
|
549
|
-
[Object.create(null)].concat(Array.prototype.slice.call(arguments))
|
|
549
|
+
[Object.create(null)].concat(Array.prototype.slice.call(arguments)),
|
|
550
550
|
);
|
|
551
551
|
};
|
|
552
552
|
|
|
@@ -563,8 +563,8 @@ exports.createMap = function () {
|
|
|
563
563
|
* @throws {TypeError} if argument is not a non-empty object.
|
|
564
564
|
*/
|
|
565
565
|
exports.defineConstants = function (obj) {
|
|
566
|
-
if (canonicalType(obj) !==
|
|
567
|
-
throw new TypeError(
|
|
566
|
+
if (canonicalType(obj) !== "object" || !Object.keys(obj).length) {
|
|
567
|
+
throw new TypeError("Invalid argument; expected a non-empty object");
|
|
568
568
|
}
|
|
569
569
|
return Object.freeze(exports.createMap(obj));
|
|
570
570
|
};
|
|
@@ -608,8 +608,8 @@ exports.castArray = function castArray(value) {
|
|
|
608
608
|
return [null];
|
|
609
609
|
}
|
|
610
610
|
if (
|
|
611
|
-
typeof value ===
|
|
612
|
-
(typeof value[Symbol.iterator] ===
|
|
611
|
+
typeof value === "object" &&
|
|
612
|
+
(typeof value[Symbol.iterator] === "function" || value.length !== undefined)
|
|
613
613
|
) {
|
|
614
614
|
return Array.from(value);
|
|
615
615
|
}
|
|
@@ -617,11 +617,11 @@ exports.castArray = function castArray(value) {
|
|
|
617
617
|
};
|
|
618
618
|
|
|
619
619
|
exports.constants = exports.defineConstants({
|
|
620
|
-
MOCHA_ID_PROP_NAME
|
|
620
|
+
MOCHA_ID_PROP_NAME,
|
|
621
621
|
});
|
|
622
622
|
|
|
623
623
|
const uniqueIDBase =
|
|
624
|
-
|
|
624
|
+
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
|
|
625
625
|
|
|
626
626
|
/**
|
|
627
627
|
* Creates a new unique identifier
|
|
@@ -630,19 +630,19 @@ const uniqueIDBase =
|
|
|
630
630
|
* @returns {string} Unique identifier
|
|
631
631
|
*/
|
|
632
632
|
exports.uniqueID = () => {
|
|
633
|
-
let id =
|
|
633
|
+
let id = "";
|
|
634
634
|
for (let i = 0; i < 21; i++) {
|
|
635
635
|
id += uniqueIDBase[(Math.random() * 64) | 0];
|
|
636
636
|
}
|
|
637
637
|
return id;
|
|
638
638
|
};
|
|
639
639
|
|
|
640
|
-
exports.assignNewMochaID = obj => {
|
|
640
|
+
exports.assignNewMochaID = (obj) => {
|
|
641
641
|
const id = exports.uniqueID();
|
|
642
642
|
Object.defineProperty(obj, MOCHA_ID_PROP_NAME, {
|
|
643
643
|
get() {
|
|
644
644
|
return id;
|
|
645
|
-
}
|
|
645
|
+
},
|
|
646
646
|
});
|
|
647
647
|
return obj;
|
|
648
648
|
};
|
|
@@ -652,8 +652,8 @@ exports.assignNewMochaID = obj => {
|
|
|
652
652
|
* @param {*} [obj] - Object
|
|
653
653
|
* @returns {string|void}
|
|
654
654
|
*/
|
|
655
|
-
exports.getMochaID = obj =>
|
|
656
|
-
obj && typeof obj ===
|
|
655
|
+
exports.getMochaID = (obj) =>
|
|
656
|
+
obj && typeof obj === "object" ? obj[MOCHA_ID_PROP_NAME] : undefined;
|
|
657
657
|
|
|
658
658
|
/**
|
|
659
659
|
* Replaces any detected circular dependency with the string '[Circular]'
|
|
@@ -661,16 +661,16 @@ exports.getMochaID = obj =>
|
|
|
661
661
|
* @param inputObj {*}
|
|
662
662
|
* @returns {*}
|
|
663
663
|
*/
|
|
664
|
-
exports.breakCircularDeps = inputObj => {
|
|
664
|
+
exports.breakCircularDeps = (inputObj) => {
|
|
665
665
|
const seen = new Set();
|
|
666
666
|
|
|
667
667
|
function _breakCircularDeps(obj) {
|
|
668
|
-
if (obj && typeof obj !==
|
|
668
|
+
if (obj && typeof obj !== "object") {
|
|
669
669
|
return obj;
|
|
670
670
|
}
|
|
671
671
|
|
|
672
672
|
if (seen.has(obj)) {
|
|
673
|
-
return
|
|
673
|
+
return "[Circular]";
|
|
674
674
|
}
|
|
675
675
|
|
|
676
676
|
seen.add(obj);
|
|
@@ -693,6 +693,6 @@ exports.breakCircularDeps = inputObj => {
|
|
|
693
693
|
/**
|
|
694
694
|
* Checks if provided input can be parsed as a JavaScript Number.
|
|
695
695
|
*/
|
|
696
|
-
exports.isNumeric = input => {
|
|
696
|
+
exports.isNumeric = (input) => {
|
|
697
697
|
return !isNaN(parseFloat(input));
|
|
698
698
|
};
|