@eggjs/mock 6.1.0-beta.10 → 6.1.0-beta.11
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/README.md +1 -1
- package/README.zh_CN.md +1 -1
- package/dist/_virtual/rolldown_runtime.js +1 -24
- package/dist/inject_mocha.d.ts +1 -1
- package/dist/inject_mocha.js +2 -3
- package/dist/lib/context.js +1 -3
- package/package.json +6 -8
- package/dist/node_modules/.pnpm/ansi-styles@4.3.0/node_modules/ansi-styles/index.js +0 -142
- package/dist/node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/index.js +0 -157
- package/dist/node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/templates.js +0 -97
- package/dist/node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/util.js +0 -40
- package/dist/node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/conversions.js +0 -814
- package/dist/node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/index.js +0 -50
- package/dist/node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/route.js +0 -68
- package/dist/node_modules/.pnpm/color-name@1.1.4/node_modules/color-name/index.js +0 -752
- package/dist/node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/browser.js +0 -203
- package/dist/node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/common.js +0 -209
- package/dist/node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/index.js +0 -18
- package/dist/node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/node.js +0 -215
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/convert/dmp.js +0 -24
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/convert/xml.js +0 -33
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/array.js +0 -29
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/base.js +0 -185
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/character.js +0 -23
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/css.js +0 -26
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/json.js +0 -83
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/line.js +0 -51
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/sentence.js +0 -26
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/word.js +0 -151
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/index.js +0 -178
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/apply.js +0 -168
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/create.js +0 -301
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/line-endings.js +0 -137
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/merge.js +0 -367
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/parse.js +0 -91
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/reverse.js +0 -99
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/util/array.js +0 -23
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/util/distance-iterator.js +0 -30
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/util/params.js +0 -22
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/util/string.js +0 -97
- package/dist/node_modules/.pnpm/escape-string-regexp@4.0.0/node_modules/escape-string-regexp/index.js +0 -14
- package/dist/node_modules/.pnpm/has-flag@4.0.0/node_modules/has-flag/index.js +0 -16
- package/dist/node_modules/.pnpm/he@1.2.0/node_modules/he/he.js +0 -4093
- package/dist/node_modules/.pnpm/is-unicode-supported@0.1.0/node_modules/is-unicode-supported/index.js +0 -14
- package/dist/node_modules/.pnpm/log-symbols@4.1.0/node_modules/log-symbols/index.js +0 -27
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/index.js +0 -12
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/context.js +0 -83
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/error-constants.js +0 -35
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/errors.js +0 -392
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/hook.js +0 -86
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/bdd.js +0 -104
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/common.js +0 -99
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/exports.js +0 -65
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/index.js +0 -18
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/qunit.js +0 -95
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/tdd.js +0 -105
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/mocha.js +0 -1037
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/mocharc.js +0 -24
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/buffered-worker-pool.js +0 -152
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/esm-utils.js +0 -74
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/file-unloader.js +0 -22
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/parallel-buffered-runner.js +0 -329
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/serializer.js +0 -314
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/pending.js +0 -22
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/base.js +0 -417
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/doc.js +0 -79
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/dot.js +0 -75
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/html.js +0 -283
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/index.js +0 -40
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/json-stream.js +0 -90
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/json.js +0 -145
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/landing.js +0 -107
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/list.js +0 -77
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/markdown.js +0 -106
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/min.js +0 -57
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/nyan.js +0 -233
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/progress.js +0 -92
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/spec.js +0 -91
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/tap.js +0 -261
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/xunit.js +0 -166
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/runnable.js +0 -346
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/runner.js +0 -922
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/stats-collector.js +0 -72
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/suite.js +0 -517
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/test.js +0 -105
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/utils.js +0 -505
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/package.js +0 -225
- package/dist/node_modules/.pnpm/ms@2.1.3/node_modules/ms/index.js +0 -124
- package/dist/node_modules/.pnpm/randombytes@2.1.0/node_modules/randombytes/index.js +0 -11
- package/dist/node_modules/.pnpm/serialize-javascript@6.0.2/node_modules/serialize-javascript/index.js +0 -114
- package/dist/node_modules/.pnpm/supports-color@7.2.0/node_modules/supports-color/index.js +0 -76
- package/dist/node_modules/.pnpm/supports-color@8.1.1/node_modules/supports-color/index.js +0 -89
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/Pool.js +0 -366
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/Promise.js +0 -248
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/WorkerHandler.js +0 -419
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/debug-port-allocator.js +0 -27
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/environment.js +0 -18
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/generated/embeddedWorker.js +0 -16
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/index.js +0 -63
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/transfer.js +0 -21
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/validateOptions.js +0 -9
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/worker.js +0 -277
|
@@ -1,1037 +0,0 @@
|
|
|
1
|
-
import { __commonJS, __require } from "../../../../../../_virtual/rolldown_runtime.js";
|
|
2
|
-
import { require_escape_string_regexp } from "../../../../escape-string-regexp@4.0.0/node_modules/escape-string-regexp/index.js";
|
|
3
|
-
import { require_utils } from "./utils.js";
|
|
4
|
-
import { require_src } from "../../../../debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/index.js";
|
|
5
|
-
import { require_errors } from "./errors.js";
|
|
6
|
-
import { require_runnable } from "./runnable.js";
|
|
7
|
-
import { require_hook } from "./hook.js";
|
|
8
|
-
import { require_suite } from "./suite.js";
|
|
9
|
-
import { require_runner } from "./runner.js";
|
|
10
|
-
import { require_reporters } from "./reporters/index.js";
|
|
11
|
-
import { require_mocharc } from "./mocharc.js";
|
|
12
|
-
import { require_esm_utils } from "./nodejs/esm-utils.js";
|
|
13
|
-
import { require_stats_collector } from "./stats-collector.js";
|
|
14
|
-
import { require_test } from "./test.js";
|
|
15
|
-
import { require_interfaces } from "./interfaces/index.js";
|
|
16
|
-
import { require_context } from "./context.js";
|
|
17
|
-
import { require_file_unloader } from "./nodejs/file-unloader.js";
|
|
18
|
-
import { require_package } from "../package.js";
|
|
19
|
-
import { require_parallel_buffered_runner } from "./nodejs/parallel-buffered-runner.js";
|
|
20
|
-
|
|
21
|
-
//#region ../../node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/mocha.js
|
|
22
|
-
var require_mocha = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/mocha.js": ((exports, module) => {
|
|
23
|
-
/*!
|
|
24
|
-
* mocha
|
|
25
|
-
* Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>
|
|
26
|
-
* MIT Licensed
|
|
27
|
-
*/
|
|
28
|
-
var escapeRe = require_escape_string_regexp();
|
|
29
|
-
var path = __require("node:path");
|
|
30
|
-
var builtinReporters = require_reporters();
|
|
31
|
-
var utils = require_utils();
|
|
32
|
-
var mocharc = require_mocharc();
|
|
33
|
-
var Suite = require_suite();
|
|
34
|
-
var esmUtils = require_esm_utils();
|
|
35
|
-
var createStatsCollector = require_stats_collector();
|
|
36
|
-
const { createInvalidReporterError, createInvalidInterfaceError, createMochaInstanceAlreadyDisposedError, createMochaInstanceAlreadyRunningError, createUnsupportedError } = require_errors();
|
|
37
|
-
const { EVENT_FILE_PRE_REQUIRE, EVENT_FILE_POST_REQUIRE, EVENT_FILE_REQUIRE } = Suite.constants;
|
|
38
|
-
var debug = require_src()("mocha:mocha");
|
|
39
|
-
/**
|
|
40
|
-
* @typedef {import('./types.d.ts').DoneCB} DoneCB
|
|
41
|
-
* @typedef {import('./types.d.ts').MochaGlobalFixture} MochaGlobalFixture
|
|
42
|
-
* @typedef {import('./types.d.ts').MochaOptions} MochaOptions
|
|
43
|
-
* @typedef {import('./types.d.ts').MochaRootHookObject} MochaRootHookObject
|
|
44
|
-
* @typedef {import('./types.d.ts').Reporter} Reporter
|
|
45
|
-
*/
|
|
46
|
-
exports = module.exports = Mocha;
|
|
47
|
-
/**
|
|
48
|
-
* A Mocha instance is a finite state machine.
|
|
49
|
-
* These are the states it can be in.
|
|
50
|
-
* @private
|
|
51
|
-
*/
|
|
52
|
-
var mochaStates = utils.defineConstants({
|
|
53
|
-
INIT: "init",
|
|
54
|
-
RUNNING: "running",
|
|
55
|
-
REFERENCES_CLEANED: "referencesCleaned",
|
|
56
|
-
DISPOSED: "disposed"
|
|
57
|
-
});
|
|
58
|
-
/**
|
|
59
|
-
* To require local UIs and reporters when running in node.
|
|
60
|
-
*/
|
|
61
|
-
if (!utils.isBrowser() && typeof module.paths !== "undefined") {
|
|
62
|
-
var cwd = utils.cwd();
|
|
63
|
-
module.paths.push(cwd, path.join(cwd, "node_modules"));
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Expose internals.
|
|
67
|
-
* @private
|
|
68
|
-
*/
|
|
69
|
-
exports.utils = utils;
|
|
70
|
-
exports.interfaces = require_interfaces();
|
|
71
|
-
/**
|
|
72
|
-
* @public
|
|
73
|
-
* @memberof Mocha
|
|
74
|
-
*/
|
|
75
|
-
exports.reporters = builtinReporters;
|
|
76
|
-
exports.Runnable = require_runnable();
|
|
77
|
-
exports.Context = require_context();
|
|
78
|
-
/**
|
|
79
|
-
*
|
|
80
|
-
* @memberof Mocha
|
|
81
|
-
*/
|
|
82
|
-
exports.Runner = require_runner();
|
|
83
|
-
exports.Suite = Suite;
|
|
84
|
-
exports.Hook = require_hook();
|
|
85
|
-
exports.Test = require_test();
|
|
86
|
-
let currentContext;
|
|
87
|
-
exports.afterEach = function(...args) {
|
|
88
|
-
return (currentContext.afterEach || currentContext.teardown).apply(this, args);
|
|
89
|
-
};
|
|
90
|
-
exports.after = function(...args) {
|
|
91
|
-
return (currentContext.after || currentContext.suiteTeardown).apply(this, args);
|
|
92
|
-
};
|
|
93
|
-
exports.beforeEach = function(...args) {
|
|
94
|
-
return (currentContext.beforeEach || currentContext.setup).apply(this, args);
|
|
95
|
-
};
|
|
96
|
-
exports.before = function(...args) {
|
|
97
|
-
return (currentContext.before || currentContext.suiteSetup).apply(this, args);
|
|
98
|
-
};
|
|
99
|
-
exports.describe = function(...args) {
|
|
100
|
-
return (currentContext.describe || currentContext.suite).apply(this, args);
|
|
101
|
-
};
|
|
102
|
-
exports.describe.only = function(...args) {
|
|
103
|
-
return (currentContext.describe || currentContext.suite).only.apply(this, args);
|
|
104
|
-
};
|
|
105
|
-
exports.describe.skip = function(...args) {
|
|
106
|
-
return (currentContext.describe || currentContext.suite).skip.apply(this, args);
|
|
107
|
-
};
|
|
108
|
-
exports.it = function(...args) {
|
|
109
|
-
return (currentContext.it || currentContext.test).apply(this, args);
|
|
110
|
-
};
|
|
111
|
-
exports.it.only = function(...args) {
|
|
112
|
-
return (currentContext.it || currentContext.test).only.apply(this, args);
|
|
113
|
-
};
|
|
114
|
-
exports.it.skip = function(...args) {
|
|
115
|
-
return (currentContext.it || currentContext.test).skip.apply(this, args);
|
|
116
|
-
};
|
|
117
|
-
exports.xdescribe = exports.describe.skip;
|
|
118
|
-
exports.xit = exports.it.skip;
|
|
119
|
-
exports.setup = exports.beforeEach;
|
|
120
|
-
exports.suiteSetup = exports.before;
|
|
121
|
-
exports.suiteTeardown = exports.after;
|
|
122
|
-
exports.suite = exports.describe;
|
|
123
|
-
exports.teardown = exports.afterEach;
|
|
124
|
-
exports.test = exports.it;
|
|
125
|
-
exports.run = function(...args) {
|
|
126
|
-
return currentContext.run.apply(this, args);
|
|
127
|
-
};
|
|
128
|
-
/**
|
|
129
|
-
* Constructs a new Mocha instance with `options`.
|
|
130
|
-
*
|
|
131
|
-
* @public
|
|
132
|
-
* @class Mocha
|
|
133
|
-
* @param {MochaOptions} [options] - Settings object.
|
|
134
|
-
*/
|
|
135
|
-
function Mocha(options = {}) {
|
|
136
|
-
options = {
|
|
137
|
-
...mocharc,
|
|
138
|
-
...options
|
|
139
|
-
};
|
|
140
|
-
this.files = [];
|
|
141
|
-
this.options = options;
|
|
142
|
-
this.suite = new exports.Suite("", new exports.Context(), true);
|
|
143
|
-
this._cleanReferencesAfterRun = true;
|
|
144
|
-
this._state = mochaStates.INIT;
|
|
145
|
-
this.grep(options.grep).fgrep(options.fgrep).ui(options.ui).reporter(options.reporter, options["reporter-option"] || options.reporterOption || options.reporterOptions).slow(options.slow).global(options.global);
|
|
146
|
-
if (typeof options.timeout !== "undefined") this.timeout(options.timeout === false ? 0 : options.timeout);
|
|
147
|
-
if ("retries" in options) this.retries(options.retries);
|
|
148
|
-
[
|
|
149
|
-
"allowUncaught",
|
|
150
|
-
"asyncOnly",
|
|
151
|
-
"bail",
|
|
152
|
-
"checkLeaks",
|
|
153
|
-
"color",
|
|
154
|
-
"delay",
|
|
155
|
-
"diff",
|
|
156
|
-
"dryRun",
|
|
157
|
-
"passOnFailingTestSuite",
|
|
158
|
-
"failZero",
|
|
159
|
-
"forbidOnly",
|
|
160
|
-
"forbidPending",
|
|
161
|
-
"fullTrace",
|
|
162
|
-
"inlineDiffs",
|
|
163
|
-
"invert"
|
|
164
|
-
].forEach(function(opt) {
|
|
165
|
-
if (options[opt]) this[opt]();
|
|
166
|
-
}, this);
|
|
167
|
-
if (options.rootHooks) this.rootHooks(options.rootHooks);
|
|
168
|
-
/**
|
|
169
|
-
* The class which we'll instantiate in {@link Mocha#run}. Defaults to
|
|
170
|
-
* {@link Runner} in serial mode; changes in parallel mode.
|
|
171
|
-
* @memberof Mocha
|
|
172
|
-
* @private
|
|
173
|
-
*/
|
|
174
|
-
this._runnerClass = exports.Runner;
|
|
175
|
-
/**
|
|
176
|
-
* Whether or not to call {@link Mocha#loadFiles} implicitly when calling
|
|
177
|
-
* {@link Mocha#run}. If this is `true`, then it's up to the consumer to call
|
|
178
|
-
* {@link Mocha#loadFiles} _or_ {@link Mocha#loadFilesAsync}.
|
|
179
|
-
* @private
|
|
180
|
-
* @memberof Mocha
|
|
181
|
-
*/
|
|
182
|
-
this._lazyLoadFiles = false;
|
|
183
|
-
/**
|
|
184
|
-
* It's useful for a Mocha instance to know if it's running in a worker process.
|
|
185
|
-
* We could derive this via other means, but it's helpful to have a flag to refer to.
|
|
186
|
-
* @memberof Mocha
|
|
187
|
-
* @private
|
|
188
|
-
*/
|
|
189
|
-
this.isWorker = Boolean(options.isWorker);
|
|
190
|
-
this.globalSetup(options.globalSetup).globalTeardown(options.globalTeardown).enableGlobalSetup(options.enableGlobalSetup).enableGlobalTeardown(options.enableGlobalTeardown);
|
|
191
|
-
if (options.parallel && (typeof options.jobs === "undefined" || options.jobs > 1)) {
|
|
192
|
-
debug("attempting to enable parallel mode");
|
|
193
|
-
this.parallelMode(true);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Enables or disables bailing on the first failure.
|
|
198
|
-
*
|
|
199
|
-
* @public
|
|
200
|
-
* @see [CLI option](../#-bail-b)
|
|
201
|
-
* @param {boolean} [bail=true] - Whether to bail on first error.
|
|
202
|
-
* @returns {Mocha} this
|
|
203
|
-
* @chainable
|
|
204
|
-
*/
|
|
205
|
-
Mocha.prototype.bail = function(bail) {
|
|
206
|
-
this.suite.bail(bail !== false);
|
|
207
|
-
return this;
|
|
208
|
-
};
|
|
209
|
-
/**
|
|
210
|
-
* @summary
|
|
211
|
-
* Adds `file` to be loaded for execution.
|
|
212
|
-
*
|
|
213
|
-
* @description
|
|
214
|
-
* Useful for generic setup code that must be included within test suite.
|
|
215
|
-
*
|
|
216
|
-
* @public
|
|
217
|
-
* @see [CLI option](../#-file-filedirectoryglob)
|
|
218
|
-
* @param {string} file - Pathname of file to be loaded.
|
|
219
|
-
* @returns {Mocha} this
|
|
220
|
-
* @chainable
|
|
221
|
-
*/
|
|
222
|
-
Mocha.prototype.addFile = function(file) {
|
|
223
|
-
this.files.push(file);
|
|
224
|
-
return this;
|
|
225
|
-
};
|
|
226
|
-
/**
|
|
227
|
-
* Sets reporter to `reporter`, defaults to "spec".
|
|
228
|
-
*
|
|
229
|
-
* @public
|
|
230
|
-
* @see [CLI option](../#-reporter-name-r-name)
|
|
231
|
-
* @see [Reporters](../#reporters)
|
|
232
|
-
* @param {String|Reporter} reporterName - Reporter name or constructor.
|
|
233
|
-
* @param {Object} [reporterOptions] - Options used to configure the reporter.
|
|
234
|
-
* @returns {Mocha} this
|
|
235
|
-
* @chainable
|
|
236
|
-
* @throws {Error} if requested reporter cannot be loaded
|
|
237
|
-
* @example
|
|
238
|
-
*
|
|
239
|
-
* // Use XUnit reporter and direct its output to file
|
|
240
|
-
* mocha.reporter('xunit', { output: '/path/to/testspec.xunit.xml' });
|
|
241
|
-
*/
|
|
242
|
-
Mocha.prototype.reporter = function(reporterName, reporterOptions) {
|
|
243
|
-
if (typeof reporterName === "function") this._reporter = reporterName;
|
|
244
|
-
else {
|
|
245
|
-
reporterName = reporterName || "spec";
|
|
246
|
-
var reporter;
|
|
247
|
-
if (builtinReporters[reporterName]) reporter = builtinReporters[reporterName];
|
|
248
|
-
if (!reporter) {
|
|
249
|
-
let foundReporter;
|
|
250
|
-
try {
|
|
251
|
-
foundReporter = __require.resolve(reporterName);
|
|
252
|
-
reporter = __require(foundReporter);
|
|
253
|
-
} catch (err) {
|
|
254
|
-
if (foundReporter) throw createInvalidReporterError(err.message, foundReporter);
|
|
255
|
-
try {
|
|
256
|
-
reporter = __require(path.resolve(reporterName));
|
|
257
|
-
} catch (err$1) {
|
|
258
|
-
throw createInvalidReporterError(err$1.message, reporterName);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
this._reporter = reporter;
|
|
263
|
-
}
|
|
264
|
-
this.options.reporterOption = reporterOptions;
|
|
265
|
-
this.options.reporterOptions = reporterOptions;
|
|
266
|
-
return this;
|
|
267
|
-
};
|
|
268
|
-
/**
|
|
269
|
-
* Sets test UI `name`, defaults to "bdd".
|
|
270
|
-
*
|
|
271
|
-
* @public
|
|
272
|
-
* @see [CLI option](../#-ui-name-u-name)
|
|
273
|
-
* @see [Interface DSLs](../#interfaces)
|
|
274
|
-
* @param {string|Function} [ui=bdd] - Interface name or class.
|
|
275
|
-
* @returns {Mocha} this
|
|
276
|
-
* @chainable
|
|
277
|
-
* @throws {Error} if requested interface cannot be loaded
|
|
278
|
-
*/
|
|
279
|
-
Mocha.prototype.ui = function(ui) {
|
|
280
|
-
var bindInterface;
|
|
281
|
-
if (typeof ui === "function") bindInterface = ui;
|
|
282
|
-
else {
|
|
283
|
-
ui = ui || "bdd";
|
|
284
|
-
bindInterface = exports.interfaces[ui];
|
|
285
|
-
if (!bindInterface) try {
|
|
286
|
-
bindInterface = __require(ui);
|
|
287
|
-
} catch (err) {
|
|
288
|
-
throw createInvalidInterfaceError(`invalid interface '${ui}'`, ui);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
bindInterface(this.suite);
|
|
292
|
-
this.suite.on(EVENT_FILE_PRE_REQUIRE, function(context) {
|
|
293
|
-
currentContext = context;
|
|
294
|
-
});
|
|
295
|
-
return this;
|
|
296
|
-
};
|
|
297
|
-
/**
|
|
298
|
-
* Loads `files` prior to execution. Does not support ES Modules.
|
|
299
|
-
*
|
|
300
|
-
* @description
|
|
301
|
-
* The implementation relies on Node's `require` to execute
|
|
302
|
-
* the test interface functions and will be subject to its cache.
|
|
303
|
-
* Supports only CommonJS modules. To load ES modules, use Mocha#loadFilesAsync.
|
|
304
|
-
*
|
|
305
|
-
* @private
|
|
306
|
-
* @see {@link Mocha#addFile}
|
|
307
|
-
* @see {@link Mocha#run}
|
|
308
|
-
* @see {@link Mocha#unloadFiles}
|
|
309
|
-
* @see {@link Mocha#loadFilesAsync}
|
|
310
|
-
* @param {Function} [fn] - Callback invoked upon completion.
|
|
311
|
-
*/
|
|
312
|
-
Mocha.prototype.loadFiles = function(fn) {
|
|
313
|
-
var self = this;
|
|
314
|
-
var suite = this.suite;
|
|
315
|
-
this.files.forEach(function(file) {
|
|
316
|
-
file = path.resolve(file);
|
|
317
|
-
suite.emit(EVENT_FILE_PRE_REQUIRE, global, file, self);
|
|
318
|
-
suite.emit(EVENT_FILE_REQUIRE, __require(file), file, self);
|
|
319
|
-
suite.emit(EVENT_FILE_POST_REQUIRE, global, file, self);
|
|
320
|
-
});
|
|
321
|
-
fn && fn();
|
|
322
|
-
};
|
|
323
|
-
/**
|
|
324
|
-
* Loads `files` prior to execution. Supports Node ES Modules.
|
|
325
|
-
*
|
|
326
|
-
* @description
|
|
327
|
-
* The implementation relies on Node's `require` and `import` to execute
|
|
328
|
-
* the test interface functions and will be subject to its cache.
|
|
329
|
-
* Supports both CJS and ESM modules.
|
|
330
|
-
*
|
|
331
|
-
* @public
|
|
332
|
-
* @see {@link Mocha#addFile}
|
|
333
|
-
* @see {@link Mocha#run}
|
|
334
|
-
* @see {@link Mocha#unloadFiles}
|
|
335
|
-
* @param {Object} [options] - Settings object.
|
|
336
|
-
* @param {Function} [options.esmDecorator] - Function invoked on esm module name right before importing it. By default will passthrough as is.
|
|
337
|
-
* @returns {Promise}
|
|
338
|
-
* @example
|
|
339
|
-
*
|
|
340
|
-
* // loads ESM (and CJS) test files asynchronously, then runs root suite
|
|
341
|
-
* mocha.loadFilesAsync()
|
|
342
|
-
* .then(() => mocha.run(failures => process.exitCode = failures ? 1 : 0))
|
|
343
|
-
* .catch(() => process.exitCode = 1);
|
|
344
|
-
*/
|
|
345
|
-
Mocha.prototype.loadFilesAsync = function({ esmDecorator } = {}) {
|
|
346
|
-
var self = this;
|
|
347
|
-
var suite = this.suite;
|
|
348
|
-
this.lazyLoadFiles(true);
|
|
349
|
-
return esmUtils.loadFilesAsync(this.files, function(file) {
|
|
350
|
-
suite.emit(EVENT_FILE_PRE_REQUIRE, global, file, self);
|
|
351
|
-
}, function(file, resultModule) {
|
|
352
|
-
suite.emit(EVENT_FILE_REQUIRE, resultModule, file, self);
|
|
353
|
-
suite.emit(EVENT_FILE_POST_REQUIRE, global, file, self);
|
|
354
|
-
}, esmDecorator);
|
|
355
|
-
};
|
|
356
|
-
/**
|
|
357
|
-
* Removes a previously loaded file from Node's `require` cache.
|
|
358
|
-
*
|
|
359
|
-
* @private
|
|
360
|
-
* @static
|
|
361
|
-
* @see {@link Mocha#unloadFiles}
|
|
362
|
-
* @param {string} file - Pathname of file to be unloaded.
|
|
363
|
-
*/
|
|
364
|
-
Mocha.unloadFile = function(file) {
|
|
365
|
-
if (utils.isBrowser()) throw createUnsupportedError("unloadFile() is only supported in a Node.js environment");
|
|
366
|
-
return require_file_unloader().unloadFile(file);
|
|
367
|
-
};
|
|
368
|
-
/**
|
|
369
|
-
* Unloads `files` from Node's `require` cache.
|
|
370
|
-
*
|
|
371
|
-
* @description
|
|
372
|
-
* This allows required files to be "freshly" reloaded, providing the ability
|
|
373
|
-
* to reuse a Mocha instance programmatically.
|
|
374
|
-
* Note: does not clear ESM module files from the cache
|
|
375
|
-
*
|
|
376
|
-
* <strong>Intended for consumers — not used internally</strong>
|
|
377
|
-
*
|
|
378
|
-
* @public
|
|
379
|
-
* @see {@link Mocha#run}
|
|
380
|
-
* @returns {Mocha} this
|
|
381
|
-
* @chainable
|
|
382
|
-
*/
|
|
383
|
-
Mocha.prototype.unloadFiles = function() {
|
|
384
|
-
if (this._state === mochaStates.DISPOSED) throw createMochaInstanceAlreadyDisposedError("Mocha instance is already disposed, it cannot be used again.", this._cleanReferencesAfterRun, this);
|
|
385
|
-
this.files.forEach(function(file) {
|
|
386
|
-
Mocha.unloadFile(file);
|
|
387
|
-
});
|
|
388
|
-
this._state = mochaStates.INIT;
|
|
389
|
-
return this;
|
|
390
|
-
};
|
|
391
|
-
/**
|
|
392
|
-
* Sets `grep` filter after escaping RegExp special characters.
|
|
393
|
-
*
|
|
394
|
-
* @public
|
|
395
|
-
* @see {@link Mocha#grep}
|
|
396
|
-
* @param {string} str - Value to be converted to a regexp.
|
|
397
|
-
* @returns {Mocha} this
|
|
398
|
-
* @chainable
|
|
399
|
-
* @example
|
|
400
|
-
*
|
|
401
|
-
* // Select tests whose full title begins with `"foo"` followed by a period
|
|
402
|
-
* mocha.fgrep('foo.');
|
|
403
|
-
*/
|
|
404
|
-
Mocha.prototype.fgrep = function(str) {
|
|
405
|
-
if (!str) return this;
|
|
406
|
-
return this.grep(new RegExp(escapeRe(str)));
|
|
407
|
-
};
|
|
408
|
-
/**
|
|
409
|
-
* @summary
|
|
410
|
-
* Sets `grep` filter used to select specific tests for execution.
|
|
411
|
-
*
|
|
412
|
-
* @description
|
|
413
|
-
* If `re` is a regexp-like string, it will be converted to regexp.
|
|
414
|
-
* The regexp is tested against the full title of each test (i.e., the
|
|
415
|
-
* name of the test preceded by titles of each its ancestral suites).
|
|
416
|
-
* As such, using an <em>exact-match</em> fixed pattern against the
|
|
417
|
-
* test name itself will not yield any matches.
|
|
418
|
-
* <br>
|
|
419
|
-
* <strong>Previous filter value will be overwritten on each call!</strong>
|
|
420
|
-
*
|
|
421
|
-
* @public
|
|
422
|
-
* @see [CLI option](../#-grep-regexp-g-regexp)
|
|
423
|
-
* @see {@link Mocha#fgrep}
|
|
424
|
-
* @see {@link Mocha#invert}
|
|
425
|
-
* @param {RegExp|String} re - Regular expression used to select tests.
|
|
426
|
-
* @return {Mocha} this
|
|
427
|
-
* @chainable
|
|
428
|
-
* @example
|
|
429
|
-
*
|
|
430
|
-
* // Select tests whose full title contains `"match"`, ignoring case
|
|
431
|
-
* mocha.grep(/match/i);
|
|
432
|
-
* @example
|
|
433
|
-
*
|
|
434
|
-
* // Same as above but with regexp-like string argument
|
|
435
|
-
* mocha.grep('/match/i');
|
|
436
|
-
* @example
|
|
437
|
-
*
|
|
438
|
-
* // ## Anti-example
|
|
439
|
-
* // Given embedded test `it('only-this-test')`...
|
|
440
|
-
* mocha.grep('/^only-this-test$/'); // NO! Use `.only()` to do this!
|
|
441
|
-
*/
|
|
442
|
-
Mocha.prototype.grep = function(re) {
|
|
443
|
-
if (utils.isString(re)) {
|
|
444
|
-
var arg = re.match(/^\/(.*)\/([gimy]{0,4})$|.*/);
|
|
445
|
-
this.options.grep = new RegExp(arg[1] || arg[0], arg[2]);
|
|
446
|
-
} else this.options.grep = re;
|
|
447
|
-
return this;
|
|
448
|
-
};
|
|
449
|
-
/**
|
|
450
|
-
* Inverts `grep` matches.
|
|
451
|
-
*
|
|
452
|
-
* @public
|
|
453
|
-
* @see {@link Mocha#grep}
|
|
454
|
-
* @return {Mocha} this
|
|
455
|
-
* @chainable
|
|
456
|
-
* @example
|
|
457
|
-
*
|
|
458
|
-
* // Select tests whose full title does *not* contain `"match"`, ignoring case
|
|
459
|
-
* mocha.grep(/match/i).invert();
|
|
460
|
-
*/
|
|
461
|
-
Mocha.prototype.invert = function() {
|
|
462
|
-
this.options.invert = true;
|
|
463
|
-
return this;
|
|
464
|
-
};
|
|
465
|
-
/**
|
|
466
|
-
* Enables or disables checking for global variables leaked while running tests.
|
|
467
|
-
*
|
|
468
|
-
* @public
|
|
469
|
-
* @see [CLI option](../#-check-leaks)
|
|
470
|
-
* @param {boolean} [checkLeaks=true] - Whether to check for global variable leaks.
|
|
471
|
-
* @return {Mocha} this
|
|
472
|
-
* @chainable
|
|
473
|
-
*/
|
|
474
|
-
Mocha.prototype.checkLeaks = function(checkLeaks) {
|
|
475
|
-
this.options.checkLeaks = checkLeaks !== false;
|
|
476
|
-
return this;
|
|
477
|
-
};
|
|
478
|
-
/**
|
|
479
|
-
* Enables or disables whether or not to dispose after each test run.
|
|
480
|
-
* Disable this to ensure you can run the test suite multiple times.
|
|
481
|
-
* If disabled, be sure to dispose mocha when you're done to prevent memory leaks.
|
|
482
|
-
* @public
|
|
483
|
-
* @see {@link Mocha#dispose}
|
|
484
|
-
* @param {boolean} cleanReferencesAfterRun
|
|
485
|
-
* @return {Mocha} this
|
|
486
|
-
* @chainable
|
|
487
|
-
*/
|
|
488
|
-
Mocha.prototype.cleanReferencesAfterRun = function(cleanReferencesAfterRun) {
|
|
489
|
-
this._cleanReferencesAfterRun = cleanReferencesAfterRun !== false;
|
|
490
|
-
return this;
|
|
491
|
-
};
|
|
492
|
-
/**
|
|
493
|
-
* Manually dispose this mocha instance. Mark this instance as `disposed` and unable to run more tests.
|
|
494
|
-
* It also removes function references to tests functions and hooks, so variables trapped in closures can be cleaned by the garbage collector.
|
|
495
|
-
* @public
|
|
496
|
-
*/
|
|
497
|
-
Mocha.prototype.dispose = function() {
|
|
498
|
-
if (this._state === mochaStates.RUNNING) throw createMochaInstanceAlreadyRunningError("Cannot dispose while the mocha instance is still running tests.");
|
|
499
|
-
this.unloadFiles();
|
|
500
|
-
this._previousRunner && this._previousRunner.dispose();
|
|
501
|
-
this.suite.dispose();
|
|
502
|
-
this._state = mochaStates.DISPOSED;
|
|
503
|
-
};
|
|
504
|
-
/**
|
|
505
|
-
* Displays full stack trace upon test failure.
|
|
506
|
-
*
|
|
507
|
-
* @public
|
|
508
|
-
* @see [CLI option](../#-full-trace)
|
|
509
|
-
* @param {boolean} [fullTrace=true] - Whether to print full stacktrace upon failure.
|
|
510
|
-
* @return {Mocha} this
|
|
511
|
-
* @chainable
|
|
512
|
-
*/
|
|
513
|
-
Mocha.prototype.fullTrace = function(fullTrace) {
|
|
514
|
-
this.options.fullTrace = fullTrace !== false;
|
|
515
|
-
return this;
|
|
516
|
-
};
|
|
517
|
-
/**
|
|
518
|
-
* Specifies whitelist of variable names to be expected in global scope.
|
|
519
|
-
*
|
|
520
|
-
* @public
|
|
521
|
-
* @see [CLI option](../#-global-variable-name)
|
|
522
|
-
* @see {@link Mocha#checkLeaks}
|
|
523
|
-
* @param {String[]|String} global - Accepted global variable name(s).
|
|
524
|
-
* @return {Mocha} this
|
|
525
|
-
* @chainable
|
|
526
|
-
* @example
|
|
527
|
-
*
|
|
528
|
-
* // Specify variables to be expected in global scope
|
|
529
|
-
* mocha.global(['jQuery', 'MyLib']);
|
|
530
|
-
*/
|
|
531
|
-
Mocha.prototype.global = function(global$1) {
|
|
532
|
-
this.options.global = (this.options.global || []).concat(global$1).filter(Boolean).filter(function(elt, idx, arr) {
|
|
533
|
-
return arr.indexOf(elt) === idx;
|
|
534
|
-
});
|
|
535
|
-
return this;
|
|
536
|
-
};
|
|
537
|
-
Mocha.prototype.globals = Mocha.prototype.global;
|
|
538
|
-
/**
|
|
539
|
-
* Enables or disables TTY color output by screen-oriented reporters.
|
|
540
|
-
*
|
|
541
|
-
* @public
|
|
542
|
-
* @see [CLI option](../#-color-c-colors)
|
|
543
|
-
* @param {boolean} [color=true] - Whether to enable color output.
|
|
544
|
-
* @return {Mocha} this
|
|
545
|
-
* @chainable
|
|
546
|
-
*/
|
|
547
|
-
Mocha.prototype.color = function(color) {
|
|
548
|
-
this.options.color = color !== false;
|
|
549
|
-
return this;
|
|
550
|
-
};
|
|
551
|
-
/**
|
|
552
|
-
* Enables or disables reporter to use inline diffs (rather than +/-)
|
|
553
|
-
* in test failure output.
|
|
554
|
-
*
|
|
555
|
-
* @public
|
|
556
|
-
* @see [CLI option](../#-inline-diffs)
|
|
557
|
-
* @param {boolean} [inlineDiffs=true] - Whether to use inline diffs.
|
|
558
|
-
* @return {Mocha} this
|
|
559
|
-
* @chainable
|
|
560
|
-
*/
|
|
561
|
-
Mocha.prototype.inlineDiffs = function(inlineDiffs) {
|
|
562
|
-
this.options.inlineDiffs = inlineDiffs !== false;
|
|
563
|
-
return this;
|
|
564
|
-
};
|
|
565
|
-
/**
|
|
566
|
-
* Enables or disables reporter to include diff in test failure output.
|
|
567
|
-
*
|
|
568
|
-
* @public
|
|
569
|
-
* @see [CLI option](../#-diff)
|
|
570
|
-
* @param {boolean} [diff=true] - Whether to show diff on failure.
|
|
571
|
-
* @return {Mocha} this
|
|
572
|
-
* @chainable
|
|
573
|
-
*/
|
|
574
|
-
Mocha.prototype.diff = function(diff) {
|
|
575
|
-
this.options.diff = diff !== false;
|
|
576
|
-
return this;
|
|
577
|
-
};
|
|
578
|
-
/**
|
|
579
|
-
* @summary
|
|
580
|
-
* Sets timeout threshold value.
|
|
581
|
-
*
|
|
582
|
-
* @description
|
|
583
|
-
* A string argument can use shorthand (such as "2s") and will be converted.
|
|
584
|
-
* If the value is `0`, timeouts will be disabled.
|
|
585
|
-
*
|
|
586
|
-
* @public
|
|
587
|
-
* @see [CLI option](../#-timeout-ms-t-ms)
|
|
588
|
-
* @see [Timeouts](../#timeouts)
|
|
589
|
-
* @param {number|string} msecs - Timeout threshold value.
|
|
590
|
-
* @return {Mocha} this
|
|
591
|
-
* @chainable
|
|
592
|
-
* @example
|
|
593
|
-
*
|
|
594
|
-
* // Sets timeout to one second
|
|
595
|
-
* mocha.timeout(1000);
|
|
596
|
-
* @example
|
|
597
|
-
*
|
|
598
|
-
* // Same as above but using string argument
|
|
599
|
-
* mocha.timeout('1s');
|
|
600
|
-
*/
|
|
601
|
-
Mocha.prototype.timeout = function(msecs) {
|
|
602
|
-
this.suite.timeout(msecs);
|
|
603
|
-
return this;
|
|
604
|
-
};
|
|
605
|
-
/**
|
|
606
|
-
* Sets the number of times to retry failed tests.
|
|
607
|
-
*
|
|
608
|
-
* @public
|
|
609
|
-
* @see [CLI option](../#-retries-n)
|
|
610
|
-
* @see [Retry Tests](../#retry-tests)
|
|
611
|
-
* @param {number} retry - Number of times to retry failed tests.
|
|
612
|
-
* @return {Mocha} this
|
|
613
|
-
* @chainable
|
|
614
|
-
* @example
|
|
615
|
-
*
|
|
616
|
-
* // Allow any failed test to retry one more time
|
|
617
|
-
* mocha.retries(1);
|
|
618
|
-
*/
|
|
619
|
-
Mocha.prototype.retries = function(retry) {
|
|
620
|
-
this.suite.retries(retry);
|
|
621
|
-
return this;
|
|
622
|
-
};
|
|
623
|
-
/**
|
|
624
|
-
* Sets slowness threshold value.
|
|
625
|
-
*
|
|
626
|
-
* @public
|
|
627
|
-
* @see [CLI option](../#-slow-ms-s-ms)
|
|
628
|
-
* @param {number} msecs - Slowness threshold value.
|
|
629
|
-
* @return {Mocha} this
|
|
630
|
-
* @chainable
|
|
631
|
-
* @example
|
|
632
|
-
*
|
|
633
|
-
* // Sets "slow" threshold to half a second
|
|
634
|
-
* mocha.slow(500);
|
|
635
|
-
* @example
|
|
636
|
-
*
|
|
637
|
-
* // Same as above but using string argument
|
|
638
|
-
* mocha.slow('0.5s');
|
|
639
|
-
*/
|
|
640
|
-
Mocha.prototype.slow = function(msecs) {
|
|
641
|
-
this.suite.slow(msecs);
|
|
642
|
-
return this;
|
|
643
|
-
};
|
|
644
|
-
/**
|
|
645
|
-
* Forces all tests to either accept a `done` callback or return a promise.
|
|
646
|
-
*
|
|
647
|
-
* @public
|
|
648
|
-
* @see [CLI option](../#-async-only-a)
|
|
649
|
-
* @param {boolean} [asyncOnly=true] - Whether to force `done` callback or promise.
|
|
650
|
-
* @return {Mocha} this
|
|
651
|
-
* @chainable
|
|
652
|
-
*/
|
|
653
|
-
Mocha.prototype.asyncOnly = function(asyncOnly) {
|
|
654
|
-
this.options.asyncOnly = asyncOnly !== false;
|
|
655
|
-
return this;
|
|
656
|
-
};
|
|
657
|
-
/**
|
|
658
|
-
* Disables syntax highlighting (in browser).
|
|
659
|
-
*
|
|
660
|
-
* @public
|
|
661
|
-
* @return {Mocha} this
|
|
662
|
-
* @chainable
|
|
663
|
-
*/
|
|
664
|
-
Mocha.prototype.noHighlighting = function() {
|
|
665
|
-
this.options.noHighlighting = true;
|
|
666
|
-
return this;
|
|
667
|
-
};
|
|
668
|
-
/**
|
|
669
|
-
* Enables or disables uncaught errors to propagate.
|
|
670
|
-
*
|
|
671
|
-
* @public
|
|
672
|
-
* @see [CLI option](../#-allow-uncaught)
|
|
673
|
-
* @param {boolean} [allowUncaught=true] - Whether to propagate uncaught errors.
|
|
674
|
-
* @return {Mocha} this
|
|
675
|
-
* @chainable
|
|
676
|
-
*/
|
|
677
|
-
Mocha.prototype.allowUncaught = function(allowUncaught) {
|
|
678
|
-
this.options.allowUncaught = allowUncaught !== false;
|
|
679
|
-
return this;
|
|
680
|
-
};
|
|
681
|
-
/**
|
|
682
|
-
* @summary
|
|
683
|
-
* Delays root suite execution.
|
|
684
|
-
*
|
|
685
|
-
* @description
|
|
686
|
-
* Used to perform async operations before any suites are run.
|
|
687
|
-
*
|
|
688
|
-
* @public
|
|
689
|
-
* @see [delayed root suite](../#delayed-root-suite)
|
|
690
|
-
* @returns {Mocha} this
|
|
691
|
-
* @chainable
|
|
692
|
-
*/
|
|
693
|
-
Mocha.prototype.delay = function delay() {
|
|
694
|
-
this.options.delay = true;
|
|
695
|
-
return this;
|
|
696
|
-
};
|
|
697
|
-
/**
|
|
698
|
-
* Enables or disables running tests in dry-run mode.
|
|
699
|
-
*
|
|
700
|
-
* @public
|
|
701
|
-
* @see [CLI option](../#-dry-run)
|
|
702
|
-
* @param {boolean} [dryRun=true] - Whether to activate dry-run mode.
|
|
703
|
-
* @return {Mocha} this
|
|
704
|
-
* @chainable
|
|
705
|
-
*/
|
|
706
|
-
Mocha.prototype.dryRun = function(dryRun) {
|
|
707
|
-
this.options.dryRun = dryRun !== false;
|
|
708
|
-
return this;
|
|
709
|
-
};
|
|
710
|
-
/**
|
|
711
|
-
* Fails test run if no tests encountered with exit-code 1.
|
|
712
|
-
*
|
|
713
|
-
* @public
|
|
714
|
-
* @see [CLI option](../#-fail-zero)
|
|
715
|
-
* @param {boolean} [failZero=true] - Whether to fail test run.
|
|
716
|
-
* @return {Mocha} this
|
|
717
|
-
* @chainable
|
|
718
|
-
*/
|
|
719
|
-
Mocha.prototype.failZero = function(failZero) {
|
|
720
|
-
this.options.failZero = failZero !== false;
|
|
721
|
-
return this;
|
|
722
|
-
};
|
|
723
|
-
/**
|
|
724
|
-
* Fail test run if tests were failed.
|
|
725
|
-
*
|
|
726
|
-
* @public
|
|
727
|
-
* @see [CLI option](../#-pass-on-failing-test-suite)
|
|
728
|
-
* @param {boolean} [passOnFailingTestSuite=false] - Whether to fail test run.
|
|
729
|
-
* @return {Mocha} this
|
|
730
|
-
* @chainable
|
|
731
|
-
*/
|
|
732
|
-
Mocha.prototype.passOnFailingTestSuite = function(passOnFailingTestSuite) {
|
|
733
|
-
this.options.passOnFailingTestSuite = passOnFailingTestSuite === true;
|
|
734
|
-
return this;
|
|
735
|
-
};
|
|
736
|
-
/**
|
|
737
|
-
* Causes tests marked `only` to fail the suite.
|
|
738
|
-
*
|
|
739
|
-
* @public
|
|
740
|
-
* @see [CLI option](../#-forbid-only)
|
|
741
|
-
* @param {boolean} [forbidOnly=true] - Whether tests marked `only` fail the suite.
|
|
742
|
-
* @returns {Mocha} this
|
|
743
|
-
* @chainable
|
|
744
|
-
*/
|
|
745
|
-
Mocha.prototype.forbidOnly = function(forbidOnly) {
|
|
746
|
-
this.options.forbidOnly = forbidOnly !== false;
|
|
747
|
-
return this;
|
|
748
|
-
};
|
|
749
|
-
/**
|
|
750
|
-
* Causes pending tests and tests marked `skip` to fail the suite.
|
|
751
|
-
*
|
|
752
|
-
* @public
|
|
753
|
-
* @see [CLI option](../#-forbid-pending)
|
|
754
|
-
* @param {boolean} [forbidPending=true] - Whether pending tests fail the suite.
|
|
755
|
-
* @returns {Mocha} this
|
|
756
|
-
* @chainable
|
|
757
|
-
*/
|
|
758
|
-
Mocha.prototype.forbidPending = function(forbidPending) {
|
|
759
|
-
this.options.forbidPending = forbidPending !== false;
|
|
760
|
-
return this;
|
|
761
|
-
};
|
|
762
|
-
/**
|
|
763
|
-
* Throws an error if mocha is in the wrong state to be able to transition to a "running" state.
|
|
764
|
-
* @private
|
|
765
|
-
*/
|
|
766
|
-
Mocha.prototype._guardRunningStateTransition = function() {
|
|
767
|
-
if (this._state === mochaStates.RUNNING) throw createMochaInstanceAlreadyRunningError("Mocha instance is currently running tests, cannot start a next test run until this one is done", this);
|
|
768
|
-
if (this._state === mochaStates.DISPOSED || this._state === mochaStates.REFERENCES_CLEANED) throw createMochaInstanceAlreadyDisposedError("Mocha instance is already disposed, cannot start a new test run. Please create a new mocha instance. Be sure to set disable `cleanReferencesAfterRun` when you want to reuse the same mocha instance for multiple test runs.", this._cleanReferencesAfterRun, this);
|
|
769
|
-
};
|
|
770
|
-
/**
|
|
771
|
-
* Mocha version as specified by "package.json".
|
|
772
|
-
*
|
|
773
|
-
* @name Mocha#version
|
|
774
|
-
* @type string
|
|
775
|
-
* @readonly
|
|
776
|
-
*/
|
|
777
|
-
Object.defineProperty(Mocha.prototype, "version", {
|
|
778
|
-
value: require_package().version,
|
|
779
|
-
configurable: false,
|
|
780
|
-
enumerable: true,
|
|
781
|
-
writable: false
|
|
782
|
-
});
|
|
783
|
-
/**
|
|
784
|
-
* Runs root suite and invokes `fn()` when complete.
|
|
785
|
-
*
|
|
786
|
-
* @description
|
|
787
|
-
* To run tests multiple times (or to run tests in files that are
|
|
788
|
-
* already in the `require` cache), make sure to clear them from
|
|
789
|
-
* the cache first!
|
|
790
|
-
*
|
|
791
|
-
* @public
|
|
792
|
-
* @see {@link Mocha#unloadFiles}
|
|
793
|
-
* @see {@link Runner#run}
|
|
794
|
-
* @param {DoneCB} [fn] - Callback invoked when test execution completed.
|
|
795
|
-
* @returns {import("./runner.js")} runner instance
|
|
796
|
-
* @example
|
|
797
|
-
*
|
|
798
|
-
* // exit with non-zero status if there were test failures
|
|
799
|
-
* mocha.run(failures => process.exitCode = failures ? 1 : 0);
|
|
800
|
-
*/
|
|
801
|
-
Mocha.prototype.run = function(fn) {
|
|
802
|
-
this._guardRunningStateTransition();
|
|
803
|
-
this._state = mochaStates.RUNNING;
|
|
804
|
-
if (this._previousRunner) {
|
|
805
|
-
this._previousRunner.dispose();
|
|
806
|
-
this.suite.reset();
|
|
807
|
-
}
|
|
808
|
-
if (this.files.length && !this._lazyLoadFiles) this.loadFiles();
|
|
809
|
-
var suite = this.suite;
|
|
810
|
-
var options = this.options;
|
|
811
|
-
options.files = this.files;
|
|
812
|
-
const runner = new this._runnerClass(suite, {
|
|
813
|
-
cleanReferencesAfterRun: this._cleanReferencesAfterRun,
|
|
814
|
-
delay: options.delay,
|
|
815
|
-
dryRun: options.dryRun,
|
|
816
|
-
failZero: options.failZero
|
|
817
|
-
});
|
|
818
|
-
createStatsCollector(runner);
|
|
819
|
-
var reporter = new this._reporter(runner, options);
|
|
820
|
-
runner.checkLeaks = options.checkLeaks === true;
|
|
821
|
-
runner.fullStackTrace = options.fullTrace;
|
|
822
|
-
runner.asyncOnly = options.asyncOnly;
|
|
823
|
-
runner.allowUncaught = options.allowUncaught;
|
|
824
|
-
runner.forbidOnly = options.forbidOnly;
|
|
825
|
-
runner.forbidPending = options.forbidPending;
|
|
826
|
-
if (options.grep) runner.grep(options.grep, options.invert);
|
|
827
|
-
if (options.global) runner.globals(options.global);
|
|
828
|
-
if (options.color !== void 0) exports.reporters.Base.useColors = options.color;
|
|
829
|
-
exports.reporters.Base.inlineDiffs = options.inlineDiffs;
|
|
830
|
-
exports.reporters.Base.hideDiff = !options.diff;
|
|
831
|
-
const done = (failures) => {
|
|
832
|
-
this._previousRunner = runner;
|
|
833
|
-
this._state = this._cleanReferencesAfterRun ? mochaStates.REFERENCES_CLEANED : mochaStates.INIT;
|
|
834
|
-
fn = fn || utils.noop;
|
|
835
|
-
if (typeof reporter.done === "function") reporter.done(failures, fn);
|
|
836
|
-
else fn(failures);
|
|
837
|
-
};
|
|
838
|
-
const runAsync = async (runner$1) => {
|
|
839
|
-
const context = this.options.enableGlobalSetup && this.hasGlobalSetupFixtures() ? await this.runGlobalSetup(runner$1) : {};
|
|
840
|
-
const failureCount = await runner$1.runAsync({
|
|
841
|
-
files: this.files,
|
|
842
|
-
options
|
|
843
|
-
});
|
|
844
|
-
if (this.options.enableGlobalTeardown && this.hasGlobalTeardownFixtures()) await this.runGlobalTeardown(runner$1, { context });
|
|
845
|
-
return failureCount;
|
|
846
|
-
};
|
|
847
|
-
runAsync(runner).then(done);
|
|
848
|
-
return runner;
|
|
849
|
-
};
|
|
850
|
-
/**
|
|
851
|
-
* Assigns hooks to the root suite
|
|
852
|
-
* @param {MochaRootHookObject} [hooks] - Hooks to assign to root suite
|
|
853
|
-
* @chainable
|
|
854
|
-
*/
|
|
855
|
-
Mocha.prototype.rootHooks = function rootHooks({ beforeAll = [], beforeEach = [], afterAll = [], afterEach = [] } = {}) {
|
|
856
|
-
beforeAll = utils.castArray(beforeAll);
|
|
857
|
-
beforeEach = utils.castArray(beforeEach);
|
|
858
|
-
afterAll = utils.castArray(afterAll);
|
|
859
|
-
afterEach = utils.castArray(afterEach);
|
|
860
|
-
beforeAll.forEach((hook) => {
|
|
861
|
-
this.suite.beforeAll(hook);
|
|
862
|
-
});
|
|
863
|
-
beforeEach.forEach((hook) => {
|
|
864
|
-
this.suite.beforeEach(hook);
|
|
865
|
-
});
|
|
866
|
-
afterAll.forEach((hook) => {
|
|
867
|
-
this.suite.afterAll(hook);
|
|
868
|
-
});
|
|
869
|
-
afterEach.forEach((hook) => {
|
|
870
|
-
this.suite.afterEach(hook);
|
|
871
|
-
});
|
|
872
|
-
return this;
|
|
873
|
-
};
|
|
874
|
-
/**
|
|
875
|
-
* Toggles parallel mode.
|
|
876
|
-
*
|
|
877
|
-
* Must be run before calling {@link Mocha#run}. Changes the `Runner` class to
|
|
878
|
-
* use; also enables lazy file loading if not already done so.
|
|
879
|
-
*
|
|
880
|
-
* Warning: when passed `false` and lazy loading has been enabled _via any means_ (including calling `parallelMode(true)`), this method will _not_ disable lazy loading. Lazy loading is a prerequisite for parallel
|
|
881
|
-
* mode, but parallel mode is _not_ a prerequisite for lazy loading!
|
|
882
|
-
* @param {boolean} [enable] - If `true`, enable; otherwise disable.
|
|
883
|
-
* @throws If run in browser
|
|
884
|
-
* @throws If Mocha not in `INIT` state
|
|
885
|
-
* @returns {Mocha}
|
|
886
|
-
* @chainable
|
|
887
|
-
* @public
|
|
888
|
-
*/
|
|
889
|
-
Mocha.prototype.parallelMode = function parallelMode(enable = true) {
|
|
890
|
-
if (utils.isBrowser()) throw createUnsupportedError("parallel mode is only supported in Node.js");
|
|
891
|
-
const parallel = Boolean(enable);
|
|
892
|
-
if (parallel === this.options.parallel && this._lazyLoadFiles && this._runnerClass !== exports.Runner) return this;
|
|
893
|
-
if (this._state !== mochaStates.INIT) throw createUnsupportedError("cannot change parallel mode after having called run()");
|
|
894
|
-
this.options.parallel = parallel;
|
|
895
|
-
this._runnerClass = parallel ? require_parallel_buffered_runner() : exports.Runner;
|
|
896
|
-
return this.lazyLoadFiles(this._lazyLoadFiles || parallel);
|
|
897
|
-
};
|
|
898
|
-
/**
|
|
899
|
-
* Disables implicit call to {@link Mocha#loadFiles} in {@link Mocha#run}. This
|
|
900
|
-
* setting is used by watch mode, parallel mode, and for loading ESM files.
|
|
901
|
-
* @todo This should throw if we've already loaded files; such behavior
|
|
902
|
-
* necessitates adding a new state.
|
|
903
|
-
* @param {boolean} [enable] - If `true`, disable eager loading of files in
|
|
904
|
-
* {@link Mocha#run}
|
|
905
|
-
* @chainable
|
|
906
|
-
* @public
|
|
907
|
-
*/
|
|
908
|
-
Mocha.prototype.lazyLoadFiles = function lazyLoadFiles(enable) {
|
|
909
|
-
this._lazyLoadFiles = enable === true;
|
|
910
|
-
debug("set lazy load to %s", enable);
|
|
911
|
-
return this;
|
|
912
|
-
};
|
|
913
|
-
/**
|
|
914
|
-
* Configures one or more global setup fixtures.
|
|
915
|
-
*
|
|
916
|
-
* If given no parameters, _unsets_ any previously-set fixtures.
|
|
917
|
-
* @chainable
|
|
918
|
-
* @public
|
|
919
|
-
* @param {MochaGlobalFixture|MochaGlobalFixture[]} [setupFns] - Global setup fixture(s)
|
|
920
|
-
* @returns {Mocha}
|
|
921
|
-
*/
|
|
922
|
-
Mocha.prototype.globalSetup = function globalSetup(setupFns = []) {
|
|
923
|
-
setupFns = utils.castArray(setupFns);
|
|
924
|
-
this.options.globalSetup = setupFns;
|
|
925
|
-
debug("configured %d global setup functions", setupFns.length);
|
|
926
|
-
return this;
|
|
927
|
-
};
|
|
928
|
-
/**
|
|
929
|
-
* Configures one or more global teardown fixtures.
|
|
930
|
-
*
|
|
931
|
-
* If given no parameters, _unsets_ any previously-set fixtures.
|
|
932
|
-
* @chainable
|
|
933
|
-
* @public
|
|
934
|
-
* @param {MochaGlobalFixture|MochaGlobalFixture[]} [teardownFns] - Global teardown fixture(s)
|
|
935
|
-
* @returns {Mocha}
|
|
936
|
-
*/
|
|
937
|
-
Mocha.prototype.globalTeardown = function globalTeardown(teardownFns = []) {
|
|
938
|
-
teardownFns = utils.castArray(teardownFns);
|
|
939
|
-
this.options.globalTeardown = teardownFns;
|
|
940
|
-
debug("configured %d global teardown functions", teardownFns.length);
|
|
941
|
-
return this;
|
|
942
|
-
};
|
|
943
|
-
/**
|
|
944
|
-
* Run any global setup fixtures sequentially, if any.
|
|
945
|
-
*
|
|
946
|
-
* This is _automatically called_ by {@link Mocha#run} _unless_ the `runGlobalSetup` option is `false`; see {@link Mocha#enableGlobalSetup}.
|
|
947
|
-
*
|
|
948
|
-
* The context object this function resolves with should be consumed by {@link Mocha#runGlobalTeardown}.
|
|
949
|
-
* @param {object} [context] - Context object if already have one
|
|
950
|
-
* @public
|
|
951
|
-
* @returns {Promise<object>} Context object
|
|
952
|
-
*/
|
|
953
|
-
Mocha.prototype.runGlobalSetup = async function runGlobalSetup(context = {}) {
|
|
954
|
-
const { globalSetup } = this.options;
|
|
955
|
-
if (globalSetup && globalSetup.length) {
|
|
956
|
-
debug("run(): global setup starting");
|
|
957
|
-
await this._runGlobalFixtures(globalSetup, context);
|
|
958
|
-
debug("run(): global setup complete");
|
|
959
|
-
}
|
|
960
|
-
return context;
|
|
961
|
-
};
|
|
962
|
-
/**
|
|
963
|
-
* Run any global teardown fixtures sequentially, if any.
|
|
964
|
-
*
|
|
965
|
-
* This is _automatically called_ by {@link Mocha#run} _unless_ the `runGlobalTeardown` option is `false`; see {@link Mocha#enableGlobalTeardown}.
|
|
966
|
-
*
|
|
967
|
-
* Should be called with context object returned by {@link Mocha#runGlobalSetup}, if applicable.
|
|
968
|
-
* @param {object} [context] - Context object if already have one
|
|
969
|
-
* @public
|
|
970
|
-
* @returns {Promise<object>} Context object
|
|
971
|
-
*/
|
|
972
|
-
Mocha.prototype.runGlobalTeardown = async function runGlobalTeardown(context = {}) {
|
|
973
|
-
const { globalTeardown } = this.options;
|
|
974
|
-
if (globalTeardown && globalTeardown.length) {
|
|
975
|
-
debug("run(): global teardown starting");
|
|
976
|
-
await this._runGlobalFixtures(globalTeardown, context);
|
|
977
|
-
}
|
|
978
|
-
debug("run(): global teardown complete");
|
|
979
|
-
return context;
|
|
980
|
-
};
|
|
981
|
-
/**
|
|
982
|
-
* Run global fixtures sequentially with context `context`
|
|
983
|
-
* @private
|
|
984
|
-
* @param {MochaGlobalFixture[]} [fixtureFns] - Fixtures to run
|
|
985
|
-
* @param {object} [context] - context object
|
|
986
|
-
* @returns {Promise<object>} context object
|
|
987
|
-
*/
|
|
988
|
-
Mocha.prototype._runGlobalFixtures = async function _runGlobalFixtures(fixtureFns = [], context = {}) {
|
|
989
|
-
for await (const fixtureFn of fixtureFns) await fixtureFn.call(context);
|
|
990
|
-
return context;
|
|
991
|
-
};
|
|
992
|
-
/**
|
|
993
|
-
* Toggle execution of any global setup fixture(s)
|
|
994
|
-
*
|
|
995
|
-
* @chainable
|
|
996
|
-
* @public
|
|
997
|
-
* @param {boolean } [enabled=true] - If `false`, do not run global setup fixture
|
|
998
|
-
* @returns {Mocha}
|
|
999
|
-
*/
|
|
1000
|
-
Mocha.prototype.enableGlobalSetup = function enableGlobalSetup(enabled = true) {
|
|
1001
|
-
this.options.enableGlobalSetup = Boolean(enabled);
|
|
1002
|
-
return this;
|
|
1003
|
-
};
|
|
1004
|
-
/**
|
|
1005
|
-
* Toggle execution of any global teardown fixture(s)
|
|
1006
|
-
*
|
|
1007
|
-
* @chainable
|
|
1008
|
-
* @public
|
|
1009
|
-
* @param {boolean } [enabled=true] - If `false`, do not run global teardown fixture
|
|
1010
|
-
* @returns {Mocha}
|
|
1011
|
-
*/
|
|
1012
|
-
Mocha.prototype.enableGlobalTeardown = function enableGlobalTeardown(enabled = true) {
|
|
1013
|
-
this.options.enableGlobalTeardown = Boolean(enabled);
|
|
1014
|
-
return this;
|
|
1015
|
-
};
|
|
1016
|
-
/**
|
|
1017
|
-
* Returns `true` if one or more global setup fixtures have been supplied.
|
|
1018
|
-
* @public
|
|
1019
|
-
* @returns {boolean}
|
|
1020
|
-
*/
|
|
1021
|
-
Mocha.prototype.hasGlobalSetupFixtures = function hasGlobalSetupFixtures() {
|
|
1022
|
-
return Boolean(this.options.globalSetup.length);
|
|
1023
|
-
};
|
|
1024
|
-
/**
|
|
1025
|
-
* Returns `true` if one or more global teardown fixtures have been supplied.
|
|
1026
|
-
* @public
|
|
1027
|
-
* @returns {boolean}
|
|
1028
|
-
*/
|
|
1029
|
-
Mocha.prototype.hasGlobalTeardownFixtures = function hasGlobalTeardownFixtures() {
|
|
1030
|
-
return Boolean(this.options.globalTeardown.length);
|
|
1031
|
-
};
|
|
1032
|
-
}) });
|
|
1033
|
-
|
|
1034
|
-
//#endregion
|
|
1035
|
-
export default require_mocha();
|
|
1036
|
-
|
|
1037
|
-
export { require_mocha };
|