@eggjs/mock 6.1.0-beta.3 → 6.1.0-beta.5
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/dist/_virtual/rolldown_runtime.js +24 -1
- package/dist/bootstrap.d.ts +1 -1
- package/dist/bootstrap.js +1 -1
- package/dist/index.js +0 -1
- package/dist/inject_mocha.d.ts +1 -0
- package/dist/inject_mocha.js +35 -0
- package/dist/node_modules/.pnpm/ansi-styles@4.3.0/node_modules/ansi-styles/index.js +142 -0
- package/dist/node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/index.js +157 -0
- package/dist/node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/templates.js +97 -0
- package/dist/node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/util.js +40 -0
- package/dist/node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/conversions.js +812 -0
- package/dist/node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/index.js +50 -0
- package/dist/node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/route.js +68 -0
- package/dist/node_modules/.pnpm/color-name@1.1.4/node_modules/color-name/index.js +752 -0
- package/dist/node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/browser.js +203 -0
- package/dist/node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/common.js +209 -0
- package/dist/node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/index.js +18 -0
- package/dist/node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/node.js +215 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/convert/dmp.js +24 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/convert/xml.js +33 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/array.js +29 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/base.js +185 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/character.js +23 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/css.js +26 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/json.js +83 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/line.js +51 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/sentence.js +26 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/word.js +151 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/index.js +178 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/apply.js +168 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/create.js +301 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/line-endings.js +137 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/merge.js +367 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/parse.js +91 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/reverse.js +99 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/util/array.js +23 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/util/distance-iterator.js +30 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/util/params.js +22 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/util/string.js +97 -0
- package/dist/node_modules/.pnpm/escape-string-regexp@4.0.0/node_modules/escape-string-regexp/index.js +14 -0
- package/dist/node_modules/.pnpm/has-flag@4.0.0/node_modules/has-flag/index.js +16 -0
- package/dist/node_modules/.pnpm/he@1.2.0/node_modules/he/he.js +4093 -0
- package/dist/node_modules/.pnpm/is-unicode-supported@0.1.0/node_modules/is-unicode-supported/index.js +14 -0
- package/dist/node_modules/.pnpm/log-symbols@4.1.0/node_modules/log-symbols/index.js +27 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/index.js +12 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/context.js +83 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/error-constants.js +35 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/errors.js +392 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/hook.js +86 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/bdd.js +104 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/common.js +99 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/exports.js +65 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/index.js +18 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/qunit.js +95 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/tdd.js +105 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/mocha.js +1037 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/mocharc.js +24 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/buffered-worker-pool.js +152 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/esm-utils.js +74 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/file-unloader.js +22 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/parallel-buffered-runner.js +329 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/serializer.js +314 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/pending.js +22 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/base.js +417 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/doc.js +79 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/dot.js +75 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/html.js +283 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/index.js +40 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/json-stream.js +90 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/json.js +145 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/landing.js +107 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/list.js +77 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/markdown.js +106 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/min.js +57 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/nyan.js +233 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/progress.js +92 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/spec.js +91 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/tap.js +261 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/xunit.js +166 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/runnable.js +346 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/runner.js +922 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/stats-collector.js +72 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/suite.js +517 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/test.js +105 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/utils.js +505 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/package.js +225 -0
- package/dist/node_modules/.pnpm/ms@2.1.3/node_modules/ms/index.js +124 -0
- package/dist/node_modules/.pnpm/randombytes@2.1.0/node_modules/randombytes/index.js +11 -0
- package/dist/node_modules/.pnpm/serialize-javascript@6.0.2/node_modules/serialize-javascript/index.js +114 -0
- package/dist/node_modules/.pnpm/supports-color@7.2.0/node_modules/supports-color/index.js +76 -0
- package/dist/node_modules/.pnpm/supports-color@8.1.1/node_modules/supports-color/index.js +89 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/Pool.js +366 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/Promise.js +248 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/WorkerHandler.js +419 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/debug-port-allocator.js +27 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/environment.js +18 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/generated/embeddedWorker.js +16 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/index.js +63 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/transfer.js +21 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/validateOptions.js +9 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/worker.js +277 -0
- package/dist/register.d.ts +0 -2
- package/dist/register.js +1 -26
- package/package.json +10 -8
|
@@ -0,0 +1,922 @@
|
|
|
1
|
+
import { __commonJS, __require } from "../../../../../../_virtual/rolldown_runtime.js";
|
|
2
|
+
import { require_utils } from "./utils.js";
|
|
3
|
+
import { require_pending } from "./pending.js";
|
|
4
|
+
import { require_src } from "../../../../debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/index.js";
|
|
5
|
+
import { require_error_constants } from "./error-constants.js";
|
|
6
|
+
import { require_errors } from "./errors.js";
|
|
7
|
+
import { require_runnable } from "./runnable.js";
|
|
8
|
+
import { require_suite } from "./suite.js";
|
|
9
|
+
|
|
10
|
+
//#region ../../node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/runner.js
|
|
11
|
+
var require_runner = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/runner.js": ((exports, module) => {
|
|
12
|
+
/**
|
|
13
|
+
* @typedef {import('./types.d.ts').RunnerOptions} RunnerOptions
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Module dependencies.
|
|
17
|
+
* @private
|
|
18
|
+
*/
|
|
19
|
+
var EventEmitter = __require("node:events").EventEmitter;
|
|
20
|
+
var Pending = require_pending();
|
|
21
|
+
var utils = require_utils();
|
|
22
|
+
var debug = require_src()("mocha:runner");
|
|
23
|
+
var Runnable = require_runnable();
|
|
24
|
+
var Suite = require_suite();
|
|
25
|
+
var HOOK_TYPE_BEFORE_EACH = Suite.constants.HOOK_TYPE_BEFORE_EACH;
|
|
26
|
+
var HOOK_TYPE_AFTER_EACH = Suite.constants.HOOK_TYPE_AFTER_EACH;
|
|
27
|
+
var HOOK_TYPE_AFTER_ALL = Suite.constants.HOOK_TYPE_AFTER_ALL;
|
|
28
|
+
var HOOK_TYPE_BEFORE_ALL = Suite.constants.HOOK_TYPE_BEFORE_ALL;
|
|
29
|
+
var EVENT_ROOT_SUITE_RUN = Suite.constants.EVENT_ROOT_SUITE_RUN;
|
|
30
|
+
var STATE_FAILED = Runnable.constants.STATE_FAILED;
|
|
31
|
+
var STATE_PASSED = Runnable.constants.STATE_PASSED;
|
|
32
|
+
var STATE_PENDING = Runnable.constants.STATE_PENDING;
|
|
33
|
+
var stackFilter = utils.stackTraceFilter();
|
|
34
|
+
var stringify = utils.stringify;
|
|
35
|
+
const { createInvalidExceptionError, createUnsupportedError, createFatalError, isMochaError } = require_errors();
|
|
36
|
+
const { constants: errorConstants } = require_error_constants();
|
|
37
|
+
/**
|
|
38
|
+
* Non-enumerable globals.
|
|
39
|
+
* @private
|
|
40
|
+
* @readonly
|
|
41
|
+
*/
|
|
42
|
+
var globals = [
|
|
43
|
+
"setTimeout",
|
|
44
|
+
"clearTimeout",
|
|
45
|
+
"setInterval",
|
|
46
|
+
"clearInterval",
|
|
47
|
+
"XMLHttpRequest",
|
|
48
|
+
"Date",
|
|
49
|
+
"setImmediate",
|
|
50
|
+
"clearImmediate"
|
|
51
|
+
];
|
|
52
|
+
var constants = utils.defineConstants(
|
|
53
|
+
/**
|
|
54
|
+
* {@link Runner}-related constants. Used by reporters. Each event emits the corresponding object, unless otherwise indicated.
|
|
55
|
+
* @example
|
|
56
|
+
* const Mocha = require('mocha');
|
|
57
|
+
* const Base = Mocha.reporters.Base;
|
|
58
|
+
* const {
|
|
59
|
+
* EVENT_HOOK_BEGIN,
|
|
60
|
+
* EVENT_TEST_PASS,
|
|
61
|
+
* EVENT_TEST_FAIL,
|
|
62
|
+
* EVENT_TEST_END
|
|
63
|
+
* } = Mocha.Runner.constants
|
|
64
|
+
*
|
|
65
|
+
* function MyReporter(runner, options) {
|
|
66
|
+
* Base.call(this, runner, options);
|
|
67
|
+
*
|
|
68
|
+
* runner.on(EVENT_HOOK_BEGIN, function(hook) {
|
|
69
|
+
* console.log('hook called: ', hook.title);
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* runner.on(EVENT_TEST_PASS, function(test) {
|
|
73
|
+
* console.log('pass: %s', test.fullTitle());
|
|
74
|
+
* });
|
|
75
|
+
*
|
|
76
|
+
* runner.on(EVENT_TEST_FAIL, function(test, err) {
|
|
77
|
+
* console.log('fail: %s -- error: %s', test.fullTitle(), err.message);
|
|
78
|
+
* });
|
|
79
|
+
*
|
|
80
|
+
* runner.on(EVENT_TEST_END, function() {
|
|
81
|
+
* console.log('end: %d/%d', runner.stats.passes, runner.stats.tests);
|
|
82
|
+
* });
|
|
83
|
+
* }
|
|
84
|
+
*
|
|
85
|
+
* module.exports = MyReporter;
|
|
86
|
+
*
|
|
87
|
+
* @public
|
|
88
|
+
* @memberof Runner
|
|
89
|
+
* @readonly
|
|
90
|
+
* @alias constants
|
|
91
|
+
* @static
|
|
92
|
+
* @enum {string}
|
|
93
|
+
*/
|
|
94
|
+
{
|
|
95
|
+
EVENT_HOOK_BEGIN: "hook",
|
|
96
|
+
EVENT_HOOK_END: "hook end",
|
|
97
|
+
EVENT_RUN_BEGIN: "start",
|
|
98
|
+
EVENT_DELAY_BEGIN: "waiting",
|
|
99
|
+
EVENT_DELAY_END: "ready",
|
|
100
|
+
EVENT_RUN_END: "end",
|
|
101
|
+
EVENT_SUITE_BEGIN: "suite",
|
|
102
|
+
EVENT_SUITE_END: "suite end",
|
|
103
|
+
EVENT_TEST_BEGIN: "test",
|
|
104
|
+
EVENT_TEST_END: "test end",
|
|
105
|
+
EVENT_TEST_FAIL: "fail",
|
|
106
|
+
EVENT_TEST_PASS: "pass",
|
|
107
|
+
EVENT_TEST_PENDING: "pending",
|
|
108
|
+
EVENT_TEST_RETRY: "retry",
|
|
109
|
+
STATE_IDLE: "idle",
|
|
110
|
+
STATE_RUNNING: "running",
|
|
111
|
+
STATE_STOPPED: "stopped"
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
var Runner = class extends EventEmitter {
|
|
115
|
+
/**
|
|
116
|
+
* Initialize a `Runner` at the Root {@link Suite}, which represents a hierarchy of {@link Suite|Suites} and {@link Test|Tests}.
|
|
117
|
+
*
|
|
118
|
+
* @extends external:EventEmitter
|
|
119
|
+
* @public
|
|
120
|
+
* @class
|
|
121
|
+
* @param {Suite} suite - Root suite
|
|
122
|
+
* @param {Object} [opts] - Settings object
|
|
123
|
+
* @param {boolean} [opts.cleanReferencesAfterRun] - Whether to clean references to test fns and hooks when a suite is done.
|
|
124
|
+
* @param {boolean} [opts.delay] - Whether to delay execution of root suite until ready.
|
|
125
|
+
* @param {boolean} [opts.dryRun] - Whether to report tests without running them.
|
|
126
|
+
* @param {boolean} [opts.failZero] - Whether to fail test run if zero tests encountered.
|
|
127
|
+
*/
|
|
128
|
+
constructor(suite, opts = {}) {
|
|
129
|
+
super();
|
|
130
|
+
var self = this;
|
|
131
|
+
this._globals = [];
|
|
132
|
+
this._abort = false;
|
|
133
|
+
this.suite = suite;
|
|
134
|
+
this._opts = opts;
|
|
135
|
+
this.state = constants.STATE_IDLE;
|
|
136
|
+
this.total = suite.total();
|
|
137
|
+
this.failures = 0;
|
|
138
|
+
/**
|
|
139
|
+
* @type {Map<EventEmitter,Map<string,Set<EventListener>>>}
|
|
140
|
+
*/
|
|
141
|
+
this._eventListeners = /* @__PURE__ */ new Map();
|
|
142
|
+
this.on(constants.EVENT_TEST_END, function(test) {
|
|
143
|
+
if (test.type === "test" && test.retriedTest() && test.parent) {
|
|
144
|
+
var idx = test.parent.tests && test.parent.tests.indexOf(test.retriedTest());
|
|
145
|
+
if (idx > -1) test.parent.tests[idx] = test;
|
|
146
|
+
}
|
|
147
|
+
self.checkGlobals(test);
|
|
148
|
+
});
|
|
149
|
+
this.on(constants.EVENT_HOOK_END, function(hook) {
|
|
150
|
+
self.checkGlobals(hook);
|
|
151
|
+
});
|
|
152
|
+
this._defaultGrep = /.*/;
|
|
153
|
+
this.grep(this._defaultGrep);
|
|
154
|
+
this.globals(this.globalProps());
|
|
155
|
+
this.uncaught = this._uncaught.bind(this);
|
|
156
|
+
this.unhandled = (reason, promise) => {
|
|
157
|
+
if (isMochaError(reason)) {
|
|
158
|
+
debug("trapped unhandled rejection coming out of Mocha; forwarding to uncaught handler:", reason);
|
|
159
|
+
this.uncaught(reason);
|
|
160
|
+
} else {
|
|
161
|
+
debug("trapped unhandled rejection from (probably) user code; re-emitting on process");
|
|
162
|
+
this._removeEventListener(process, "unhandledRejection", this.unhandled);
|
|
163
|
+
try {
|
|
164
|
+
process.emit("unhandledRejection", reason, promise);
|
|
165
|
+
} finally {
|
|
166
|
+
this._addEventListener(process, "unhandledRejection", this.unhandled);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* Wrapper for setImmediate, process.nextTick, or browser polyfill.
|
|
174
|
+
*
|
|
175
|
+
* @param {Function} fn
|
|
176
|
+
* @private
|
|
177
|
+
*/
|
|
178
|
+
Runner.immediately = global.setImmediate || process.nextTick;
|
|
179
|
+
/**
|
|
180
|
+
* Replacement for `target.on(eventName, listener)` that does bookkeeping to remove them when this runner instance is disposed.
|
|
181
|
+
* @param {EventEmitter} target - The `EventEmitter`
|
|
182
|
+
* @param {string} eventName - The event name
|
|
183
|
+
* @param {string} fn - Listener function
|
|
184
|
+
* @private
|
|
185
|
+
*/
|
|
186
|
+
Runner.prototype._addEventListener = function(target, eventName, listener) {
|
|
187
|
+
debug("_addEventListener(): adding for event %s; %d current listeners", eventName, target.listenerCount(eventName));
|
|
188
|
+
/* istanbul ignore next */
|
|
189
|
+
if (this._eventListeners.has(target) && this._eventListeners.get(target).has(eventName) && this._eventListeners.get(target).get(eventName).has(listener)) {
|
|
190
|
+
debug("warning: tried to attach duplicate event listener for %s", eventName);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
target.on(eventName, listener);
|
|
194
|
+
const targetListeners = this._eventListeners.has(target) ? this._eventListeners.get(target) : /* @__PURE__ */ new Map();
|
|
195
|
+
const targetEventListeners = targetListeners.has(eventName) ? targetListeners.get(eventName) : /* @__PURE__ */ new Set();
|
|
196
|
+
targetEventListeners.add(listener);
|
|
197
|
+
targetListeners.set(eventName, targetEventListeners);
|
|
198
|
+
this._eventListeners.set(target, targetListeners);
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
201
|
+
* Replacement for `target.removeListener(eventName, listener)` that also updates the bookkeeping.
|
|
202
|
+
* @param {EventEmitter} target - The `EventEmitter`
|
|
203
|
+
* @param {string} eventName - The event name
|
|
204
|
+
* @param {function} listener - Listener function
|
|
205
|
+
* @private
|
|
206
|
+
*/
|
|
207
|
+
Runner.prototype._removeEventListener = function(target, eventName, listener) {
|
|
208
|
+
target.removeListener(eventName, listener);
|
|
209
|
+
if (this._eventListeners.has(target)) {
|
|
210
|
+
const targetListeners = this._eventListeners.get(target);
|
|
211
|
+
if (targetListeners.has(eventName)) {
|
|
212
|
+
const targetEventListeners = targetListeners.get(eventName);
|
|
213
|
+
targetEventListeners.delete(listener);
|
|
214
|
+
if (!targetEventListeners.size) targetListeners.delete(eventName);
|
|
215
|
+
}
|
|
216
|
+
if (!targetListeners.size) this._eventListeners.delete(target);
|
|
217
|
+
} else debug("trying to remove listener for untracked object %s", target);
|
|
218
|
+
};
|
|
219
|
+
/**
|
|
220
|
+
* Removes all event handlers set during a run on this instance.
|
|
221
|
+
* Remark: this does _not_ clean/dispose the tests or suites themselves.
|
|
222
|
+
*/
|
|
223
|
+
Runner.prototype.dispose = function() {
|
|
224
|
+
this.removeAllListeners();
|
|
225
|
+
this._eventListeners.forEach((targetListeners, target) => {
|
|
226
|
+
targetListeners.forEach((targetEventListeners, eventName) => {
|
|
227
|
+
targetEventListeners.forEach((listener) => {
|
|
228
|
+
target.removeListener(eventName, listener);
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
this._eventListeners.clear();
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
235
|
+
* Run tests with full titles matching `re`. Updates runner.total
|
|
236
|
+
* with number of tests matched.
|
|
237
|
+
*
|
|
238
|
+
* @public
|
|
239
|
+
* @memberof Runner
|
|
240
|
+
* @param {RegExp} re
|
|
241
|
+
* @param {boolean} invert
|
|
242
|
+
* @return {Runner} Runner instance.
|
|
243
|
+
*/
|
|
244
|
+
Runner.prototype.grep = function(re, invert) {
|
|
245
|
+
debug("grep(): setting to %s", re);
|
|
246
|
+
this._grep = re;
|
|
247
|
+
this._invert = invert;
|
|
248
|
+
this.total = this.grepTotal(this.suite);
|
|
249
|
+
return this;
|
|
250
|
+
};
|
|
251
|
+
/**
|
|
252
|
+
* Returns the number of tests matching the grep search for the
|
|
253
|
+
* given suite.
|
|
254
|
+
*
|
|
255
|
+
* @memberof Runner
|
|
256
|
+
* @public
|
|
257
|
+
* @param {Suite} suite
|
|
258
|
+
* @return {number}
|
|
259
|
+
*/
|
|
260
|
+
Runner.prototype.grepTotal = function(suite) {
|
|
261
|
+
var self = this;
|
|
262
|
+
var total = 0;
|
|
263
|
+
suite.eachTest(function(test) {
|
|
264
|
+
var match = self._grep.test(test.fullTitle());
|
|
265
|
+
if (self._invert) match = !match;
|
|
266
|
+
if (match) total++;
|
|
267
|
+
});
|
|
268
|
+
return total;
|
|
269
|
+
};
|
|
270
|
+
/**
|
|
271
|
+
* Return a list of global properties.
|
|
272
|
+
*
|
|
273
|
+
* @return {Array}
|
|
274
|
+
* @private
|
|
275
|
+
*/
|
|
276
|
+
Runner.prototype.globalProps = function() {
|
|
277
|
+
var props = Object.keys(global);
|
|
278
|
+
for (var i = 0; i < globals.length; ++i) {
|
|
279
|
+
if (~props.indexOf(globals[i])) continue;
|
|
280
|
+
props.push(globals[i]);
|
|
281
|
+
}
|
|
282
|
+
return props;
|
|
283
|
+
};
|
|
284
|
+
/**
|
|
285
|
+
* Allow the given `arr` of globals.
|
|
286
|
+
*
|
|
287
|
+
* @public
|
|
288
|
+
* @memberof Runner
|
|
289
|
+
* @param {Array} arr
|
|
290
|
+
* @return {Runner} Runner instance.
|
|
291
|
+
*/
|
|
292
|
+
Runner.prototype.globals = function(arr) {
|
|
293
|
+
if (!arguments.length) return this._globals;
|
|
294
|
+
debug("globals(): setting to %O", arr);
|
|
295
|
+
this._globals = this._globals.concat(arr);
|
|
296
|
+
return this;
|
|
297
|
+
};
|
|
298
|
+
/**
|
|
299
|
+
* Check for global variable leaks.
|
|
300
|
+
*
|
|
301
|
+
* @private
|
|
302
|
+
*/
|
|
303
|
+
Runner.prototype.checkGlobals = function(test) {
|
|
304
|
+
if (!this.checkLeaks) return;
|
|
305
|
+
var ok = this._globals;
|
|
306
|
+
var globals$1 = this.globalProps();
|
|
307
|
+
var leaks;
|
|
308
|
+
if (test) ok = ok.concat(test._allowedGlobals || []);
|
|
309
|
+
if (this.prevGlobalsLength === globals$1.length) return;
|
|
310
|
+
this.prevGlobalsLength = globals$1.length;
|
|
311
|
+
leaks = filterLeaks(ok, globals$1);
|
|
312
|
+
this._globals = this._globals.concat(leaks);
|
|
313
|
+
if (leaks.length) {
|
|
314
|
+
var msg = `global leak(s) detected: ${leaks.map((e) => `'${e}'`).join(", ")}`;
|
|
315
|
+
this.fail(test, new Error(msg));
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
/**
|
|
319
|
+
* Fail the given `test`.
|
|
320
|
+
*
|
|
321
|
+
* If `test` is a hook, failures work in the following pattern:
|
|
322
|
+
* - If bail, run corresponding `after each` and `after` hooks,
|
|
323
|
+
* then exit
|
|
324
|
+
* - Failed `before` hook skips all tests in a suite and subsuites,
|
|
325
|
+
* but jumps to corresponding `after` hook
|
|
326
|
+
* - Failed `before each` hook skips remaining tests in a
|
|
327
|
+
* suite and jumps to corresponding `after each` hook,
|
|
328
|
+
* which is run only once
|
|
329
|
+
* - Failed `after` hook does not alter execution order
|
|
330
|
+
* - Failed `after each` hook skips remaining tests in a
|
|
331
|
+
* suite and subsuites, but executes other `after each`
|
|
332
|
+
* hooks
|
|
333
|
+
*
|
|
334
|
+
* @private
|
|
335
|
+
* @param {Runnable} test
|
|
336
|
+
* @param {Error} err
|
|
337
|
+
* @param {boolean} [force=false] - Whether to fail a pending test.
|
|
338
|
+
*/
|
|
339
|
+
Runner.prototype.fail = function(test, err, force) {
|
|
340
|
+
force = force === true;
|
|
341
|
+
if (test.isPending() && !force) return;
|
|
342
|
+
if (this.state === constants.STATE_STOPPED) {
|
|
343
|
+
if (err.code === errorConstants.MULTIPLE_DONE) throw err;
|
|
344
|
+
throw createFatalError("Test failed after root suite execution completed!", err);
|
|
345
|
+
}
|
|
346
|
+
++this.failures;
|
|
347
|
+
debug("total number of failures: %d", this.failures);
|
|
348
|
+
test.state = STATE_FAILED;
|
|
349
|
+
if (!isError(err)) err = thrown2Error(err);
|
|
350
|
+
if (!this.fullStackTrace) {
|
|
351
|
+
const alreadyFiltered = /* @__PURE__ */ new Set();
|
|
352
|
+
let currentErr = err;
|
|
353
|
+
while (currentErr && currentErr.stack && !alreadyFiltered.has(currentErr)) {
|
|
354
|
+
alreadyFiltered.add(currentErr);
|
|
355
|
+
try {
|
|
356
|
+
currentErr.stack = stackFilter(currentErr.stack);
|
|
357
|
+
} catch (ignore) {}
|
|
358
|
+
currentErr = currentErr.cause;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
this.emit(constants.EVENT_TEST_FAIL, test, err);
|
|
362
|
+
};
|
|
363
|
+
/**
|
|
364
|
+
* Run hook `name` callbacks and then invoke `fn()`.
|
|
365
|
+
*
|
|
366
|
+
* @private
|
|
367
|
+
* @param {string} name
|
|
368
|
+
* @param {Function} fn
|
|
369
|
+
*/
|
|
370
|
+
Runner.prototype.hook = function(name, fn) {
|
|
371
|
+
if (this._opts.dryRun) return fn();
|
|
372
|
+
var suite = this.suite;
|
|
373
|
+
var hooks = suite.getHooks(name);
|
|
374
|
+
var self = this;
|
|
375
|
+
function next(i) {
|
|
376
|
+
var hook = hooks[i];
|
|
377
|
+
if (!hook) return fn();
|
|
378
|
+
self.currentRunnable = hook;
|
|
379
|
+
if (name === HOOK_TYPE_BEFORE_ALL) hook.ctx.currentTest = hook.parent.tests[0];
|
|
380
|
+
else if (name === HOOK_TYPE_AFTER_ALL) hook.ctx.currentTest = hook.parent.tests[hook.parent.tests.length - 1];
|
|
381
|
+
else hook.ctx.currentTest = self.test;
|
|
382
|
+
setHookTitle(hook);
|
|
383
|
+
hook.allowUncaught = self.allowUncaught;
|
|
384
|
+
self.emit(constants.EVENT_HOOK_BEGIN, hook);
|
|
385
|
+
if (!hook.listeners("error").length) self._addEventListener(hook, "error", function(err) {
|
|
386
|
+
self.fail(hook, err);
|
|
387
|
+
});
|
|
388
|
+
hook.run(function cbHookRun(err) {
|
|
389
|
+
var testError = hook.error();
|
|
390
|
+
if (testError) self.fail(self.test, testError);
|
|
391
|
+
if (hook.pending) if (name === HOOK_TYPE_AFTER_EACH) {
|
|
392
|
+
if (self.test) self.test.pending = true;
|
|
393
|
+
} else if (name === HOOK_TYPE_BEFORE_EACH) {
|
|
394
|
+
if (self.test) self.test.pending = true;
|
|
395
|
+
self.emit(constants.EVENT_HOOK_END, hook);
|
|
396
|
+
hook.pending = false;
|
|
397
|
+
return fn(/* @__PURE__ */ new Error("abort hookDown"));
|
|
398
|
+
} else if (name === HOOK_TYPE_BEFORE_ALL) {
|
|
399
|
+
suite.tests.forEach(function(test) {
|
|
400
|
+
test.pending = true;
|
|
401
|
+
});
|
|
402
|
+
suite.suites.forEach(function(suite$1) {
|
|
403
|
+
suite$1.pending = true;
|
|
404
|
+
});
|
|
405
|
+
hooks = [];
|
|
406
|
+
} else {
|
|
407
|
+
hook.pending = false;
|
|
408
|
+
var errForbid = createUnsupportedError("`this.skip` forbidden");
|
|
409
|
+
self.fail(hook, errForbid);
|
|
410
|
+
return fn(errForbid);
|
|
411
|
+
}
|
|
412
|
+
else if (err) {
|
|
413
|
+
self.fail(hook, err);
|
|
414
|
+
return fn(err);
|
|
415
|
+
}
|
|
416
|
+
self.emit(constants.EVENT_HOOK_END, hook);
|
|
417
|
+
delete hook.ctx.currentTest;
|
|
418
|
+
setHookTitle(hook);
|
|
419
|
+
next(++i);
|
|
420
|
+
});
|
|
421
|
+
function setHookTitle(hook$1) {
|
|
422
|
+
hook$1.originalTitle = hook$1.originalTitle || hook$1.title;
|
|
423
|
+
if (hook$1.ctx && hook$1.ctx.currentTest) hook$1.title = `${hook$1.originalTitle} for "${hook$1.ctx.currentTest.title}"`;
|
|
424
|
+
else {
|
|
425
|
+
var parentTitle;
|
|
426
|
+
if (hook$1.parent.title) parentTitle = hook$1.parent.title;
|
|
427
|
+
else parentTitle = hook$1.parent.root ? "{root}" : "";
|
|
428
|
+
hook$1.title = `${hook$1.originalTitle} in "${parentTitle}"`;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
Runner.immediately(function() {
|
|
433
|
+
next(0);
|
|
434
|
+
});
|
|
435
|
+
};
|
|
436
|
+
/**
|
|
437
|
+
* Run hook `name` for the given array of `suites`
|
|
438
|
+
* in order, and callback `fn(err, errSuite)`.
|
|
439
|
+
*
|
|
440
|
+
* @private
|
|
441
|
+
* @param {string} name
|
|
442
|
+
* @param {Array} suites
|
|
443
|
+
* @param {Function} fn
|
|
444
|
+
*/
|
|
445
|
+
Runner.prototype.hooks = function(name, suites, fn) {
|
|
446
|
+
var self = this;
|
|
447
|
+
var orig = this.suite;
|
|
448
|
+
function next(suite) {
|
|
449
|
+
self.suite = suite;
|
|
450
|
+
if (!suite) {
|
|
451
|
+
self.suite = orig;
|
|
452
|
+
return fn();
|
|
453
|
+
}
|
|
454
|
+
self.hook(name, function(err) {
|
|
455
|
+
if (err) {
|
|
456
|
+
var errSuite = self.suite;
|
|
457
|
+
self.suite = orig;
|
|
458
|
+
return fn(err, errSuite);
|
|
459
|
+
}
|
|
460
|
+
next(suites.pop());
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
next(suites.pop());
|
|
464
|
+
};
|
|
465
|
+
/**
|
|
466
|
+
* Run 'afterEach' hooks from bottom up.
|
|
467
|
+
*
|
|
468
|
+
* @param {String} name
|
|
469
|
+
* @param {Function} fn
|
|
470
|
+
* @private
|
|
471
|
+
*/
|
|
472
|
+
Runner.prototype.hookUp = function(name, fn) {
|
|
473
|
+
var suites = [this.suite].concat(this.parents()).reverse();
|
|
474
|
+
this.hooks(name, suites, fn);
|
|
475
|
+
};
|
|
476
|
+
/**
|
|
477
|
+
* Run 'beforeEach' hooks from top level down.
|
|
478
|
+
*
|
|
479
|
+
* @param {String} name
|
|
480
|
+
* @param {Function} fn
|
|
481
|
+
* @private
|
|
482
|
+
*/
|
|
483
|
+
Runner.prototype.hookDown = function(name, fn) {
|
|
484
|
+
var suites = [this.suite].concat(this.parents());
|
|
485
|
+
this.hooks(name, suites, fn);
|
|
486
|
+
};
|
|
487
|
+
/**
|
|
488
|
+
* Return an array of parent Suites from
|
|
489
|
+
* closest to furthest.
|
|
490
|
+
*
|
|
491
|
+
* @return {Array}
|
|
492
|
+
* @private
|
|
493
|
+
*/
|
|
494
|
+
Runner.prototype.parents = function() {
|
|
495
|
+
var suite = this.suite;
|
|
496
|
+
var suites = [];
|
|
497
|
+
while (suite.parent) {
|
|
498
|
+
suite = suite.parent;
|
|
499
|
+
suites.push(suite);
|
|
500
|
+
}
|
|
501
|
+
return suites;
|
|
502
|
+
};
|
|
503
|
+
/**
|
|
504
|
+
* Run the current test and callback `fn(err)`.
|
|
505
|
+
*
|
|
506
|
+
* @param {Function} fn
|
|
507
|
+
* @private
|
|
508
|
+
*/
|
|
509
|
+
Runner.prototype.runTest = function(fn) {
|
|
510
|
+
if (this._opts.dryRun) return Runner.immediately(fn);
|
|
511
|
+
var self = this;
|
|
512
|
+
var test = this.test;
|
|
513
|
+
if (!test) return;
|
|
514
|
+
if (this.asyncOnly) test.asyncOnly = true;
|
|
515
|
+
this._addEventListener(test, "error", function(err) {
|
|
516
|
+
self.fail(test, err);
|
|
517
|
+
});
|
|
518
|
+
if (this.allowUncaught) {
|
|
519
|
+
test.allowUncaught = true;
|
|
520
|
+
return test.run(fn);
|
|
521
|
+
}
|
|
522
|
+
try {
|
|
523
|
+
test.run(fn);
|
|
524
|
+
} catch (err) {
|
|
525
|
+
fn(err);
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
/**
|
|
529
|
+
* Run tests in the given `suite` and invoke the callback `fn()` when complete.
|
|
530
|
+
*
|
|
531
|
+
* @private
|
|
532
|
+
* @param {Suite} suite
|
|
533
|
+
* @param {Function} fn
|
|
534
|
+
*/
|
|
535
|
+
Runner.prototype.runTests = function(suite, fn) {
|
|
536
|
+
var self = this;
|
|
537
|
+
var tests = suite.tests.slice();
|
|
538
|
+
var test;
|
|
539
|
+
function hookErr(_, errSuite, after) {
|
|
540
|
+
var orig = self.suite;
|
|
541
|
+
self.suite = after ? errSuite.parent : errSuite;
|
|
542
|
+
if (self.suite) self.hookUp(HOOK_TYPE_AFTER_EACH, function(err2, errSuite2) {
|
|
543
|
+
self.suite = orig;
|
|
544
|
+
if (err2) return hookErr(err2, errSuite2, true);
|
|
545
|
+
fn(errSuite);
|
|
546
|
+
});
|
|
547
|
+
else {
|
|
548
|
+
self.suite = orig;
|
|
549
|
+
fn(errSuite);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
function next(err, errSuite) {
|
|
553
|
+
if (self.failures && suite._bail) tests = [];
|
|
554
|
+
if (self._abort) return fn();
|
|
555
|
+
if (err) return hookErr(err, errSuite, true);
|
|
556
|
+
test = tests.shift();
|
|
557
|
+
if (!test) return fn();
|
|
558
|
+
var match = self._grep.test(test.fullTitle());
|
|
559
|
+
if (self._invert) match = !match;
|
|
560
|
+
if (!match) {
|
|
561
|
+
if (self._grep !== self._defaultGrep) Runner.immediately(next);
|
|
562
|
+
else next();
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
if (test.isPending()) {
|
|
566
|
+
if (self.forbidPending) self.fail(test, /* @__PURE__ */ new Error("Pending test forbidden"), true);
|
|
567
|
+
else {
|
|
568
|
+
test.state = STATE_PENDING;
|
|
569
|
+
self.emit(constants.EVENT_TEST_PENDING, test);
|
|
570
|
+
}
|
|
571
|
+
self.emit(constants.EVENT_TEST_END, test);
|
|
572
|
+
return next();
|
|
573
|
+
}
|
|
574
|
+
self.emit(constants.EVENT_TEST_BEGIN, self.test = test);
|
|
575
|
+
self.hookDown(HOOK_TYPE_BEFORE_EACH, function(err$1, errSuite$1) {
|
|
576
|
+
if (test.isPending()) {
|
|
577
|
+
if (self.forbidPending) self.fail(test, /* @__PURE__ */ new Error("Pending test forbidden"), true);
|
|
578
|
+
else {
|
|
579
|
+
test.state = STATE_PENDING;
|
|
580
|
+
self.emit(constants.EVENT_TEST_PENDING, test);
|
|
581
|
+
}
|
|
582
|
+
self.emit(constants.EVENT_TEST_END, test);
|
|
583
|
+
var origSuite = self.suite;
|
|
584
|
+
self.suite = errSuite$1 || self.suite;
|
|
585
|
+
return self.hookUp(HOOK_TYPE_AFTER_EACH, function(e, eSuite) {
|
|
586
|
+
self.suite = origSuite;
|
|
587
|
+
next(e, eSuite);
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
if (err$1) return hookErr(err$1, errSuite$1, false);
|
|
591
|
+
self.currentRunnable = self.test;
|
|
592
|
+
self.runTest(function(err$2) {
|
|
593
|
+
test = self.test;
|
|
594
|
+
if (test.pending) {
|
|
595
|
+
if (self.forbidPending) self.fail(test, /* @__PURE__ */ new Error("Pending test forbidden"), true);
|
|
596
|
+
else {
|
|
597
|
+
test.state = STATE_PENDING;
|
|
598
|
+
self.emit(constants.EVENT_TEST_PENDING, test);
|
|
599
|
+
}
|
|
600
|
+
self.emit(constants.EVENT_TEST_END, test);
|
|
601
|
+
return self.hookUp(HOOK_TYPE_AFTER_EACH, next);
|
|
602
|
+
} else if (err$2) {
|
|
603
|
+
var retry = test.currentRetry();
|
|
604
|
+
if (retry < test.retries()) {
|
|
605
|
+
var clonedTest = test.clone();
|
|
606
|
+
clonedTest.currentRetry(retry + 1);
|
|
607
|
+
tests.unshift(clonedTest);
|
|
608
|
+
self.emit(constants.EVENT_TEST_RETRY, test, err$2);
|
|
609
|
+
return self.hookUp(HOOK_TYPE_AFTER_EACH, next);
|
|
610
|
+
} else self.fail(test, err$2);
|
|
611
|
+
self.emit(constants.EVENT_TEST_END, test);
|
|
612
|
+
return self.hookUp(HOOK_TYPE_AFTER_EACH, next);
|
|
613
|
+
}
|
|
614
|
+
test.state = STATE_PASSED;
|
|
615
|
+
self.emit(constants.EVENT_TEST_PASS, test);
|
|
616
|
+
self.emit(constants.EVENT_TEST_END, test);
|
|
617
|
+
self.hookUp(HOOK_TYPE_AFTER_EACH, next);
|
|
618
|
+
});
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
this.next = next;
|
|
622
|
+
this.hookErr = hookErr;
|
|
623
|
+
next();
|
|
624
|
+
};
|
|
625
|
+
/**
|
|
626
|
+
* Run the given `suite` and invoke the callback `fn()` when complete.
|
|
627
|
+
*
|
|
628
|
+
* @private
|
|
629
|
+
* @param {Suite} suite
|
|
630
|
+
* @param {Function} fn
|
|
631
|
+
*/
|
|
632
|
+
Runner.prototype.runSuite = function(suite, fn) {
|
|
633
|
+
var i = 0;
|
|
634
|
+
var self = this;
|
|
635
|
+
var total = this.grepTotal(suite);
|
|
636
|
+
debug("runSuite(): running %s", suite.fullTitle());
|
|
637
|
+
if (!total || self.failures && suite._bail) {
|
|
638
|
+
debug("runSuite(): bailing");
|
|
639
|
+
return fn();
|
|
640
|
+
}
|
|
641
|
+
this.emit(constants.EVENT_SUITE_BEGIN, this.suite = suite);
|
|
642
|
+
function next(errSuite) {
|
|
643
|
+
if (errSuite) {
|
|
644
|
+
if (errSuite === suite) return done();
|
|
645
|
+
return done(errSuite);
|
|
646
|
+
}
|
|
647
|
+
if (self._abort) return done();
|
|
648
|
+
var curr = suite.suites[i++];
|
|
649
|
+
if (!curr) return done();
|
|
650
|
+
if (self._grep !== self._defaultGrep) Runner.immediately(function() {
|
|
651
|
+
self.runSuite(curr, next);
|
|
652
|
+
});
|
|
653
|
+
else self.runSuite(curr, next);
|
|
654
|
+
}
|
|
655
|
+
function done(errSuite) {
|
|
656
|
+
self.suite = suite;
|
|
657
|
+
self.nextSuite = next;
|
|
658
|
+
delete self.test;
|
|
659
|
+
self.hook(HOOK_TYPE_AFTER_ALL, function() {
|
|
660
|
+
self.emit(constants.EVENT_SUITE_END, suite);
|
|
661
|
+
fn(errSuite);
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
this.nextSuite = next;
|
|
665
|
+
this.hook(HOOK_TYPE_BEFORE_ALL, function(err) {
|
|
666
|
+
if (err) return done();
|
|
667
|
+
self.runTests(suite, next);
|
|
668
|
+
});
|
|
669
|
+
};
|
|
670
|
+
/**
|
|
671
|
+
* Handle uncaught exceptions within runner.
|
|
672
|
+
*
|
|
673
|
+
* This function is bound to the instance as `Runner#uncaught` at instantiation
|
|
674
|
+
* time. It's intended to be listening on the `Process.uncaughtException` event.
|
|
675
|
+
* In order to not leak EE listeners, we need to ensure no more than a single
|
|
676
|
+
* `uncaughtException` listener exists per `Runner`. The only way to do
|
|
677
|
+
* this--because this function needs the context (and we don't have lambdas)--is
|
|
678
|
+
* to use `Function.prototype.bind`. We need strict equality to unregister and
|
|
679
|
+
* _only_ unregister the _one_ listener we set from the
|
|
680
|
+
* `Process.uncaughtException` event; would be poor form to just remove
|
|
681
|
+
* everything. See {@link Runner#run} for where the event listener is registered
|
|
682
|
+
* and unregistered.
|
|
683
|
+
* @param {Error} err - Some uncaught error
|
|
684
|
+
* @private
|
|
685
|
+
*/
|
|
686
|
+
Runner.prototype._uncaught = function(err) {
|
|
687
|
+
if (!(this instanceof Runner)) throw createFatalError("Runner#uncaught() called with invalid context", this);
|
|
688
|
+
if (err instanceof Pending) {
|
|
689
|
+
debug("uncaught(): caught a Pending");
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
if (this.allowUncaught && !utils.isBrowser()) {
|
|
693
|
+
debug("uncaught(): bubbling exception due to --allow-uncaught");
|
|
694
|
+
throw err;
|
|
695
|
+
}
|
|
696
|
+
if (this.state === constants.STATE_STOPPED) {
|
|
697
|
+
debug("uncaught(): throwing after run has completed!");
|
|
698
|
+
throw err;
|
|
699
|
+
}
|
|
700
|
+
if (err) debug("uncaught(): got truthy exception %O", err);
|
|
701
|
+
else {
|
|
702
|
+
debug("uncaught(): undefined/falsy exception");
|
|
703
|
+
err = createInvalidExceptionError("Caught falsy/undefined exception which would otherwise be uncaught. No stack trace found; try a debugger", err);
|
|
704
|
+
}
|
|
705
|
+
if (!isError(err)) {
|
|
706
|
+
err = thrown2Error(err);
|
|
707
|
+
debug("uncaught(): converted \"error\" %o to Error", err);
|
|
708
|
+
}
|
|
709
|
+
err.uncaught = true;
|
|
710
|
+
var runnable = this.currentRunnable;
|
|
711
|
+
if (!runnable) {
|
|
712
|
+
runnable = new Runnable("Uncaught error outside test suite");
|
|
713
|
+
debug("uncaught(): no current Runnable; created a phony one");
|
|
714
|
+
runnable.parent = this.suite;
|
|
715
|
+
if (this.state === constants.STATE_RUNNING) {
|
|
716
|
+
debug("uncaught(): failing gracefully");
|
|
717
|
+
this.fail(runnable, err);
|
|
718
|
+
} else {
|
|
719
|
+
debug("uncaught(): test run has not yet started; unrecoverable");
|
|
720
|
+
this.emit(constants.EVENT_RUN_BEGIN);
|
|
721
|
+
this.fail(runnable, err);
|
|
722
|
+
this.emit(constants.EVENT_RUN_END);
|
|
723
|
+
}
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
runnable.clearTimeout();
|
|
727
|
+
if (runnable.isFailed()) {
|
|
728
|
+
debug("uncaught(): Runnable has already failed");
|
|
729
|
+
return;
|
|
730
|
+
} else if (runnable.isPending()) {
|
|
731
|
+
debug("uncaught(): pending Runnable wound up failing!");
|
|
732
|
+
this.fail(runnable, err, true);
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
if (runnable.isPassed()) {
|
|
736
|
+
debug("uncaught(): Runnable has already passed; bailing gracefully");
|
|
737
|
+
this.fail(runnable, err);
|
|
738
|
+
this.abort();
|
|
739
|
+
} else {
|
|
740
|
+
debug("uncaught(): forcing Runnable to complete with Error");
|
|
741
|
+
return runnable.callback(err);
|
|
742
|
+
}
|
|
743
|
+
};
|
|
744
|
+
/**
|
|
745
|
+
* Run the root suite and invoke `fn(failures)`
|
|
746
|
+
* on completion.
|
|
747
|
+
*
|
|
748
|
+
* @public
|
|
749
|
+
* @memberof Runner
|
|
750
|
+
* @param {Function} fn - Callback when finished
|
|
751
|
+
* @param {RunnerOptions} [opts] - For subclasses
|
|
752
|
+
* @returns {Runner} Runner instance.
|
|
753
|
+
*/
|
|
754
|
+
Runner.prototype.run = function(fn, opts = {}) {
|
|
755
|
+
var rootSuite = this.suite;
|
|
756
|
+
var options = opts.options || {};
|
|
757
|
+
debug("run(): got options: %O", options);
|
|
758
|
+
fn = fn || function() {};
|
|
759
|
+
const end = () => {
|
|
760
|
+
if (!this.total && this._opts.failZero) this.failures = 1;
|
|
761
|
+
debug("run(): root suite completed; emitting %s", constants.EVENT_RUN_END);
|
|
762
|
+
this.emit(constants.EVENT_RUN_END);
|
|
763
|
+
};
|
|
764
|
+
const begin = () => {
|
|
765
|
+
debug("run(): emitting %s", constants.EVENT_RUN_BEGIN);
|
|
766
|
+
this.emit(constants.EVENT_RUN_BEGIN);
|
|
767
|
+
debug("run(): emitted %s", constants.EVENT_RUN_BEGIN);
|
|
768
|
+
this.runSuite(rootSuite, end);
|
|
769
|
+
};
|
|
770
|
+
const prepare = () => {
|
|
771
|
+
debug("run(): starting");
|
|
772
|
+
if (rootSuite.hasOnly()) {
|
|
773
|
+
rootSuite.filterOnly();
|
|
774
|
+
debug("run(): filtered exclusive Runnables");
|
|
775
|
+
}
|
|
776
|
+
this.state = constants.STATE_RUNNING;
|
|
777
|
+
if (this._opts.delay) {
|
|
778
|
+
this.emit(constants.EVENT_DELAY_END);
|
|
779
|
+
debug("run(): \"delay\" ended");
|
|
780
|
+
}
|
|
781
|
+
return begin();
|
|
782
|
+
};
|
|
783
|
+
if (this._opts.cleanReferencesAfterRun) this.on(constants.EVENT_SUITE_END, (suite) => {
|
|
784
|
+
suite.cleanReferences();
|
|
785
|
+
});
|
|
786
|
+
this.on(constants.EVENT_RUN_END, function() {
|
|
787
|
+
this.state = constants.STATE_STOPPED;
|
|
788
|
+
debug("run(): emitted %s", constants.EVENT_RUN_END);
|
|
789
|
+
fn(this.failures);
|
|
790
|
+
});
|
|
791
|
+
this._removeEventListener(process, "uncaughtException", this.uncaught);
|
|
792
|
+
this._removeEventListener(process, "unhandledRejection", this.unhandled);
|
|
793
|
+
this._addEventListener(process, "uncaughtException", this.uncaught);
|
|
794
|
+
this._addEventListener(process, "unhandledRejection", this.unhandled);
|
|
795
|
+
if (this._opts.delay) {
|
|
796
|
+
this.emit(constants.EVENT_DELAY_BEGIN, rootSuite);
|
|
797
|
+
rootSuite.once(EVENT_ROOT_SUITE_RUN, prepare);
|
|
798
|
+
debug("run(): waiting for green light due to --delay");
|
|
799
|
+
} else Runner.immediately(prepare);
|
|
800
|
+
return this;
|
|
801
|
+
};
|
|
802
|
+
/**
|
|
803
|
+
* Toggle partial object linking behavior; used for building object references from
|
|
804
|
+
* unique ID's. Does nothing in serial mode, because the object references already exist.
|
|
805
|
+
* Subclasses can implement this (e.g., `ParallelBufferedRunner`)
|
|
806
|
+
* @abstract
|
|
807
|
+
* @param {boolean} [value] - If `true`, enable partial object linking, otherwise disable
|
|
808
|
+
* @returns {Runner}
|
|
809
|
+
* @chainable
|
|
810
|
+
* @public
|
|
811
|
+
* @example
|
|
812
|
+
* // this reporter needs proper object references when run in parallel mode
|
|
813
|
+
* class MyReporter {
|
|
814
|
+
* constructor(runner) {
|
|
815
|
+
* runner.linkPartialObjects(true)
|
|
816
|
+
* .on(EVENT_SUITE_BEGIN, suite => {
|
|
817
|
+
* // this Suite may be the same object...
|
|
818
|
+
* })
|
|
819
|
+
* .on(EVENT_TEST_BEGIN, test => {
|
|
820
|
+
* // ...as the `test.parent` property
|
|
821
|
+
* });
|
|
822
|
+
* }
|
|
823
|
+
* }
|
|
824
|
+
*/
|
|
825
|
+
Runner.prototype.linkPartialObjects = function() {
|
|
826
|
+
return this;
|
|
827
|
+
};
|
|
828
|
+
Runner.prototype.runAsync = async function runAsync(opts = {}) {
|
|
829
|
+
return new Promise((resolve) => {
|
|
830
|
+
this.run(resolve, opts);
|
|
831
|
+
});
|
|
832
|
+
};
|
|
833
|
+
/**
|
|
834
|
+
* Cleanly abort execution.
|
|
835
|
+
*
|
|
836
|
+
* @memberof Runner
|
|
837
|
+
* @public
|
|
838
|
+
* @return {Runner} Runner instance.
|
|
839
|
+
*/
|
|
840
|
+
Runner.prototype.abort = function() {
|
|
841
|
+
debug("abort(): aborting");
|
|
842
|
+
this._abort = true;
|
|
843
|
+
return this;
|
|
844
|
+
};
|
|
845
|
+
/**
|
|
846
|
+
* Returns `true` if Mocha is running in parallel mode. For reporters.
|
|
847
|
+
*
|
|
848
|
+
* Subclasses should return an appropriate value.
|
|
849
|
+
* @public
|
|
850
|
+
* @returns {false}
|
|
851
|
+
*/
|
|
852
|
+
Runner.prototype.isParallelMode = function isParallelMode() {
|
|
853
|
+
return false;
|
|
854
|
+
};
|
|
855
|
+
/**
|
|
856
|
+
* Configures an alternate reporter for worker processes to use. Subclasses
|
|
857
|
+
* using worker processes should implement this.
|
|
858
|
+
* @public
|
|
859
|
+
* @param {string} path - Absolute path to alternate reporter for worker processes to use
|
|
860
|
+
* @returns {Runner}
|
|
861
|
+
* @throws When in serial mode
|
|
862
|
+
* @chainable
|
|
863
|
+
* @abstract
|
|
864
|
+
*/
|
|
865
|
+
Runner.prototype.workerReporter = function() {
|
|
866
|
+
throw createUnsupportedError("workerReporter() not supported in serial mode");
|
|
867
|
+
};
|
|
868
|
+
/**
|
|
869
|
+
* Filter leaks with the given globals flagged as `ok`.
|
|
870
|
+
*
|
|
871
|
+
* @private
|
|
872
|
+
* @param {Array} ok
|
|
873
|
+
* @param {Array} globals
|
|
874
|
+
* @return {Array}
|
|
875
|
+
*/
|
|
876
|
+
function filterLeaks(ok, globals$1) {
|
|
877
|
+
return globals$1.filter(function(key) {
|
|
878
|
+
if (/^\d+/.test(key)) return false;
|
|
879
|
+
if (global.navigator && /^getInterface/.test(key)) return false;
|
|
880
|
+
if (global.navigator && /^\d+/.test(key)) return false;
|
|
881
|
+
if (/^mocha-/.test(key)) return false;
|
|
882
|
+
return !ok.filter(function(ok$1) {
|
|
883
|
+
if (~ok$1.indexOf("*")) return key.indexOf(ok$1.split("*")[0]) === 0;
|
|
884
|
+
return key === ok$1;
|
|
885
|
+
}).length && (!global.navigator || key !== "onerror");
|
|
886
|
+
});
|
|
887
|
+
}
|
|
888
|
+
/**
|
|
889
|
+
* Check if argument is an instance of Error object or a duck-typed equivalent.
|
|
890
|
+
*
|
|
891
|
+
* @private
|
|
892
|
+
* @param {Object} err - object to check
|
|
893
|
+
* @param {string} err.message - error message
|
|
894
|
+
* @returns {boolean}
|
|
895
|
+
*/
|
|
896
|
+
function isError(err) {
|
|
897
|
+
return err instanceof Error || err && typeof err.message === "string";
|
|
898
|
+
}
|
|
899
|
+
/**
|
|
900
|
+
*
|
|
901
|
+
* Converts thrown non-extensible type into proper Error.
|
|
902
|
+
*
|
|
903
|
+
* @private
|
|
904
|
+
* @param {*} thrown - Non-extensible type thrown by code
|
|
905
|
+
* @return {Error}
|
|
906
|
+
*/
|
|
907
|
+
function thrown2Error(err) {
|
|
908
|
+
return /* @__PURE__ */ new Error(`the ${utils.canonicalType(err)} ${stringify(err)} was thrown, throw an Error :)`);
|
|
909
|
+
}
|
|
910
|
+
Runner.constants = constants;
|
|
911
|
+
/**
|
|
912
|
+
* Node.js' `EventEmitter`
|
|
913
|
+
* @external EventEmitter
|
|
914
|
+
* @see {@link https://nodejs.org/api/events.html#events_class_eventemitter}
|
|
915
|
+
*/
|
|
916
|
+
module.exports = Runner;
|
|
917
|
+
}) });
|
|
918
|
+
|
|
919
|
+
//#endregion
|
|
920
|
+
export default require_runner();
|
|
921
|
+
|
|
922
|
+
export { require_runner };
|