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/plugin-loader.js
CHANGED
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
* @module plugin
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
"use strict";
|
|
17
17
|
|
|
18
|
-
const debug = require(
|
|
18
|
+
const debug = require("debug")("mocha:plugin-loader");
|
|
19
19
|
const {
|
|
20
20
|
createInvalidPluginDefinitionError,
|
|
21
|
-
createInvalidPluginImplementationError
|
|
22
|
-
} = require(
|
|
23
|
-
const {castArray} = require(
|
|
21
|
+
createInvalidPluginImplementationError,
|
|
22
|
+
} = require("./errors");
|
|
23
|
+
const { castArray } = require("./utils");
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* @typedef {import('./types.d.ts').PluginLoaderOptions} PluginLoaderOptions
|
|
@@ -35,24 +35,24 @@ const MochaPlugins = [
|
|
|
35
35
|
* @type {PluginDefinition}
|
|
36
36
|
*/
|
|
37
37
|
{
|
|
38
|
-
exportName:
|
|
39
|
-
optionName:
|
|
38
|
+
exportName: "mochaHooks",
|
|
39
|
+
optionName: "rootHooks",
|
|
40
40
|
validate(value) {
|
|
41
41
|
if (
|
|
42
42
|
Array.isArray(value) ||
|
|
43
|
-
(typeof value !==
|
|
43
|
+
(typeof value !== "function" && typeof value !== "object")
|
|
44
44
|
) {
|
|
45
45
|
throw createInvalidPluginImplementationError(
|
|
46
|
-
`mochaHooks must be an object or a function returning (or fulfilling with) an object
|
|
46
|
+
`mochaHooks must be an object or a function returning (or fulfilling with) an object`,
|
|
47
47
|
);
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
50
|
async finalize(rootHooks) {
|
|
51
51
|
if (rootHooks.length) {
|
|
52
52
|
const rootHookObjects = await Promise.all(
|
|
53
|
-
rootHooks.map(async hook =>
|
|
54
|
-
typeof hook ===
|
|
55
|
-
)
|
|
53
|
+
rootHooks.map(async (hook) =>
|
|
54
|
+
typeof hook === "function" ? hook() : hook,
|
|
55
|
+
),
|
|
56
56
|
);
|
|
57
57
|
|
|
58
58
|
return rootHookObjects.reduce(
|
|
@@ -62,68 +62,68 @@ const MochaPlugins = [
|
|
|
62
62
|
beforeEach: [],
|
|
63
63
|
afterAll: [],
|
|
64
64
|
afterEach: [],
|
|
65
|
-
...hook
|
|
65
|
+
...hook,
|
|
66
66
|
};
|
|
67
67
|
return {
|
|
68
68
|
beforeAll: [...acc.beforeAll, ...castArray(hook.beforeAll)],
|
|
69
69
|
beforeEach: [...acc.beforeEach, ...castArray(hook.beforeEach)],
|
|
70
70
|
afterAll: [...acc.afterAll, ...castArray(hook.afterAll)],
|
|
71
|
-
afterEach: [...acc.afterEach, ...castArray(hook.afterEach)]
|
|
71
|
+
afterEach: [...acc.afterEach, ...castArray(hook.afterEach)],
|
|
72
72
|
};
|
|
73
73
|
},
|
|
74
|
-
{beforeAll: [], beforeEach: [], afterAll: [], afterEach: []}
|
|
74
|
+
{ beforeAll: [], beforeEach: [], afterAll: [], afterEach: [] },
|
|
75
75
|
);
|
|
76
76
|
}
|
|
77
|
-
}
|
|
77
|
+
},
|
|
78
78
|
},
|
|
79
79
|
/**
|
|
80
80
|
* Global setup fixture plugin definition
|
|
81
81
|
* @type {PluginDefinition}
|
|
82
82
|
*/
|
|
83
83
|
{
|
|
84
|
-
exportName:
|
|
85
|
-
optionName:
|
|
84
|
+
exportName: "mochaGlobalSetup",
|
|
85
|
+
optionName: "globalSetup",
|
|
86
86
|
validate(value) {
|
|
87
87
|
let isValid = true;
|
|
88
88
|
if (Array.isArray(value)) {
|
|
89
|
-
if (value.some(item => typeof item !==
|
|
89
|
+
if (value.some((item) => typeof item !== "function")) {
|
|
90
90
|
isValid = false;
|
|
91
91
|
}
|
|
92
|
-
} else if (typeof value !==
|
|
92
|
+
} else if (typeof value !== "function") {
|
|
93
93
|
isValid = false;
|
|
94
94
|
}
|
|
95
95
|
if (!isValid) {
|
|
96
96
|
throw createInvalidPluginImplementationError(
|
|
97
97
|
`mochaGlobalSetup must be a function or an array of functions`,
|
|
98
|
-
{pluginDef: this, pluginImpl: value}
|
|
98
|
+
{ pluginDef: this, pluginImpl: value },
|
|
99
99
|
);
|
|
100
100
|
}
|
|
101
|
-
}
|
|
101
|
+
},
|
|
102
102
|
},
|
|
103
103
|
/**
|
|
104
104
|
* Global teardown fixture plugin definition
|
|
105
105
|
* @type {PluginDefinition}
|
|
106
106
|
*/
|
|
107
107
|
{
|
|
108
|
-
exportName:
|
|
109
|
-
optionName:
|
|
108
|
+
exportName: "mochaGlobalTeardown",
|
|
109
|
+
optionName: "globalTeardown",
|
|
110
110
|
validate(value) {
|
|
111
111
|
let isValid = true;
|
|
112
112
|
if (Array.isArray(value)) {
|
|
113
|
-
if (value.some(item => typeof item !==
|
|
113
|
+
if (value.some((item) => typeof item !== "function")) {
|
|
114
114
|
isValid = false;
|
|
115
115
|
}
|
|
116
|
-
} else if (typeof value !==
|
|
116
|
+
} else if (typeof value !== "function") {
|
|
117
117
|
isValid = false;
|
|
118
118
|
}
|
|
119
119
|
if (!isValid) {
|
|
120
120
|
throw createInvalidPluginImplementationError(
|
|
121
121
|
`mochaGlobalTeardown must be a function or an array of functions`,
|
|
122
|
-
{pluginDef: this, pluginImpl: value}
|
|
122
|
+
{ pluginDef: this, pluginImpl: value },
|
|
123
123
|
);
|
|
124
124
|
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
127
|
];
|
|
128
128
|
|
|
129
129
|
/**
|
|
@@ -138,7 +138,7 @@ class PluginLoader {
|
|
|
138
138
|
* Initializes plugin names, plugin map, etc.
|
|
139
139
|
* @param {PluginLoaderOptions} [opts] - Options
|
|
140
140
|
*/
|
|
141
|
-
constructor({pluginDefs = MochaPlugins, ignore = []} = {}) {
|
|
141
|
+
constructor({ pluginDefs = MochaPlugins, ignore = [] } = {}) {
|
|
142
142
|
/**
|
|
143
143
|
* Map of registered plugin defs
|
|
144
144
|
* @type {Map<string,PluginDefinition>}
|
|
@@ -169,14 +169,14 @@ class PluginLoader {
|
|
|
169
169
|
*/
|
|
170
170
|
this.ignoredExportNames = new Set(castArray(ignore));
|
|
171
171
|
|
|
172
|
-
castArray(pluginDefs).forEach(pluginDef => {
|
|
172
|
+
castArray(pluginDefs).forEach((pluginDef) => {
|
|
173
173
|
this.register(pluginDef);
|
|
174
174
|
});
|
|
175
175
|
|
|
176
176
|
debug(
|
|
177
|
-
|
|
177
|
+
"registered %d plugin defs (%d ignored)",
|
|
178
178
|
this.registered.size,
|
|
179
|
-
this.ignoredExportNames.size
|
|
179
|
+
this.ignoredExportNames.size,
|
|
180
180
|
);
|
|
181
181
|
}
|
|
182
182
|
|
|
@@ -185,23 +185,23 @@ class PluginLoader {
|
|
|
185
185
|
* @param {PluginDefinition} pluginDef - Plugin definition
|
|
186
186
|
*/
|
|
187
187
|
register(pluginDef) {
|
|
188
|
-
if (!pluginDef || typeof pluginDef !==
|
|
188
|
+
if (!pluginDef || typeof pluginDef !== "object") {
|
|
189
189
|
throw createInvalidPluginDefinitionError(
|
|
190
|
-
|
|
191
|
-
pluginDef
|
|
190
|
+
"pluginDef is non-object or falsy",
|
|
191
|
+
pluginDef,
|
|
192
192
|
);
|
|
193
193
|
}
|
|
194
194
|
if (!pluginDef.exportName) {
|
|
195
195
|
throw createInvalidPluginDefinitionError(
|
|
196
196
|
`exportName is expected to be a non-empty string`,
|
|
197
|
-
pluginDef
|
|
197
|
+
pluginDef,
|
|
198
198
|
);
|
|
199
199
|
}
|
|
200
|
-
let {exportName} = pluginDef;
|
|
200
|
+
let { exportName } = pluginDef;
|
|
201
201
|
if (this.ignoredExportNames.has(exportName)) {
|
|
202
202
|
debug(
|
|
203
203
|
'refusing to register ignored plugin with export name "%s"',
|
|
204
|
-
exportName
|
|
204
|
+
exportName,
|
|
205
205
|
);
|
|
206
206
|
return;
|
|
207
207
|
}
|
|
@@ -210,7 +210,7 @@ class PluginLoader {
|
|
|
210
210
|
if (this.knownExportNames.has(exportName)) {
|
|
211
211
|
throw createInvalidPluginDefinitionError(
|
|
212
212
|
`Plugin definition conflict: ${exportName}; exportName must be unique`,
|
|
213
|
-
pluginDef
|
|
213
|
+
pluginDef,
|
|
214
214
|
);
|
|
215
215
|
}
|
|
216
216
|
this.loaded.set(exportName, []);
|
|
@@ -229,24 +229,24 @@ class PluginLoader {
|
|
|
229
229
|
load(requiredModule) {
|
|
230
230
|
// we should explicitly NOT fail if other stuff is exported.
|
|
231
231
|
// we only care about the plugins we know about.
|
|
232
|
-
if (requiredModule && typeof requiredModule ===
|
|
232
|
+
if (requiredModule && typeof requiredModule === "object") {
|
|
233
233
|
return Array.from(this.knownExportNames).reduce(
|
|
234
234
|
(pluginImplFound, pluginName) => {
|
|
235
235
|
const pluginImpl = requiredModule[pluginName];
|
|
236
236
|
if (pluginImpl) {
|
|
237
237
|
const plugin = this.registered.get(pluginName);
|
|
238
|
-
if (typeof plugin.validate ===
|
|
238
|
+
if (typeof plugin.validate === "function") {
|
|
239
239
|
plugin.validate(pluginImpl);
|
|
240
240
|
}
|
|
241
241
|
this.loaded.set(pluginName, [
|
|
242
242
|
...this.loaded.get(pluginName),
|
|
243
|
-
...castArray(pluginImpl)
|
|
243
|
+
...castArray(pluginImpl),
|
|
244
244
|
]);
|
|
245
245
|
return true;
|
|
246
246
|
}
|
|
247
247
|
return pluginImplFound;
|
|
248
248
|
},
|
|
249
|
-
false
|
|
249
|
+
false,
|
|
250
250
|
);
|
|
251
251
|
}
|
|
252
252
|
return false;
|
|
@@ -265,13 +265,13 @@ class PluginLoader {
|
|
|
265
265
|
if (pluginImpls.length) {
|
|
266
266
|
const plugin = this.registered.get(exportName);
|
|
267
267
|
finalizedPlugins[plugin.optionName] =
|
|
268
|
-
typeof plugin.finalize ===
|
|
268
|
+
typeof plugin.finalize === "function"
|
|
269
269
|
? await plugin.finalize(pluginImpls)
|
|
270
270
|
: pluginImpls;
|
|
271
271
|
}
|
|
272
272
|
}
|
|
273
273
|
|
|
274
|
-
debug(
|
|
274
|
+
debug("finalized plugins: %O", finalizedPlugins);
|
|
275
275
|
return finalizedPlugins;
|
|
276
276
|
}
|
|
277
277
|
|
|
@@ -279,8 +279,8 @@ class PluginLoader {
|
|
|
279
279
|
* Constructs a {@link PluginLoader}
|
|
280
280
|
* @param {PluginLoaderOptions} [opts] - Plugin loader options
|
|
281
281
|
*/
|
|
282
|
-
static create({pluginDefs = MochaPlugins, ignore = []} = {}) {
|
|
283
|
-
return new PluginLoader({pluginDefs, ignore});
|
|
282
|
+
static create({ pluginDefs = MochaPlugins, ignore = [] } = {}) {
|
|
283
|
+
return new PluginLoader({ pluginDefs, ignore });
|
|
284
284
|
}
|
|
285
285
|
}
|
|
286
286
|
|
package/lib/reporters/base.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @typedef {import('../runner.js')} Runner
|
|
@@ -13,19 +13,19 @@
|
|
|
13
13
|
* Module dependencies.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
var diff = require(
|
|
17
|
-
var milliseconds = require(
|
|
18
|
-
var utils = require(
|
|
19
|
-
var supportsColor = require(
|
|
20
|
-
var symbols = require(
|
|
21
|
-
var constants = require(
|
|
16
|
+
var diff = require("diff");
|
|
17
|
+
var milliseconds = require("ms");
|
|
18
|
+
var utils = require("../utils");
|
|
19
|
+
var supportsColor = require("supports-color");
|
|
20
|
+
var symbols = require("log-symbols");
|
|
21
|
+
var constants = require("../runner").constants;
|
|
22
22
|
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
|
23
23
|
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
|
24
24
|
|
|
25
25
|
const isBrowser = utils.isBrowser();
|
|
26
26
|
|
|
27
27
|
function getBrowserWindowSize() {
|
|
28
|
-
if (
|
|
28
|
+
if ("innerHeight" in global) {
|
|
29
29
|
return [global.innerHeight, global.innerWidth];
|
|
30
30
|
}
|
|
31
31
|
// In a Web Worker, the DOM Window is not available.
|
|
@@ -75,25 +75,25 @@ exports.maxDiffSize = 8192;
|
|
|
75
75
|
exports.colors = {
|
|
76
76
|
pass: 90,
|
|
77
77
|
fail: 31,
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
"bright pass": 92,
|
|
79
|
+
"bright fail": 91,
|
|
80
|
+
"bright yellow": 93,
|
|
81
81
|
pending: 36,
|
|
82
82
|
suite: 0,
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
"error title": 0,
|
|
84
|
+
"error message": 31,
|
|
85
|
+
"error stack": 90,
|
|
86
86
|
checkmark: 32,
|
|
87
87
|
fast: 90,
|
|
88
88
|
medium: 33,
|
|
89
89
|
slow: 31,
|
|
90
90
|
green: 32,
|
|
91
91
|
light: 90,
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
92
|
+
"diff gutter": 90,
|
|
93
|
+
"diff added": 32,
|
|
94
|
+
"diff removed": 31,
|
|
95
|
+
"diff added inline": "30;42",
|
|
96
|
+
"diff removed inline": "30;41",
|
|
97
97
|
};
|
|
98
98
|
|
|
99
99
|
/**
|
|
@@ -103,9 +103,9 @@ exports.colors = {
|
|
|
103
103
|
exports.symbols = {
|
|
104
104
|
ok: symbols.success,
|
|
105
105
|
err: symbols.error,
|
|
106
|
-
dot:
|
|
107
|
-
comma:
|
|
108
|
-
bang:
|
|
106
|
+
dot: ".",
|
|
107
|
+
comma: ",",
|
|
108
|
+
bang: "!",
|
|
109
109
|
};
|
|
110
110
|
|
|
111
111
|
/**
|
|
@@ -123,7 +123,7 @@ var color = (exports.color = function (type, str) {
|
|
|
123
123
|
if (!exports.useColors) {
|
|
124
124
|
return String(str);
|
|
125
125
|
}
|
|
126
|
-
return
|
|
126
|
+
return "\u001b[" + exports.colors[type] + "m" + str + "\u001b[0m";
|
|
127
127
|
});
|
|
128
128
|
|
|
129
129
|
/**
|
|
@@ -131,7 +131,7 @@ var color = (exports.color = function (type, str) {
|
|
|
131
131
|
*/
|
|
132
132
|
|
|
133
133
|
exports.window = {
|
|
134
|
-
width: 75
|
|
134
|
+
width: 75,
|
|
135
135
|
};
|
|
136
136
|
|
|
137
137
|
if (isatty) {
|
|
@@ -148,19 +148,19 @@ if (isatty) {
|
|
|
148
148
|
|
|
149
149
|
exports.cursor = {
|
|
150
150
|
hide: function () {
|
|
151
|
-
isatty && process.stdout.write(
|
|
151
|
+
isatty && process.stdout.write("\u001b[?25l");
|
|
152
152
|
},
|
|
153
153
|
|
|
154
154
|
show: function () {
|
|
155
|
-
isatty && process.stdout.write(
|
|
155
|
+
isatty && process.stdout.write("\u001b[?25h");
|
|
156
156
|
},
|
|
157
157
|
|
|
158
158
|
deleteLine: function () {
|
|
159
|
-
isatty && process.stdout.write(
|
|
159
|
+
isatty && process.stdout.write("\u001b[2K");
|
|
160
160
|
},
|
|
161
161
|
|
|
162
162
|
beginningOfLine: function () {
|
|
163
|
-
isatty && process.stdout.write(
|
|
163
|
+
isatty && process.stdout.write("\u001b[0G");
|
|
164
164
|
},
|
|
165
165
|
|
|
166
166
|
CR: function () {
|
|
@@ -168,9 +168,9 @@ exports.cursor = {
|
|
|
168
168
|
exports.cursor.deleteLine();
|
|
169
169
|
exports.cursor.beginningOfLine();
|
|
170
170
|
} else {
|
|
171
|
-
process.stdout.write(
|
|
171
|
+
process.stdout.write("\r");
|
|
172
172
|
}
|
|
173
|
-
}
|
|
173
|
+
},
|
|
174
174
|
};
|
|
175
175
|
|
|
176
176
|
var showDiff = (exports.showDiff = function (err) {
|
|
@@ -219,11 +219,11 @@ var generateDiff = (exports.generateDiff = function (actual, expected) {
|
|
|
219
219
|
return result;
|
|
220
220
|
} catch (err) {
|
|
221
221
|
var msg =
|
|
222
|
-
|
|
223
|
-
color(
|
|
224
|
-
|
|
225
|
-
color(
|
|
226
|
-
|
|
222
|
+
"\n " +
|
|
223
|
+
color("diff added", "+ expected") +
|
|
224
|
+
" " +
|
|
225
|
+
color("diff removed", "- actual: failed to generate Mocha diff") +
|
|
226
|
+
"\n";
|
|
227
227
|
return msg;
|
|
228
228
|
}
|
|
229
229
|
});
|
|
@@ -238,17 +238,17 @@ var generateDiff = (exports.generateDiff = function (actual, expected) {
|
|
|
238
238
|
*/
|
|
239
239
|
var getFullErrorStack = function (err, seen) {
|
|
240
240
|
if (seen && seen.has(err)) {
|
|
241
|
-
return { message:
|
|
241
|
+
return { message: "", msg: "<circular>", stack: "" };
|
|
242
242
|
}
|
|
243
243
|
|
|
244
244
|
var message;
|
|
245
245
|
|
|
246
|
-
if (typeof err.inspect ===
|
|
247
|
-
message = err.inspect() +
|
|
248
|
-
} else if (err.message && typeof err.message.toString ===
|
|
249
|
-
message = err.message +
|
|
246
|
+
if (typeof err.inspect === "function") {
|
|
247
|
+
message = err.inspect() + "";
|
|
248
|
+
} else if (err.message && typeof err.message.toString === "function") {
|
|
249
|
+
message = err.message + "";
|
|
250
250
|
} else {
|
|
251
|
-
message =
|
|
251
|
+
message = "";
|
|
252
252
|
}
|
|
253
253
|
|
|
254
254
|
var msg;
|
|
@@ -266,15 +266,18 @@ var getFullErrorStack = function (err, seen) {
|
|
|
266
266
|
if (err.cause) {
|
|
267
267
|
seen = seen || new Set();
|
|
268
268
|
seen.add(err);
|
|
269
|
-
const causeStack = getFullErrorStack(err.cause, seen)
|
|
270
|
-
stack +=
|
|
269
|
+
const causeStack = getFullErrorStack(err.cause, seen);
|
|
270
|
+
stack +=
|
|
271
|
+
"\n Caused by: " +
|
|
272
|
+
causeStack.msg +
|
|
273
|
+
(causeStack.stack ? "\n" + causeStack.stack : "");
|
|
271
274
|
}
|
|
272
275
|
}
|
|
273
276
|
|
|
274
277
|
return {
|
|
275
278
|
message,
|
|
276
279
|
msg,
|
|
277
|
-
stack
|
|
280
|
+
stack,
|
|
278
281
|
};
|
|
279
282
|
};
|
|
280
283
|
|
|
@@ -293,9 +296,9 @@ exports.list = function (failures) {
|
|
|
293
296
|
failures.forEach(function (test, i) {
|
|
294
297
|
// format
|
|
295
298
|
var fmt =
|
|
296
|
-
color(
|
|
297
|
-
color(
|
|
298
|
-
color(
|
|
299
|
+
color("error title", " %s) %s:\n") +
|
|
300
|
+
color("error message", " %s") +
|
|
301
|
+
color("error stack", "\n%s\n");
|
|
299
302
|
|
|
300
303
|
// msg
|
|
301
304
|
var err;
|
|
@@ -313,30 +316,30 @@ exports.list = function (failures) {
|
|
|
313
316
|
|
|
314
317
|
// uncaught
|
|
315
318
|
if (err.uncaught) {
|
|
316
|
-
msg =
|
|
319
|
+
msg = "Uncaught " + msg;
|
|
317
320
|
}
|
|
318
321
|
// explicitly show diff
|
|
319
322
|
if (!exports.hideDiff && showDiff(err)) {
|
|
320
323
|
stringifyDiffObjs(err);
|
|
321
324
|
fmt =
|
|
322
|
-
color(
|
|
325
|
+
color("error title", " %s) %s:\n%s") + color("error stack", "\n%s\n");
|
|
323
326
|
var match = message.match(/^([^:]+): expected/);
|
|
324
|
-
msg =
|
|
327
|
+
msg = "\n " + color("error message", match ? match[1] : msg);
|
|
325
328
|
|
|
326
329
|
msg += generateDiff(err.actual, err.expected);
|
|
327
330
|
}
|
|
328
331
|
|
|
329
332
|
// indent stack trace
|
|
330
|
-
stack = stack.replace(/^/gm,
|
|
333
|
+
stack = stack.replace(/^/gm, " ");
|
|
331
334
|
|
|
332
335
|
// indented test title
|
|
333
|
-
var testTitle =
|
|
336
|
+
var testTitle = "";
|
|
334
337
|
test.titlePath().forEach(function (str, index) {
|
|
335
338
|
if (index !== 0) {
|
|
336
|
-
testTitle +=
|
|
339
|
+
testTitle += "\n ";
|
|
337
340
|
}
|
|
338
341
|
for (var i = 0; i < index; i++) {
|
|
339
|
-
testTitle +=
|
|
342
|
+
testTitle += " ";
|
|
340
343
|
}
|
|
341
344
|
testTitle += str;
|
|
342
345
|
});
|
|
@@ -361,7 +364,7 @@ function Base(runner, options) {
|
|
|
361
364
|
var failures = (this.failures = []);
|
|
362
365
|
|
|
363
366
|
if (!runner) {
|
|
364
|
-
throw new TypeError(
|
|
367
|
+
throw new TypeError("Missing runner argument");
|
|
365
368
|
}
|
|
366
369
|
this.options = options || {};
|
|
367
370
|
this.runner = runner;
|
|
@@ -375,11 +378,11 @@ function Base(runner, options) {
|
|
|
375
378
|
|
|
376
379
|
runner.on(EVENT_TEST_PASS, function (test) {
|
|
377
380
|
if (test.duration > test.slow()) {
|
|
378
|
-
test.speed =
|
|
381
|
+
test.speed = "slow";
|
|
379
382
|
} else if (test.duration > test.slow() / 2) {
|
|
380
|
-
test.speed =
|
|
383
|
+
test.speed = "medium";
|
|
381
384
|
} else {
|
|
382
|
-
test.speed =
|
|
385
|
+
test.speed = "fast";
|
|
383
386
|
}
|
|
384
387
|
});
|
|
385
388
|
|
|
@@ -411,22 +414,22 @@ Base.prototype.epilogue = function () {
|
|
|
411
414
|
|
|
412
415
|
// passes
|
|
413
416
|
fmt =
|
|
414
|
-
color(
|
|
415
|
-
color(
|
|
416
|
-
color(
|
|
417
|
+
color("bright pass", " ") +
|
|
418
|
+
color("green", " %d passing") +
|
|
419
|
+
color("light", " (%s)");
|
|
417
420
|
|
|
418
421
|
Base.consoleLog(fmt, stats.passes || 0, milliseconds(stats.duration));
|
|
419
422
|
|
|
420
423
|
// pending
|
|
421
424
|
if (stats.pending) {
|
|
422
|
-
fmt = color(
|
|
425
|
+
fmt = color("pending", " ") + color("pending", " %d pending");
|
|
423
426
|
|
|
424
427
|
Base.consoleLog(fmt, stats.pending);
|
|
425
428
|
}
|
|
426
429
|
|
|
427
430
|
// failures
|
|
428
431
|
if (stats.failures) {
|
|
429
|
-
fmt = color(
|
|
432
|
+
fmt = color("fail", " %d failing");
|
|
430
433
|
|
|
431
434
|
Base.consoleLog(fmt, stats.failures);
|
|
432
435
|
|
|
@@ -447,7 +450,7 @@ Base.prototype.epilogue = function () {
|
|
|
447
450
|
*/
|
|
448
451
|
function pad(str, len) {
|
|
449
452
|
str = String(str);
|
|
450
|
-
return Array(len - str.length + 1).join(
|
|
453
|
+
return Array(len - str.length + 1).join(" ") + str;
|
|
451
454
|
}
|
|
452
455
|
|
|
453
456
|
/**
|
|
@@ -462,28 +465,28 @@ function inlineDiff(actual, expected) {
|
|
|
462
465
|
var msg = errorDiff(actual, expected);
|
|
463
466
|
|
|
464
467
|
// linenos
|
|
465
|
-
var lines = msg.split(
|
|
468
|
+
var lines = msg.split("\n");
|
|
466
469
|
if (lines.length > 4) {
|
|
467
470
|
var width = String(lines.length).length;
|
|
468
471
|
msg = lines
|
|
469
472
|
.map(function (str, i) {
|
|
470
|
-
return pad(++i, width) +
|
|
473
|
+
return pad(++i, width) + " |" + " " + str;
|
|
471
474
|
})
|
|
472
|
-
.join(
|
|
475
|
+
.join("\n");
|
|
473
476
|
}
|
|
474
477
|
|
|
475
478
|
// legend
|
|
476
479
|
msg =
|
|
477
|
-
|
|
478
|
-
color(
|
|
479
|
-
|
|
480
|
-
color(
|
|
481
|
-
|
|
480
|
+
"\n" +
|
|
481
|
+
color("diff removed inline", "actual") +
|
|
482
|
+
" " +
|
|
483
|
+
color("diff added inline", "expected") +
|
|
484
|
+
"\n\n" +
|
|
482
485
|
msg +
|
|
483
|
-
|
|
486
|
+
"\n";
|
|
484
487
|
|
|
485
488
|
// indent
|
|
486
|
-
msg = msg.replace(/^/gm,
|
|
489
|
+
msg = msg.replace(/^/gm, " ");
|
|
487
490
|
return msg;
|
|
488
491
|
}
|
|
489
492
|
|
|
@@ -496,16 +499,16 @@ function inlineDiff(actual, expected) {
|
|
|
496
499
|
* @return {string} The diff.
|
|
497
500
|
*/
|
|
498
501
|
function unifiedDiff(actual, expected) {
|
|
499
|
-
var indent =
|
|
502
|
+
var indent = " ";
|
|
500
503
|
function cleanUp(line) {
|
|
501
|
-
if (line[0] ===
|
|
502
|
-
return indent + colorLines(
|
|
504
|
+
if (line[0] === "+") {
|
|
505
|
+
return indent + colorLines("diff added", line);
|
|
503
506
|
}
|
|
504
|
-
if (line[0] ===
|
|
505
|
-
return indent + colorLines(
|
|
507
|
+
if (line[0] === "-") {
|
|
508
|
+
return indent + colorLines("diff removed", line);
|
|
506
509
|
}
|
|
507
510
|
if (line.match(/@@/)) {
|
|
508
|
-
return
|
|
511
|
+
return "--";
|
|
509
512
|
}
|
|
510
513
|
if (line.match(/\\ No newline/)) {
|
|
511
514
|
return null;
|
|
@@ -513,17 +516,17 @@ function unifiedDiff(actual, expected) {
|
|
|
513
516
|
return indent + line;
|
|
514
517
|
}
|
|
515
518
|
function notBlank(line) {
|
|
516
|
-
return typeof line !==
|
|
519
|
+
return typeof line !== "undefined" && line !== null;
|
|
517
520
|
}
|
|
518
|
-
var msg = diff.createPatch(
|
|
519
|
-
var lines = msg.split(
|
|
521
|
+
var msg = diff.createPatch("string", actual, expected);
|
|
522
|
+
var lines = msg.split("\n").splice(5);
|
|
520
523
|
return (
|
|
521
|
-
|
|
522
|
-
colorLines(
|
|
523
|
-
|
|
524
|
-
colorLines(
|
|
525
|
-
|
|
526
|
-
lines.map(cleanUp).filter(notBlank).join(
|
|
524
|
+
"\n " +
|
|
525
|
+
colorLines("diff added", "+ expected") +
|
|
526
|
+
" " +
|
|
527
|
+
colorLines("diff removed", "- actual") +
|
|
528
|
+
"\n\n" +
|
|
529
|
+
lines.map(cleanUp).filter(notBlank).join("\n")
|
|
527
530
|
);
|
|
528
531
|
}
|
|
529
532
|
|
|
@@ -540,14 +543,14 @@ function errorDiff(actual, expected) {
|
|
|
540
543
|
.diffWordsWithSpace(actual, expected)
|
|
541
544
|
.map(function (str) {
|
|
542
545
|
if (str.added) {
|
|
543
|
-
return colorLines(
|
|
546
|
+
return colorLines("diff added inline", str.value);
|
|
544
547
|
}
|
|
545
548
|
if (str.removed) {
|
|
546
|
-
return colorLines(
|
|
549
|
+
return colorLines("diff removed inline", str.value);
|
|
547
550
|
}
|
|
548
551
|
return str.value;
|
|
549
552
|
})
|
|
550
|
-
.join(
|
|
553
|
+
.join("");
|
|
551
554
|
}
|
|
552
555
|
|
|
553
556
|
/**
|
|
@@ -560,11 +563,11 @@ function errorDiff(actual, expected) {
|
|
|
560
563
|
*/
|
|
561
564
|
function colorLines(name, str) {
|
|
562
565
|
return str
|
|
563
|
-
.split(
|
|
566
|
+
.split("\n")
|
|
564
567
|
.map(function (str) {
|
|
565
568
|
return color(name, str);
|
|
566
569
|
})
|
|
567
|
-
.join(
|
|
570
|
+
.join("\n");
|
|
568
571
|
}
|
|
569
572
|
|
|
570
573
|
/**
|