vitest 0.9.4 → 0.10.0
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/LICENSE.md +7 -0
- package/dist/{chunk-api-setup.49283db8.js → chunk-api-setup.d70fc960.js} +5 -5
- package/dist/{chunk-constants.c8f1d38c.js → chunk-constants.d540b1d1.js} +1 -1
- package/dist/{chunk-defaults.43e746f3.js → chunk-defaults.04d5d90b.js} +1 -1
- package/dist/{chunk-install-pkg.cbf3a38b.js → chunk-install-pkg.73b84ae1.js} +113 -115
- package/dist/chunk-integrations-globals.d2c09cd2.js +29 -0
- package/dist/chunk-integrations-spy.f036df6f.js +102 -0
- package/dist/{chunk-runtime-chain.701cffd8.js → chunk-runtime-chain.f863f182.js} +931 -897
- package/dist/{chunk-runtime-mocker.e802beae.js → chunk-runtime-mocker.111ac858.js} +3 -3
- package/dist/{chunk-runtime-rpc.c47f2233.js → chunk-runtime-rpc.8f648236.js} +1 -1
- package/dist/{chunk-utils-global.a3293dce.js → chunk-utils-global.37a7c822.js} +8 -10
- package/dist/{chunk-utils-timers.b26e7c5c.js → chunk-utils-timers.12bc05d1.js} +1404 -1057
- package/dist/{chunk-vite-node-externalize.1c19fc5e.js → chunk-vite-node-externalize.5c678054.js} +544 -517
- package/dist/{chunk-vite-node-utils.b4debb0b.js → chunk-vite-node-utils.33447cc0.js} +71 -71
- package/dist/cli.js +12 -12
- package/dist/entry.js +15 -919
- package/dist/index.d.ts +90 -25
- package/dist/index.js +8 -8
- package/dist/node.d.ts +24 -7
- package/dist/node.js +11 -11
- package/dist/spy.js +2 -102
- package/dist/vendor-_commonjsHelpers.addc3445.js +3 -0
- package/dist/vendor-entry.369fd6c9.js +949 -0
- package/dist/vendor-index.405e58ef.js +6291 -0
- package/dist/{vendor-index.bd255bc8.js → vendor-index.40be925a.js} +173 -158
- package/dist/worker.js +6 -6
- package/package.json +4 -4
- package/dist/chunk-integrations-globals.b4a20711.js +0 -23
- package/dist/vendor-_commonjsHelpers.34b404ce.js +0 -7
- package/dist/vendor-index.13468339.js +0 -5707
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import { c as commonjsRequire, a as commonjsGlobal } from './vendor-_commonjsHelpers.34b404ce.js';
|
|
6
|
-
import { r as rpc } from './chunk-runtime-rpc.c47f2233.js';
|
|
1
|
+
import chai$1, { expect as expect$1, util } from 'chai';
|
|
2
|
+
import { c as commonjsGlobal } from './vendor-_commonjsHelpers.addc3445.js';
|
|
3
|
+
import { r as rpc } from './chunk-runtime-rpc.8f648236.js';
|
|
4
|
+
import { i as isObject, a as index, g as getCallLastIndex, s as slash, b as getWorkerState, c as getNames, d as assertTypes, p as picocolors, n as noop, t as toArray, r as resetModules } from './chunk-utils-global.37a7c822.js';
|
|
7
5
|
import fs, { promises } from 'fs';
|
|
8
|
-
import {
|
|
6
|
+
import { p as plugins_1, f as format_1, g as getOriginalPos, a as posToNumber, n as numberToPos, l as lineSplitRE, b as parseStacktrace, u as unifiedDiff, s as stringify, m as matcherUtils, c as setTimeout, d as clearTimeout } from './chunk-utils-timers.12bc05d1.js';
|
|
7
|
+
import { i as isMockFunction, s as spyOn, f as fn, a as spies } from './chunk-integrations-spy.f036df6f.js';
|
|
8
|
+
import require$$0, { format } from 'util';
|
|
9
9
|
|
|
10
10
|
var __defProp$4 = Object.defineProperty;
|
|
11
11
|
var __defProps$2 = Object.defineProperties;
|
|
@@ -45,313 +45,92 @@ function createChainable(keys, fn) {
|
|
|
45
45
|
return chain;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
currentSuite: null
|
|
51
|
-
};
|
|
52
|
-
function collectTask(task) {
|
|
53
|
-
var _a;
|
|
54
|
-
(_a = context.currentSuite) == null ? void 0 : _a.tasks.push(task);
|
|
55
|
-
}
|
|
56
|
-
async function runWithSuite(suite, fn) {
|
|
57
|
-
const prev = context.currentSuite;
|
|
58
|
-
context.currentSuite = suite;
|
|
59
|
-
await fn();
|
|
60
|
-
context.currentSuite = prev;
|
|
61
|
-
}
|
|
62
|
-
function getDefaultTestTimeout() {
|
|
63
|
-
return getWorkerState().config.testTimeout;
|
|
64
|
-
}
|
|
65
|
-
function getDefaultHookTimeout() {
|
|
66
|
-
return getWorkerState().config.hookTimeout;
|
|
67
|
-
}
|
|
68
|
-
function withTimeout(fn, timeout = getDefaultTestTimeout(), isHook = false) {
|
|
69
|
-
if (timeout <= 0 || timeout === Infinity)
|
|
70
|
-
return fn;
|
|
71
|
-
return (...args) => {
|
|
72
|
-
return Promise.race([fn(...args), new Promise((resolve, reject) => {
|
|
73
|
-
const timer = setTimeout(() => {
|
|
74
|
-
clearTimeout(timer);
|
|
75
|
-
reject(new Error(makeTimeoutMsg(isHook, timeout)));
|
|
76
|
-
}, timeout);
|
|
77
|
-
timer.unref();
|
|
78
|
-
})]);
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
function makeTimeoutMsg(isHook, timeout) {
|
|
82
|
-
return `${isHook ? "Hook" : "Test"} timed out in ${timeout}ms.
|
|
83
|
-
If this is a long-running test, pass a timeout value as the last argument or configure it globally with "${isHook ? "hookTimeout" : "testTimeout"}".`;
|
|
84
|
-
}
|
|
85
|
-
function ensureAsyncTest(fn) {
|
|
86
|
-
if (!fn.length)
|
|
87
|
-
return fn;
|
|
88
|
-
return () => new Promise((resolve, reject) => {
|
|
89
|
-
const done = (...args) => args[0] ? reject(args[0]) : resolve();
|
|
90
|
-
fn(done);
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
function normalizeTest(fn, timeout) {
|
|
94
|
-
return withTimeout(ensureAsyncTest(fn), timeout);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const fnMap = /* @__PURE__ */ new WeakMap();
|
|
98
|
-
const hooksMap = /* @__PURE__ */ new WeakMap();
|
|
99
|
-
function setFn(key, fn) {
|
|
100
|
-
fnMap.set(key, fn);
|
|
101
|
-
}
|
|
102
|
-
function getFn(key) {
|
|
103
|
-
return fnMap.get(key);
|
|
104
|
-
}
|
|
105
|
-
function setHooks(key, hooks) {
|
|
106
|
-
hooksMap.set(key, hooks);
|
|
107
|
-
}
|
|
108
|
-
function getHooks(key) {
|
|
109
|
-
return hooksMap.get(key);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const suite = createSuite();
|
|
113
|
-
const test = createTest(function(name, fn, timeout) {
|
|
114
|
-
getCurrentSuite().test.fn.call(this, name, fn, timeout);
|
|
115
|
-
});
|
|
116
|
-
function formatTitle(template, items, idx) {
|
|
117
|
-
if (template.includes("%#")) {
|
|
118
|
-
template = template.replace(/%%/g, "__vitest_escaped_%__").replace(/%#/g, `${idx}`).replace(/__vitest_escaped_%__/g, "%%");
|
|
119
|
-
}
|
|
120
|
-
const count = template.split("%").length - 1;
|
|
121
|
-
let formatted = format(template, ...items.slice(0, count));
|
|
122
|
-
if (isObject(items[0])) {
|
|
123
|
-
formatted = formatted.replace(/\$([$\w_]+)/g, (_, key) => {
|
|
124
|
-
return items[0][key];
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
return formatted;
|
|
128
|
-
}
|
|
129
|
-
const describe = suite;
|
|
130
|
-
const it = test;
|
|
131
|
-
const defaultSuite = suite("");
|
|
132
|
-
function clearContext() {
|
|
133
|
-
context.tasks.length = 0;
|
|
134
|
-
defaultSuite.clear();
|
|
135
|
-
context.currentSuite = defaultSuite;
|
|
136
|
-
}
|
|
137
|
-
function getCurrentSuite() {
|
|
138
|
-
return context.currentSuite || defaultSuite;
|
|
139
|
-
}
|
|
140
|
-
function createSuiteHooks() {
|
|
141
|
-
return {
|
|
142
|
-
beforeAll: [],
|
|
143
|
-
afterAll: [],
|
|
144
|
-
beforeEach: [],
|
|
145
|
-
afterEach: []
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
function createSuiteCollector(name, factory = () => {
|
|
149
|
-
}, mode, concurrent) {
|
|
150
|
-
const tasks = [];
|
|
151
|
-
const factoryQueue = [];
|
|
152
|
-
let suite2;
|
|
153
|
-
initSuite();
|
|
154
|
-
const test2 = createTest(function(name2, fn, timeout) {
|
|
155
|
-
const mode2 = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
|
|
156
|
-
const test3 = {
|
|
157
|
-
id: "",
|
|
158
|
-
type: "test",
|
|
159
|
-
name: name2,
|
|
160
|
-
mode: mode2,
|
|
161
|
-
suite: void 0,
|
|
162
|
-
fails: this.fails
|
|
163
|
-
};
|
|
164
|
-
if (this.concurrent || concurrent)
|
|
165
|
-
test3.concurrent = true;
|
|
166
|
-
setFn(test3, normalizeTest(fn || noop, timeout));
|
|
167
|
-
tasks.push(test3);
|
|
168
|
-
});
|
|
169
|
-
const collector = {
|
|
170
|
-
type: "collector",
|
|
171
|
-
name,
|
|
172
|
-
mode,
|
|
173
|
-
test: test2,
|
|
174
|
-
tasks,
|
|
175
|
-
collect,
|
|
176
|
-
clear,
|
|
177
|
-
on: addHook
|
|
178
|
-
};
|
|
179
|
-
function addHook(name2, ...fn) {
|
|
180
|
-
getHooks(suite2)[name2].push(...fn);
|
|
181
|
-
}
|
|
182
|
-
function initSuite() {
|
|
183
|
-
suite2 = {
|
|
184
|
-
id: "",
|
|
185
|
-
type: "suite",
|
|
186
|
-
name,
|
|
187
|
-
mode,
|
|
188
|
-
tasks: []
|
|
189
|
-
};
|
|
190
|
-
setHooks(suite2, createSuiteHooks());
|
|
191
|
-
}
|
|
192
|
-
function clear() {
|
|
193
|
-
tasks.length = 0;
|
|
194
|
-
factoryQueue.length = 0;
|
|
195
|
-
initSuite();
|
|
196
|
-
}
|
|
197
|
-
async function collect(file) {
|
|
198
|
-
factoryQueue.length = 0;
|
|
199
|
-
if (factory)
|
|
200
|
-
await runWithSuite(collector, () => factory(test2));
|
|
201
|
-
const allChildren = [];
|
|
202
|
-
for (const i of [...factoryQueue, ...tasks])
|
|
203
|
-
allChildren.push(i.type === "collector" ? await i.collect(file) : i);
|
|
204
|
-
suite2.file = file;
|
|
205
|
-
suite2.tasks = allChildren;
|
|
206
|
-
allChildren.forEach((task) => {
|
|
207
|
-
task.suite = suite2;
|
|
208
|
-
if (file)
|
|
209
|
-
task.file = file;
|
|
210
|
-
});
|
|
211
|
-
return suite2;
|
|
212
|
-
}
|
|
213
|
-
collectTask(collector);
|
|
214
|
-
return collector;
|
|
215
|
-
}
|
|
216
|
-
function createSuite() {
|
|
217
|
-
const suite2 = createChainable(["concurrent", "skip", "only", "todo"], function(name, factory) {
|
|
218
|
-
const mode = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
|
|
219
|
-
return createSuiteCollector(name, factory, mode, this.concurrent);
|
|
220
|
-
});
|
|
221
|
-
suite2.each = (cases) => {
|
|
222
|
-
return (name, fn) => {
|
|
223
|
-
cases.forEach((i, idx) => {
|
|
224
|
-
const items = toArray(i);
|
|
225
|
-
suite2(formatTitle(name, items, idx), () => fn(...items));
|
|
226
|
-
});
|
|
227
|
-
};
|
|
228
|
-
};
|
|
229
|
-
return suite2;
|
|
230
|
-
}
|
|
231
|
-
function createTest(fn) {
|
|
232
|
-
const test2 = createChainable(["concurrent", "skip", "only", "todo", "fails"], fn);
|
|
233
|
-
test2.each = (cases) => {
|
|
234
|
-
return (name, fn2) => {
|
|
235
|
-
cases.forEach((i, idx) => {
|
|
236
|
-
const items = toArray(i);
|
|
237
|
-
test2(formatTitle(name, items, idx), () => fn2(...items));
|
|
238
|
-
});
|
|
239
|
-
};
|
|
240
|
-
};
|
|
241
|
-
return test2;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
const beforeAll = (fn, timeout) => getCurrentSuite().on("beforeAll", withTimeout(fn, timeout ?? getDefaultHookTimeout(), true));
|
|
245
|
-
const afterAll = (fn, timeout) => getCurrentSuite().on("afterAll", withTimeout(fn, timeout ?? getDefaultHookTimeout(), true));
|
|
246
|
-
const beforeEach = (fn, timeout) => getCurrentSuite().on("beforeEach", withTimeout(fn, timeout ?? getDefaultHookTimeout(), true));
|
|
247
|
-
const afterEach = (fn, timeout) => getCurrentSuite().on("afterEach", withTimeout(fn, timeout ?? getDefaultHookTimeout(), true));
|
|
248
|
-
|
|
249
|
-
const filesCount = /* @__PURE__ */ new Map();
|
|
250
|
-
const cache = /* @__PURE__ */ new Map();
|
|
251
|
-
function runOnce(fn, key) {
|
|
252
|
-
const filepath = getWorkerState().filepath || "__unknown_files__";
|
|
253
|
-
if (!key) {
|
|
254
|
-
filesCount.set(filepath, (filesCount.get(filepath) || 0) + 1);
|
|
255
|
-
key = String(filesCount.get(filepath));
|
|
256
|
-
}
|
|
257
|
-
const id = `${filepath}:${key}`;
|
|
258
|
-
if (!cache.has(id))
|
|
259
|
-
cache.set(id, fn());
|
|
260
|
-
return cache.get(id);
|
|
261
|
-
}
|
|
262
|
-
function isFirstRun() {
|
|
263
|
-
let firstRun = false;
|
|
264
|
-
runOnce(() => {
|
|
265
|
-
firstRun = true;
|
|
266
|
-
}, "__vitest_first_run__");
|
|
267
|
-
return firstRun;
|
|
268
|
-
}
|
|
269
|
-
function resetRunOnceCounter() {
|
|
270
|
-
filesCount.clear();
|
|
48
|
+
function commonjsRequire(path) {
|
|
49
|
+
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
|
|
271
50
|
}
|
|
272
51
|
|
|
273
52
|
var chaiSubset = {exports: {}};
|
|
274
53
|
|
|
275
54
|
(function (module, exports) {
|
|
276
|
-
(function() {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
}
|
|
283
|
-
})(function(chai, utils) {
|
|
284
|
-
var Assertion = chai.Assertion;
|
|
285
|
-
var assertionPrototype = Assertion.prototype;
|
|
286
|
-
|
|
287
|
-
Assertion.addMethod('containSubset', function (expected) {
|
|
288
|
-
var actual = utils.flag(this, 'object');
|
|
289
|
-
var showDiff = chai.config.showDiff;
|
|
290
|
-
|
|
291
|
-
assertionPrototype.assert.call(this,
|
|
292
|
-
compare(expected, actual),
|
|
293
|
-
'expected #{act} to contain subset #{exp}',
|
|
294
|
-
'expected #{act} to not contain subset #{exp}',
|
|
295
|
-
expected,
|
|
296
|
-
actual,
|
|
297
|
-
showDiff
|
|
298
|
-
);
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
chai.assert.containSubset = function(val, exp, msg) {
|
|
302
|
-
new chai.Assertion(val, msg).to.be.containSubset(exp);
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
function compare(expected, actual) {
|
|
306
|
-
if (expected === actual) {
|
|
307
|
-
return true;
|
|
308
|
-
}
|
|
309
|
-
if (typeof(actual) !== typeof(expected)) {
|
|
310
|
-
return false;
|
|
311
|
-
}
|
|
312
|
-
if (typeof(expected) !== 'object' || expected === null) {
|
|
313
|
-
return expected === actual;
|
|
314
|
-
}
|
|
315
|
-
if (!!expected && !actual) {
|
|
316
|
-
return false;
|
|
55
|
+
(function() {
|
|
56
|
+
(function(chaiSubset) {
|
|
57
|
+
if (typeof commonjsRequire === 'function' && 'object' === 'object' && 'object' === 'object') {
|
|
58
|
+
return module.exports = chaiSubset;
|
|
59
|
+
} else {
|
|
60
|
+
return chai.use(chaiSubset);
|
|
317
61
|
}
|
|
62
|
+
})(function(chai, utils) {
|
|
63
|
+
var Assertion = chai.Assertion;
|
|
64
|
+
var assertionPrototype = Assertion.prototype;
|
|
65
|
+
|
|
66
|
+
Assertion.addMethod('containSubset', function (expected) {
|
|
67
|
+
var actual = utils.flag(this, 'object');
|
|
68
|
+
var showDiff = chai.config.showDiff;
|
|
69
|
+
|
|
70
|
+
assertionPrototype.assert.call(this,
|
|
71
|
+
compare(expected, actual),
|
|
72
|
+
'expected #{act} to contain subset #{exp}',
|
|
73
|
+
'expected #{act} to not contain subset #{exp}',
|
|
74
|
+
expected,
|
|
75
|
+
actual,
|
|
76
|
+
showDiff
|
|
77
|
+
);
|
|
78
|
+
});
|
|
318
79
|
|
|
319
|
-
|
|
320
|
-
|
|
80
|
+
chai.assert.containSubset = function(val, exp, msg) {
|
|
81
|
+
new chai.Assertion(val, msg).to.be.containSubset(exp);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
function compare(expected, actual) {
|
|
85
|
+
if (expected === actual) {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
if (typeof(actual) !== typeof(expected)) {
|
|
321
89
|
return false;
|
|
322
90
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
});
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
if (expected instanceof Date) {
|
|
332
|
-
if (actual instanceof Date) {
|
|
333
|
-
return expected.getTime() === actual.getTime();
|
|
334
|
-
} else {
|
|
91
|
+
if (typeof(expected) !== 'object' || expected === null) {
|
|
92
|
+
return expected === actual;
|
|
93
|
+
}
|
|
94
|
+
if (!!expected && !actual) {
|
|
335
95
|
return false;
|
|
336
96
|
}
|
|
337
|
-
}
|
|
338
97
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
98
|
+
if (Array.isArray(expected)) {
|
|
99
|
+
if (typeof(actual.length) !== 'number') {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
var aa = Array.prototype.slice.call(actual);
|
|
103
|
+
return expected.every(function (exp) {
|
|
104
|
+
return aa.some(function (act) {
|
|
105
|
+
return compare(exp, act);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
344
108
|
}
|
|
345
|
-
|
|
346
|
-
|
|
109
|
+
|
|
110
|
+
if (expected instanceof Date) {
|
|
111
|
+
if (actual instanceof Date) {
|
|
112
|
+
return expected.getTime() === actual.getTime();
|
|
113
|
+
} else {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
347
116
|
}
|
|
348
|
-
return ao === eo;
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
});
|
|
352
117
|
|
|
353
|
-
|
|
354
|
-
|
|
118
|
+
return Object.keys(expected).every(function (key) {
|
|
119
|
+
var eo = expected[key];
|
|
120
|
+
var ao = actual[key];
|
|
121
|
+
if (typeof(eo) === 'object' && eo !== null && ao !== null) {
|
|
122
|
+
return compare(eo, ao);
|
|
123
|
+
}
|
|
124
|
+
if (typeof(eo) === 'function') {
|
|
125
|
+
return eo(ao);
|
|
126
|
+
}
|
|
127
|
+
return ao === eo;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
}).call(commonjsGlobal);
|
|
133
|
+
} (chaiSubset));
|
|
355
134
|
|
|
356
135
|
var Subset = chaiSubset.exports;
|
|
357
136
|
|
|
@@ -597,7 +376,7 @@ const sparseArrayEquality = (a, b) => {
|
|
|
597
376
|
return equals(a, b, [iterableEquality, typeEquality], true) && equals(aKeys, bKeys);
|
|
598
377
|
};
|
|
599
378
|
|
|
600
|
-
var naturalCompare$
|
|
379
|
+
var naturalCompare$1 = {exports: {}};
|
|
601
380
|
|
|
602
381
|
/*
|
|
603
382
|
* @version 1.4.0
|
|
@@ -649,13 +428,11 @@ var naturalCompare = function(a, b) {
|
|
|
649
428
|
};
|
|
650
429
|
|
|
651
430
|
try {
|
|
652
|
-
naturalCompare$
|
|
431
|
+
naturalCompare$1.exports = naturalCompare;
|
|
653
432
|
} catch (e) {
|
|
654
433
|
String.naturalCompare = naturalCompare;
|
|
655
434
|
}
|
|
656
435
|
|
|
657
|
-
var naturalCompare$1 = naturalCompare$2.exports;
|
|
658
|
-
|
|
659
436
|
const {
|
|
660
437
|
DOMCollection,
|
|
661
438
|
DOMElement,
|
|
@@ -740,7 +517,7 @@ function printBacktickString(str) {
|
|
|
740
517
|
}
|
|
741
518
|
function ensureDirectoryExists(filePath) {
|
|
742
519
|
try {
|
|
743
|
-
fs.mkdirSync(index
|
|
520
|
+
fs.mkdirSync(index.join(index.dirname(filePath)), { recursive: true });
|
|
744
521
|
} catch {
|
|
745
522
|
}
|
|
746
523
|
}
|
|
@@ -748,7 +525,7 @@ function normalizeNewlines(string) {
|
|
|
748
525
|
return string.replace(/\r\n|\r/g, "\n");
|
|
749
526
|
}
|
|
750
527
|
async function saveSnapshotFile(snapshotData, snapshotPath) {
|
|
751
|
-
const snapshots = Object.keys(snapshotData).sort(naturalCompare$1).map((key) => `exports[${printBacktickString(key)}] = ${printBacktickString(normalizeNewlines(snapshotData[key]))};`);
|
|
528
|
+
const snapshots = Object.keys(snapshotData).sort(naturalCompare$1.exports).map((key) => `exports[${printBacktickString(key)}] = ${printBacktickString(normalizeNewlines(snapshotData[key]))};`);
|
|
752
529
|
ensureDirectoryExists(snapshotPath);
|
|
753
530
|
await promises.writeFile(snapshotPath, `${writeSnapshotVersion()}
|
|
754
531
|
|
|
@@ -911,9 +688,10 @@ var __spreadValues$2 = (a, b) => {
|
|
|
911
688
|
return a;
|
|
912
689
|
};
|
|
913
690
|
class SnapshotState {
|
|
914
|
-
constructor(snapshotPath, options) {
|
|
915
|
-
this.
|
|
916
|
-
|
|
691
|
+
constructor(testFilePath, snapshotPath, options) {
|
|
692
|
+
this.testFilePath = testFilePath;
|
|
693
|
+
this.snapshotPath = snapshotPath;
|
|
694
|
+
const { data, dirty } = getSnapshotData(this.snapshotPath, options.updateSnapshot);
|
|
917
695
|
this._initialData = data;
|
|
918
696
|
this._snapshotData = data;
|
|
919
697
|
this._dirty = dirty;
|
|
@@ -968,6 +746,7 @@ ${JSON.stringify(stacks)}`);
|
|
|
968
746
|
this.matched = 0;
|
|
969
747
|
this.unmatched = 0;
|
|
970
748
|
this.updated = 0;
|
|
749
|
+
this._dirty = false;
|
|
971
750
|
}
|
|
972
751
|
async save() {
|
|
973
752
|
const hasExternalSnapshots = Object.keys(this._snapshotData).length;
|
|
@@ -979,13 +758,13 @@ ${JSON.stringify(stacks)}`);
|
|
|
979
758
|
};
|
|
980
759
|
if ((this._dirty || this._uncheckedKeys.size) && !isEmpty) {
|
|
981
760
|
if (hasExternalSnapshots)
|
|
982
|
-
await saveSnapshotFile(this._snapshotData, this.
|
|
761
|
+
await saveSnapshotFile(this._snapshotData, this.snapshotPath);
|
|
983
762
|
if (hasInlineSnapshots)
|
|
984
763
|
await saveInlineSnapshots(this._inlineSnapshots);
|
|
985
764
|
status.saved = true;
|
|
986
|
-
} else if (!hasExternalSnapshots && fs.existsSync(this.
|
|
765
|
+
} else if (!hasExternalSnapshots && fs.existsSync(this.snapshotPath)) {
|
|
987
766
|
if (this._updateSnapshot === "all")
|
|
988
|
-
fs.unlinkSync(this.
|
|
767
|
+
fs.unlinkSync(this.snapshotPath);
|
|
989
768
|
status.deleted = true;
|
|
990
769
|
}
|
|
991
770
|
return status;
|
|
@@ -1022,7 +801,7 @@ ${JSON.stringify(stacks)}`);
|
|
|
1022
801
|
const expectedTrimmed = prepareExpected(expected);
|
|
1023
802
|
const pass = expectedTrimmed === prepareExpected(receivedSerialized);
|
|
1024
803
|
const hasSnapshot = expected !== void 0;
|
|
1025
|
-
const snapshotIsPersisted = isInline || fs.existsSync(this.
|
|
804
|
+
const snapshotIsPersisted = isInline || fs.existsSync(this.snapshotPath);
|
|
1026
805
|
if (pass && !isInline) {
|
|
1027
806
|
this._snapshotData[key] = receivedSerialized;
|
|
1028
807
|
}
|
|
@@ -1070,26 +849,57 @@ ${JSON.stringify(stacks)}`);
|
|
|
1070
849
|
}
|
|
1071
850
|
}
|
|
1072
851
|
}
|
|
852
|
+
async pack() {
|
|
853
|
+
const snapshot = {
|
|
854
|
+
filepath: this.testFilePath,
|
|
855
|
+
added: 0,
|
|
856
|
+
fileDeleted: false,
|
|
857
|
+
matched: 0,
|
|
858
|
+
unchecked: 0,
|
|
859
|
+
uncheckedKeys: [],
|
|
860
|
+
unmatched: 0,
|
|
861
|
+
updated: 0
|
|
862
|
+
};
|
|
863
|
+
const uncheckedCount = this.getUncheckedCount();
|
|
864
|
+
const uncheckedKeys = this.getUncheckedKeys();
|
|
865
|
+
if (uncheckedCount)
|
|
866
|
+
this.removeUncheckedKeys();
|
|
867
|
+
const status = await this.save();
|
|
868
|
+
snapshot.fileDeleted = status.deleted;
|
|
869
|
+
snapshot.added = this.added;
|
|
870
|
+
snapshot.matched = this.matched;
|
|
871
|
+
snapshot.unmatched = this.unmatched;
|
|
872
|
+
snapshot.updated = this.updated;
|
|
873
|
+
snapshot.unchecked = !status.deleted ? uncheckedCount : 0;
|
|
874
|
+
snapshot.uncheckedKeys = Array.from(uncheckedKeys);
|
|
875
|
+
return snapshot;
|
|
876
|
+
}
|
|
1073
877
|
}
|
|
1074
878
|
|
|
1075
879
|
class SnapshotClient {
|
|
1076
880
|
constructor() {
|
|
1077
|
-
this.
|
|
881
|
+
this.snapshotStateMap = /* @__PURE__ */ new Map();
|
|
1078
882
|
}
|
|
1079
883
|
async setTest(test) {
|
|
884
|
+
var _a;
|
|
1080
885
|
this.test = test;
|
|
1081
|
-
if (this.
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
886
|
+
if (((_a = this.snapshotState) == null ? void 0 : _a.testFilePath) !== this.test.file.filepath) {
|
|
887
|
+
this.saveCurrent();
|
|
888
|
+
const filePath = this.test.file.filepath;
|
|
889
|
+
if (!this.getSnapshotState(test)) {
|
|
890
|
+
this.snapshotStateMap.set(filePath, new SnapshotState(filePath, await rpc().resolveSnapshotPath(filePath), getWorkerState().config.snapshotOptions));
|
|
891
|
+
}
|
|
892
|
+
this.snapshotState = this.getSnapshotState(test);
|
|
1086
893
|
}
|
|
1087
894
|
}
|
|
895
|
+
getSnapshotState(test) {
|
|
896
|
+
return this.snapshotStateMap.get(test.file.filepath);
|
|
897
|
+
}
|
|
1088
898
|
clearTest() {
|
|
1089
899
|
this.test = void 0;
|
|
1090
900
|
}
|
|
1091
|
-
assert(received, message, isInline = false, properties, inlineSnapshot, error) {
|
|
1092
|
-
if (!
|
|
901
|
+
assert(received, test = this.test, message, isInline = false, properties, inlineSnapshot, error) {
|
|
902
|
+
if (!test)
|
|
1093
903
|
throw new Error("Snapshot cannot be used outside of test");
|
|
1094
904
|
if (typeof properties === "object") {
|
|
1095
905
|
if (typeof received !== "object" || !received)
|
|
@@ -1106,10 +916,11 @@ class SnapshotClient {
|
|
|
1106
916
|
}
|
|
1107
917
|
}
|
|
1108
918
|
const testName = [
|
|
1109
|
-
...getNames(
|
|
919
|
+
...getNames(test).slice(1),
|
|
1110
920
|
...message ? [message] : []
|
|
1111
921
|
].join(" > ");
|
|
1112
|
-
const
|
|
922
|
+
const snapshotState = this.getSnapshotState(test);
|
|
923
|
+
const { actual, expected, key, pass } = snapshotState.match({
|
|
1113
924
|
testName,
|
|
1114
925
|
received,
|
|
1115
926
|
isInline,
|
|
@@ -1125,39 +936,16 @@ class SnapshotClient {
|
|
|
1125
936
|
}
|
|
1126
937
|
}
|
|
1127
938
|
}
|
|
1128
|
-
async
|
|
1129
|
-
if (!this.
|
|
939
|
+
async saveCurrent() {
|
|
940
|
+
if (!this.snapshotState)
|
|
1130
941
|
return;
|
|
1131
|
-
const result = await
|
|
942
|
+
const result = await this.snapshotState.pack();
|
|
1132
943
|
await rpc().snapshotSaved(result);
|
|
1133
|
-
this.testFile = "";
|
|
1134
944
|
this.snapshotState = void 0;
|
|
1135
945
|
}
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
filepath,
|
|
1140
|
-
added: 0,
|
|
1141
|
-
fileDeleted: false,
|
|
1142
|
-
matched: 0,
|
|
1143
|
-
unchecked: 0,
|
|
1144
|
-
uncheckedKeys: [],
|
|
1145
|
-
unmatched: 0,
|
|
1146
|
-
updated: 0
|
|
1147
|
-
};
|
|
1148
|
-
const uncheckedCount = state.getUncheckedCount();
|
|
1149
|
-
const uncheckedKeys = state.getUncheckedKeys();
|
|
1150
|
-
if (uncheckedCount)
|
|
1151
|
-
state.removeUncheckedKeys();
|
|
1152
|
-
const status = await state.save();
|
|
1153
|
-
snapshot.fileDeleted = status.deleted;
|
|
1154
|
-
snapshot.added = state.added;
|
|
1155
|
-
snapshot.matched = state.matched;
|
|
1156
|
-
snapshot.unmatched = state.unmatched;
|
|
1157
|
-
snapshot.updated = state.updated;
|
|
1158
|
-
snapshot.unchecked = !status.deleted ? uncheckedCount : 0;
|
|
1159
|
-
snapshot.uncheckedKeys = Array.from(uncheckedKeys);
|
|
1160
|
-
return snapshot;
|
|
946
|
+
clear() {
|
|
947
|
+
this.snapshotStateMap.clear();
|
|
948
|
+
}
|
|
1161
949
|
}
|
|
1162
950
|
|
|
1163
951
|
let _client;
|
|
@@ -1180,16 +968,18 @@ const SnapshotPlugin = (chai, utils) => {
|
|
|
1180
968
|
for (const key of ["matchSnapshot", "toMatchSnapshot"]) {
|
|
1181
969
|
utils.addMethod(chai.Assertion.prototype, key, function(properties, message) {
|
|
1182
970
|
const expected = utils.flag(this, "object");
|
|
971
|
+
const test = utils.flag(this, "vitest-test");
|
|
1183
972
|
if (typeof properties === "string" && typeof message === "undefined") {
|
|
1184
973
|
message = properties;
|
|
1185
974
|
properties = void 0;
|
|
1186
975
|
}
|
|
1187
|
-
getSnapshotClient().assert(expected, message, false, properties);
|
|
976
|
+
getSnapshotClient().assert(expected, test, message, false, properties);
|
|
1188
977
|
});
|
|
1189
978
|
}
|
|
1190
979
|
utils.addMethod(chai.Assertion.prototype, "toMatchInlineSnapshot", function __VITEST_INLINE_SNAPSHOT__(properties, inlineSnapshot, message) {
|
|
1191
980
|
const expected = utils.flag(this, "object");
|
|
1192
981
|
const error = utils.flag(this, "error");
|
|
982
|
+
const test = utils.flag(this, "vitest-test");
|
|
1193
983
|
if (typeof properties === "string") {
|
|
1194
984
|
message = inlineSnapshot;
|
|
1195
985
|
inlineSnapshot = properties;
|
|
@@ -1197,16 +987,18 @@ const SnapshotPlugin = (chai, utils) => {
|
|
|
1197
987
|
}
|
|
1198
988
|
if (inlineSnapshot)
|
|
1199
989
|
inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
|
|
1200
|
-
getSnapshotClient().assert(expected, message, true, properties, inlineSnapshot, error);
|
|
990
|
+
getSnapshotClient().assert(expected, test, message, true, properties, inlineSnapshot, error);
|
|
1201
991
|
});
|
|
1202
992
|
utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingSnapshot", function(message) {
|
|
1203
993
|
const expected = utils.flag(this, "object");
|
|
1204
|
-
|
|
994
|
+
const test = utils.flag(this, "vitest-test");
|
|
995
|
+
getSnapshotClient().assert(getErrorString(expected), test, message);
|
|
1205
996
|
});
|
|
1206
997
|
utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingInlineSnapshot", function __VITEST_INLINE_SNAPSHOT__(inlineSnapshot, message) {
|
|
1207
998
|
const expected = utils.flag(this, "object");
|
|
1208
999
|
const error = utils.flag(this, "error");
|
|
1209
|
-
|
|
1000
|
+
const test = utils.flag(this, "vitest-test");
|
|
1001
|
+
getSnapshotClient().assert(getErrorString(expected), test, message, true, void 0, inlineSnapshot, error);
|
|
1210
1002
|
});
|
|
1211
1003
|
};
|
|
1212
1004
|
|
|
@@ -1253,6 +1045,10 @@ const JestChaiExpect = (chai, utils) => {
|
|
|
1253
1045
|
};
|
|
1254
1046
|
});
|
|
1255
1047
|
});
|
|
1048
|
+
def("withTest", function(test) {
|
|
1049
|
+
utils.flag(this, "vitest-test", test);
|
|
1050
|
+
return this;
|
|
1051
|
+
});
|
|
1256
1052
|
def("toEqual", function(expected) {
|
|
1257
1053
|
const actual = utils.flag(this, "object");
|
|
1258
1054
|
const equal = equals(actual, expected, [iterableEquality]);
|
|
@@ -1392,11 +1188,11 @@ const JestChaiExpect = (chai, utils) => {
|
|
|
1392
1188
|
return `${i}th`;
|
|
1393
1189
|
};
|
|
1394
1190
|
const formatCalls = (spy, msg, actualCall) => {
|
|
1395
|
-
msg +=
|
|
1191
|
+
msg += picocolors.exports.gray(`
|
|
1396
1192
|
|
|
1397
1193
|
Received:
|
|
1398
1194
|
${spy.mock.calls.map((callArg, i) => {
|
|
1399
|
-
let methodCall =
|
|
1195
|
+
let methodCall = picocolors.exports.bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call:
|
|
1400
1196
|
|
|
1401
1197
|
`);
|
|
1402
1198
|
if (actualCall)
|
|
@@ -1406,9 +1202,9 @@ ${spy.mock.calls.map((callArg, i) => {
|
|
|
1406
1202
|
methodCall += "\n";
|
|
1407
1203
|
return methodCall;
|
|
1408
1204
|
}).join("\n")}`);
|
|
1409
|
-
msg +=
|
|
1205
|
+
msg += picocolors.exports.gray(`
|
|
1410
1206
|
|
|
1411
|
-
Number of calls: ${
|
|
1207
|
+
Number of calls: ${picocolors.exports.bold(spy.mock.calls.length)}
|
|
1412
1208
|
`);
|
|
1413
1209
|
return msg;
|
|
1414
1210
|
};
|
|
@@ -1840,90 +1636,341 @@ const getMatcherState = (assertion) => {
|
|
|
1840
1636
|
equals,
|
|
1841
1637
|
suppressedErrors: []
|
|
1842
1638
|
});
|
|
1843
|
-
return {
|
|
1844
|
-
state: matcherState,
|
|
1845
|
-
isNot,
|
|
1846
|
-
obj
|
|
1639
|
+
return {
|
|
1640
|
+
state: matcherState,
|
|
1641
|
+
isNot,
|
|
1642
|
+
obj
|
|
1643
|
+
};
|
|
1644
|
+
};
|
|
1645
|
+
class JestExtendError extends Error {
|
|
1646
|
+
constructor(message, actual, expected) {
|
|
1647
|
+
super(message);
|
|
1648
|
+
this.actual = actual;
|
|
1649
|
+
this.expected = expected;
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
function JestExtendPlugin(expect, matchers) {
|
|
1653
|
+
return (c, utils) => {
|
|
1654
|
+
Object.entries(matchers).forEach(([expectAssertionName, expectAssertion]) => {
|
|
1655
|
+
function expectSyncWrapper(...args) {
|
|
1656
|
+
const { state, isNot, obj } = getMatcherState(this);
|
|
1657
|
+
const { pass, message, actual, expected } = expectAssertion.call(state, obj, ...args);
|
|
1658
|
+
if (pass && isNot || !pass && !isNot)
|
|
1659
|
+
throw new JestExtendError(message(), actual, expected);
|
|
1660
|
+
}
|
|
1661
|
+
async function expectAsyncWrapper(...args) {
|
|
1662
|
+
const { state, isNot, obj } = getMatcherState(this);
|
|
1663
|
+
const { pass, message, actual, expected } = await expectAssertion.call(state, obj, ...args);
|
|
1664
|
+
if (pass && isNot || !pass && !isNot)
|
|
1665
|
+
throw new JestExtendError(message(), actual, expected);
|
|
1666
|
+
}
|
|
1667
|
+
const expectAssertionWrapper = isAsyncFunction(expectAssertion) ? expectAsyncWrapper : expectSyncWrapper;
|
|
1668
|
+
utils.addMethod(c.Assertion.prototype, expectAssertionName, expectAssertionWrapper);
|
|
1669
|
+
class CustomMatcher extends AsymmetricMatcher {
|
|
1670
|
+
constructor(inverse = false, ...sample) {
|
|
1671
|
+
super(sample, inverse);
|
|
1672
|
+
}
|
|
1673
|
+
asymmetricMatch(other) {
|
|
1674
|
+
const { pass } = expectAssertion.call(this.getMatcherContext(), other, ...this.sample);
|
|
1675
|
+
return this.inverse ? !pass : pass;
|
|
1676
|
+
}
|
|
1677
|
+
toString() {
|
|
1678
|
+
return `${this.inverse ? "not." : ""}${expectAssertionName}`;
|
|
1679
|
+
}
|
|
1680
|
+
getExpectedType() {
|
|
1681
|
+
return "any";
|
|
1682
|
+
}
|
|
1683
|
+
toAsymmetricMatcher() {
|
|
1684
|
+
return `${this.toString()}<${this.sample.map(String).join(", ")}>`;
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
Object.defineProperty(expect, expectAssertionName, {
|
|
1688
|
+
configurable: true,
|
|
1689
|
+
enumerable: true,
|
|
1690
|
+
value: (...sample) => new CustomMatcher(false, ...sample),
|
|
1691
|
+
writable: true
|
|
1692
|
+
});
|
|
1693
|
+
Object.defineProperty(expect.not, expectAssertionName, {
|
|
1694
|
+
configurable: true,
|
|
1695
|
+
enumerable: true,
|
|
1696
|
+
value: (...sample) => new CustomMatcher(true, ...sample),
|
|
1697
|
+
writable: true
|
|
1698
|
+
});
|
|
1699
|
+
});
|
|
1700
|
+
};
|
|
1701
|
+
}
|
|
1702
|
+
const JestExtend = (chai, utils) => {
|
|
1703
|
+
utils.addMethod(chai.expect, "extend", (expect, expects) => {
|
|
1704
|
+
chai.use(JestExtendPlugin(expect, expects));
|
|
1705
|
+
});
|
|
1706
|
+
};
|
|
1707
|
+
|
|
1708
|
+
chai$1.use(JestExtend);
|
|
1709
|
+
chai$1.use(JestChaiExpect);
|
|
1710
|
+
chai$1.use(Subset);
|
|
1711
|
+
chai$1.use(SnapshotPlugin);
|
|
1712
|
+
chai$1.use(JestAsymmetricMatchers);
|
|
1713
|
+
|
|
1714
|
+
function createExpect(test) {
|
|
1715
|
+
const expect2 = (value, message) => {
|
|
1716
|
+
const { assertionCalls } = getState();
|
|
1717
|
+
setState({ assertionCalls: assertionCalls + 1 });
|
|
1718
|
+
const assert2 = chai$1.expect(value, message);
|
|
1719
|
+
if (test)
|
|
1720
|
+
return assert2.withTest(test);
|
|
1721
|
+
else
|
|
1722
|
+
return assert2;
|
|
1723
|
+
};
|
|
1724
|
+
Object.assign(expect2, chai$1.expect);
|
|
1725
|
+
expect2.getState = getState;
|
|
1726
|
+
expect2.setState = setState;
|
|
1727
|
+
expect2.extend = (matchers) => chai$1.expect.extend(expect2, matchers);
|
|
1728
|
+
return expect2;
|
|
1729
|
+
}
|
|
1730
|
+
const expect = createExpect();
|
|
1731
|
+
|
|
1732
|
+
const collectorContext = {
|
|
1733
|
+
tasks: [],
|
|
1734
|
+
currentSuite: null
|
|
1735
|
+
};
|
|
1736
|
+
function collectTask(task) {
|
|
1737
|
+
var _a;
|
|
1738
|
+
(_a = collectorContext.currentSuite) == null ? void 0 : _a.tasks.push(task);
|
|
1739
|
+
}
|
|
1740
|
+
async function runWithSuite(suite, fn) {
|
|
1741
|
+
const prev = collectorContext.currentSuite;
|
|
1742
|
+
collectorContext.currentSuite = suite;
|
|
1743
|
+
await fn();
|
|
1744
|
+
collectorContext.currentSuite = prev;
|
|
1745
|
+
}
|
|
1746
|
+
function getDefaultTestTimeout() {
|
|
1747
|
+
return getWorkerState().config.testTimeout;
|
|
1748
|
+
}
|
|
1749
|
+
function getDefaultHookTimeout() {
|
|
1750
|
+
return getWorkerState().config.hookTimeout;
|
|
1751
|
+
}
|
|
1752
|
+
function withTimeout(fn, timeout = getDefaultTestTimeout(), isHook = false) {
|
|
1753
|
+
if (timeout <= 0 || timeout === Infinity)
|
|
1754
|
+
return fn;
|
|
1755
|
+
return (...args) => {
|
|
1756
|
+
return Promise.race([fn(...args), new Promise((resolve, reject) => {
|
|
1757
|
+
const timer = setTimeout(() => {
|
|
1758
|
+
clearTimeout(timer);
|
|
1759
|
+
reject(new Error(makeTimeoutMsg(isHook, timeout)));
|
|
1760
|
+
}, timeout);
|
|
1761
|
+
timer.unref();
|
|
1762
|
+
})]);
|
|
1763
|
+
};
|
|
1764
|
+
}
|
|
1765
|
+
function createTestContext(test) {
|
|
1766
|
+
const context = function() {
|
|
1767
|
+
throw new Error("done() callback is deperated, use promise instead");
|
|
1768
|
+
};
|
|
1769
|
+
context.meta = test;
|
|
1770
|
+
let _expect;
|
|
1771
|
+
Object.defineProperty(context, "expect", {
|
|
1772
|
+
get() {
|
|
1773
|
+
if (!_expect)
|
|
1774
|
+
_expect = createExpect(test);
|
|
1775
|
+
return _expect;
|
|
1776
|
+
}
|
|
1777
|
+
});
|
|
1778
|
+
return context;
|
|
1779
|
+
}
|
|
1780
|
+
function makeTimeoutMsg(isHook, timeout) {
|
|
1781
|
+
return `${isHook ? "Hook" : "Test"} timed out in ${timeout}ms.
|
|
1782
|
+
If this is a long-running test, pass a timeout value as the last argument or configure it globally with "${isHook ? "hookTimeout" : "testTimeout"}".`;
|
|
1783
|
+
}
|
|
1784
|
+
|
|
1785
|
+
const fnMap = /* @__PURE__ */ new WeakMap();
|
|
1786
|
+
const hooksMap = /* @__PURE__ */ new WeakMap();
|
|
1787
|
+
function setFn(key, fn) {
|
|
1788
|
+
fnMap.set(key, fn);
|
|
1789
|
+
}
|
|
1790
|
+
function getFn(key) {
|
|
1791
|
+
return fnMap.get(key);
|
|
1792
|
+
}
|
|
1793
|
+
function setHooks(key, hooks) {
|
|
1794
|
+
hooksMap.set(key, hooks);
|
|
1795
|
+
}
|
|
1796
|
+
function getHooks(key) {
|
|
1797
|
+
return hooksMap.get(key);
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1800
|
+
const suite = createSuite();
|
|
1801
|
+
const test = createTest(function(name, fn, timeout) {
|
|
1802
|
+
getCurrentSuite().test.fn.call(this, name, fn, timeout);
|
|
1803
|
+
});
|
|
1804
|
+
function formatTitle(template, items, idx) {
|
|
1805
|
+
if (template.includes("%#")) {
|
|
1806
|
+
template = template.replace(/%%/g, "__vitest_escaped_%__").replace(/%#/g, `${idx}`).replace(/__vitest_escaped_%__/g, "%%");
|
|
1807
|
+
}
|
|
1808
|
+
const count = template.split("%").length - 1;
|
|
1809
|
+
let formatted = format(template, ...items.slice(0, count));
|
|
1810
|
+
if (isObject(items[0])) {
|
|
1811
|
+
formatted = formatted.replace(/\$([$\w_]+)/g, (_, key) => {
|
|
1812
|
+
return items[0][key];
|
|
1813
|
+
});
|
|
1814
|
+
}
|
|
1815
|
+
return formatted;
|
|
1816
|
+
}
|
|
1817
|
+
const describe = suite;
|
|
1818
|
+
const it = test;
|
|
1819
|
+
const defaultSuite = suite("");
|
|
1820
|
+
function clearCollectorContext() {
|
|
1821
|
+
collectorContext.tasks.length = 0;
|
|
1822
|
+
defaultSuite.clear();
|
|
1823
|
+
collectorContext.currentSuite = defaultSuite;
|
|
1824
|
+
}
|
|
1825
|
+
function getCurrentSuite() {
|
|
1826
|
+
return collectorContext.currentSuite || defaultSuite;
|
|
1827
|
+
}
|
|
1828
|
+
function createSuiteHooks() {
|
|
1829
|
+
return {
|
|
1830
|
+
beforeAll: [],
|
|
1831
|
+
afterAll: [],
|
|
1832
|
+
beforeEach: [],
|
|
1833
|
+
afterEach: []
|
|
1834
|
+
};
|
|
1835
|
+
}
|
|
1836
|
+
function createSuiteCollector(name, factory = () => {
|
|
1837
|
+
}, mode, concurrent) {
|
|
1838
|
+
const tasks = [];
|
|
1839
|
+
const factoryQueue = [];
|
|
1840
|
+
let suite2;
|
|
1841
|
+
initSuite();
|
|
1842
|
+
const test2 = createTest(function(name2, fn = noop, timeout) {
|
|
1843
|
+
const mode2 = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
|
|
1844
|
+
const test3 = {
|
|
1845
|
+
id: "",
|
|
1846
|
+
type: "test",
|
|
1847
|
+
name: name2,
|
|
1848
|
+
mode: mode2,
|
|
1849
|
+
suite: void 0,
|
|
1850
|
+
fails: this.fails
|
|
1851
|
+
};
|
|
1852
|
+
if (this.concurrent || concurrent)
|
|
1853
|
+
test3.concurrent = true;
|
|
1854
|
+
const context = createTestContext(test3);
|
|
1855
|
+
Object.defineProperty(test3, "context", {
|
|
1856
|
+
value: context,
|
|
1857
|
+
enumerable: false
|
|
1858
|
+
});
|
|
1859
|
+
setFn(test3, withTimeout(() => fn(context), timeout));
|
|
1860
|
+
tasks.push(test3);
|
|
1861
|
+
});
|
|
1862
|
+
const collector = {
|
|
1863
|
+
type: "collector",
|
|
1864
|
+
name,
|
|
1865
|
+
mode,
|
|
1866
|
+
test: test2,
|
|
1867
|
+
tasks,
|
|
1868
|
+
collect,
|
|
1869
|
+
clear,
|
|
1870
|
+
on: addHook
|
|
1847
1871
|
};
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1872
|
+
function addHook(name2, ...fn) {
|
|
1873
|
+
getHooks(suite2)[name2].push(...fn);
|
|
1874
|
+
}
|
|
1875
|
+
function initSuite() {
|
|
1876
|
+
suite2 = {
|
|
1877
|
+
id: "",
|
|
1878
|
+
type: "suite",
|
|
1879
|
+
name,
|
|
1880
|
+
mode,
|
|
1881
|
+
tasks: []
|
|
1882
|
+
};
|
|
1883
|
+
setHooks(suite2, createSuiteHooks());
|
|
1854
1884
|
}
|
|
1885
|
+
function clear() {
|
|
1886
|
+
tasks.length = 0;
|
|
1887
|
+
factoryQueue.length = 0;
|
|
1888
|
+
initSuite();
|
|
1889
|
+
}
|
|
1890
|
+
async function collect(file) {
|
|
1891
|
+
factoryQueue.length = 0;
|
|
1892
|
+
if (factory)
|
|
1893
|
+
await runWithSuite(collector, () => factory(test2));
|
|
1894
|
+
const allChildren = [];
|
|
1895
|
+
for (const i of [...factoryQueue, ...tasks])
|
|
1896
|
+
allChildren.push(i.type === "collector" ? await i.collect(file) : i);
|
|
1897
|
+
suite2.file = file;
|
|
1898
|
+
suite2.tasks = allChildren;
|
|
1899
|
+
allChildren.forEach((task) => {
|
|
1900
|
+
task.suite = suite2;
|
|
1901
|
+
if (file)
|
|
1902
|
+
task.file = file;
|
|
1903
|
+
});
|
|
1904
|
+
return suite2;
|
|
1905
|
+
}
|
|
1906
|
+
collectTask(collector);
|
|
1907
|
+
return collector;
|
|
1855
1908
|
}
|
|
1856
|
-
function
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
const { state, isNot, obj } = getMatcherState(this);
|
|
1867
|
-
const { pass, message, actual, expected } = await expectAssertion.call(state, obj, ...args);
|
|
1868
|
-
if (pass && isNot || !pass && !isNot)
|
|
1869
|
-
throw new JestExtendError(message(), actual, expected);
|
|
1870
|
-
}
|
|
1871
|
-
const expectAssertionWrapper = isAsyncFunction(expectAssertion) ? expectAsyncWrapper : expectSyncWrapper;
|
|
1872
|
-
utils.addMethod(c.Assertion.prototype, expectAssertionName, expectAssertionWrapper);
|
|
1873
|
-
class CustomMatcher extends AsymmetricMatcher {
|
|
1874
|
-
constructor(inverse = false, ...sample) {
|
|
1875
|
-
super(sample, inverse);
|
|
1876
|
-
}
|
|
1877
|
-
asymmetricMatch(other) {
|
|
1878
|
-
const { pass } = expectAssertion.call(this.getMatcherContext(), other, ...this.sample);
|
|
1879
|
-
return this.inverse ? !pass : pass;
|
|
1880
|
-
}
|
|
1881
|
-
toString() {
|
|
1882
|
-
return `${this.inverse ? "not." : ""}${expectAssertionName}`;
|
|
1883
|
-
}
|
|
1884
|
-
getExpectedType() {
|
|
1885
|
-
return "any";
|
|
1886
|
-
}
|
|
1887
|
-
toAsymmetricMatcher() {
|
|
1888
|
-
return `${this.toString()}<${this.sample.map(String).join(", ")}>`;
|
|
1889
|
-
}
|
|
1890
|
-
}
|
|
1891
|
-
Object.defineProperty(expect, expectAssertionName, {
|
|
1892
|
-
configurable: true,
|
|
1893
|
-
enumerable: true,
|
|
1894
|
-
value: (...sample) => new CustomMatcher(false, ...sample),
|
|
1895
|
-
writable: true
|
|
1909
|
+
function createSuite() {
|
|
1910
|
+
const suite2 = createChainable(["concurrent", "skip", "only", "todo"], function(name, factory) {
|
|
1911
|
+
const mode = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
|
|
1912
|
+
return createSuiteCollector(name, factory, mode, this.concurrent);
|
|
1913
|
+
});
|
|
1914
|
+
suite2.each = (cases) => {
|
|
1915
|
+
return (name, fn) => {
|
|
1916
|
+
cases.forEach((i, idx) => {
|
|
1917
|
+
const items = toArray(i);
|
|
1918
|
+
suite2(formatTitle(name, items, idx), () => fn(...items));
|
|
1896
1919
|
});
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1920
|
+
};
|
|
1921
|
+
};
|
|
1922
|
+
return suite2;
|
|
1923
|
+
}
|
|
1924
|
+
function createTest(fn) {
|
|
1925
|
+
const test2 = createChainable(["concurrent", "skip", "only", "todo", "fails"], fn);
|
|
1926
|
+
test2.each = (cases) => {
|
|
1927
|
+
return (name, fn2) => {
|
|
1928
|
+
cases.forEach((i, idx) => {
|
|
1929
|
+
const items = toArray(i);
|
|
1930
|
+
test2(formatTitle(name, items, idx), () => fn2(...items));
|
|
1902
1931
|
});
|
|
1903
|
-
}
|
|
1932
|
+
};
|
|
1904
1933
|
};
|
|
1934
|
+
return test2;
|
|
1905
1935
|
}
|
|
1906
|
-
const JestExtend = (chai, utils) => {
|
|
1907
|
-
utils.addMethod(chai.expect, "extend", (expect, expects) => {
|
|
1908
|
-
chai.use(JestExtendPlugin(expect, expects));
|
|
1909
|
-
});
|
|
1910
|
-
};
|
|
1911
1936
|
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
chai$1.use(JestAsymmetricMatchers);
|
|
1937
|
+
const beforeAll = (fn, timeout) => getCurrentSuite().on("beforeAll", withTimeout(fn, timeout ?? getDefaultHookTimeout(), true));
|
|
1938
|
+
const afterAll = (fn, timeout) => getCurrentSuite().on("afterAll", withTimeout(fn, timeout ?? getDefaultHookTimeout(), true));
|
|
1939
|
+
const beforeEach = (fn, timeout) => getCurrentSuite().on("beforeEach", withTimeout(fn, timeout ?? getDefaultHookTimeout(), true));
|
|
1940
|
+
const afterEach = (fn, timeout) => getCurrentSuite().on("afterEach", withTimeout(fn, timeout ?? getDefaultHookTimeout(), true));
|
|
1917
1941
|
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1942
|
+
function withCallback(fn) {
|
|
1943
|
+
return new Promise((resolve, reject) => fn((err) => {
|
|
1944
|
+
if (err)
|
|
1945
|
+
reject(err);
|
|
1946
|
+
else
|
|
1947
|
+
resolve();
|
|
1948
|
+
}));
|
|
1949
|
+
}
|
|
1950
|
+
|
|
1951
|
+
const filesCount = /* @__PURE__ */ new Map();
|
|
1952
|
+
const cache = /* @__PURE__ */ new Map();
|
|
1953
|
+
function runOnce(fn, key) {
|
|
1954
|
+
const filepath = getWorkerState().filepath || "__unknown_files__";
|
|
1955
|
+
if (!key) {
|
|
1956
|
+
filesCount.set(filepath, (filesCount.get(filepath) || 0) + 1);
|
|
1957
|
+
key = String(filesCount.get(filepath));
|
|
1958
|
+
}
|
|
1959
|
+
const id = `${filepath}:${key}`;
|
|
1960
|
+
if (!cache.has(id))
|
|
1961
|
+
cache.set(id, fn());
|
|
1962
|
+
return cache.get(id);
|
|
1963
|
+
}
|
|
1964
|
+
function isFirstRun() {
|
|
1965
|
+
let firstRun = false;
|
|
1966
|
+
runOnce(() => {
|
|
1967
|
+
firstRun = true;
|
|
1968
|
+
}, "__vitest_first_run__");
|
|
1969
|
+
return firstRun;
|
|
1970
|
+
}
|
|
1971
|
+
function resetRunOnceCounter() {
|
|
1972
|
+
filesCount.clear();
|
|
1973
|
+
}
|
|
1927
1974
|
|
|
1928
1975
|
/**
|
|
1929
1976
|
* A reference to the global object
|
|
@@ -2086,62 +2133,62 @@ var deprecated = {};
|
|
|
2086
2133
|
|
|
2087
2134
|
(function (exports) {
|
|
2088
2135
|
|
|
2089
|
-
/**
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
exports.wrap = function(func, msg) {
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
};
|
|
2107
|
-
|
|
2108
|
-
/**
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
exports.defaultMsg = function(packageName, funcName) {
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
};
|
|
2126
|
-
|
|
2127
|
-
/**
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
exports.printWarning = function(msg) {
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
};
|
|
2144
|
-
}(deprecated));
|
|
2136
|
+
/**
|
|
2137
|
+
* Returns a function that will invoke the supplied function and print a
|
|
2138
|
+
* deprecation warning to the console each time it is called.
|
|
2139
|
+
*
|
|
2140
|
+
* @param {Function} func
|
|
2141
|
+
* @param {string} msg
|
|
2142
|
+
* @returns {Function}
|
|
2143
|
+
*/
|
|
2144
|
+
exports.wrap = function(func, msg) {
|
|
2145
|
+
var wrapped = function() {
|
|
2146
|
+
exports.printWarning(msg);
|
|
2147
|
+
return func.apply(this, arguments);
|
|
2148
|
+
};
|
|
2149
|
+
if (func.prototype) {
|
|
2150
|
+
wrapped.prototype = func.prototype;
|
|
2151
|
+
}
|
|
2152
|
+
return wrapped;
|
|
2153
|
+
};
|
|
2154
|
+
|
|
2155
|
+
/**
|
|
2156
|
+
* Returns a string which can be supplied to `wrap()` to notify the user that a
|
|
2157
|
+
* particular part of the sinon API has been deprecated.
|
|
2158
|
+
*
|
|
2159
|
+
* @param {string} packageName
|
|
2160
|
+
* @param {string} funcName
|
|
2161
|
+
* @returns {string}
|
|
2162
|
+
*/
|
|
2163
|
+
exports.defaultMsg = function(packageName, funcName) {
|
|
2164
|
+
return (
|
|
2165
|
+
packageName +
|
|
2166
|
+
"." +
|
|
2167
|
+
funcName +
|
|
2168
|
+
" is deprecated and will be removed from the public API in a future version of " +
|
|
2169
|
+
packageName +
|
|
2170
|
+
"."
|
|
2171
|
+
);
|
|
2172
|
+
};
|
|
2173
|
+
|
|
2174
|
+
/**
|
|
2175
|
+
* Prints a warning on the console, when it exists
|
|
2176
|
+
*
|
|
2177
|
+
* @param {string} msg
|
|
2178
|
+
* @returns {undefined}
|
|
2179
|
+
*/
|
|
2180
|
+
exports.printWarning = function(msg) {
|
|
2181
|
+
/* istanbul ignore next */
|
|
2182
|
+
if (typeof process === "object" && process.emitWarning) {
|
|
2183
|
+
// Emit Warnings in Node
|
|
2184
|
+
process.emitWarning(msg);
|
|
2185
|
+
} else if (console.info) {
|
|
2186
|
+
console.info(msg);
|
|
2187
|
+
} else {
|
|
2188
|
+
console.log(msg);
|
|
2189
|
+
}
|
|
2190
|
+
};
|
|
2191
|
+
} (deprecated));
|
|
2145
2192
|
|
|
2146
2193
|
/**
|
|
2147
2194
|
* Returns true when fn returns true for all members of obj.
|
|
@@ -2236,392 +2283,392 @@ var prototypes = {
|
|
|
2236
2283
|
var typeDetect = {exports: {}};
|
|
2237
2284
|
|
|
2238
2285
|
(function (module, exports) {
|
|
2239
|
-
(function (global, factory) {
|
|
2240
|
-
|
|
2241
|
-
}(commonjsGlobal, (function () {
|
|
2242
|
-
/* !
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
var promiseExists = typeof Promise === 'function';
|
|
2248
|
-
|
|
2249
|
-
/* eslint-disable no-undef */
|
|
2250
|
-
var globalObject = typeof self === 'object' ? self : commonjsGlobal; // eslint-disable-line id-blacklist
|
|
2251
|
-
|
|
2252
|
-
var symbolExists = typeof Symbol !== 'undefined';
|
|
2253
|
-
var mapExists = typeof Map !== 'undefined';
|
|
2254
|
-
var setExists = typeof Set !== 'undefined';
|
|
2255
|
-
var weakMapExists = typeof WeakMap !== 'undefined';
|
|
2256
|
-
var weakSetExists = typeof WeakSet !== 'undefined';
|
|
2257
|
-
var dataViewExists = typeof DataView !== 'undefined';
|
|
2258
|
-
var symbolIteratorExists = symbolExists && typeof Symbol.iterator !== 'undefined';
|
|
2259
|
-
var symbolToStringTagExists = symbolExists && typeof Symbol.toStringTag !== 'undefined';
|
|
2260
|
-
var setEntriesExists = setExists && typeof Set.prototype.entries === 'function';
|
|
2261
|
-
var mapEntriesExists = mapExists && typeof Map.prototype.entries === 'function';
|
|
2262
|
-
var setIteratorPrototype = setEntriesExists && Object.getPrototypeOf(new Set().entries());
|
|
2263
|
-
var mapIteratorPrototype = mapEntriesExists && Object.getPrototypeOf(new Map().entries());
|
|
2264
|
-
var arrayIteratorExists = symbolIteratorExists && typeof Array.prototype[Symbol.iterator] === 'function';
|
|
2265
|
-
var arrayIteratorPrototype = arrayIteratorExists && Object.getPrototypeOf([][Symbol.iterator]());
|
|
2266
|
-
var stringIteratorExists = symbolIteratorExists && typeof String.prototype[Symbol.iterator] === 'function';
|
|
2267
|
-
var stringIteratorPrototype = stringIteratorExists && Object.getPrototypeOf(''[Symbol.iterator]());
|
|
2268
|
-
var toStringLeftSliceLength = 8;
|
|
2269
|
-
var toStringRightSliceLength = -1;
|
|
2270
|
-
/**
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
function typeDetect(obj) {
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
}
|
|
2286
|
+
(function (global, factory) {
|
|
2287
|
+
module.exports = factory() ;
|
|
2288
|
+
}(commonjsGlobal, (function () {
|
|
2289
|
+
/* !
|
|
2290
|
+
* type-detect
|
|
2291
|
+
* Copyright(c) 2013 jake luer <jake@alogicalparadox.com>
|
|
2292
|
+
* MIT Licensed
|
|
2293
|
+
*/
|
|
2294
|
+
var promiseExists = typeof Promise === 'function';
|
|
2295
|
+
|
|
2296
|
+
/* eslint-disable no-undef */
|
|
2297
|
+
var globalObject = typeof self === 'object' ? self : commonjsGlobal; // eslint-disable-line id-blacklist
|
|
2298
|
+
|
|
2299
|
+
var symbolExists = typeof Symbol !== 'undefined';
|
|
2300
|
+
var mapExists = typeof Map !== 'undefined';
|
|
2301
|
+
var setExists = typeof Set !== 'undefined';
|
|
2302
|
+
var weakMapExists = typeof WeakMap !== 'undefined';
|
|
2303
|
+
var weakSetExists = typeof WeakSet !== 'undefined';
|
|
2304
|
+
var dataViewExists = typeof DataView !== 'undefined';
|
|
2305
|
+
var symbolIteratorExists = symbolExists && typeof Symbol.iterator !== 'undefined';
|
|
2306
|
+
var symbolToStringTagExists = symbolExists && typeof Symbol.toStringTag !== 'undefined';
|
|
2307
|
+
var setEntriesExists = setExists && typeof Set.prototype.entries === 'function';
|
|
2308
|
+
var mapEntriesExists = mapExists && typeof Map.prototype.entries === 'function';
|
|
2309
|
+
var setIteratorPrototype = setEntriesExists && Object.getPrototypeOf(new Set().entries());
|
|
2310
|
+
var mapIteratorPrototype = mapEntriesExists && Object.getPrototypeOf(new Map().entries());
|
|
2311
|
+
var arrayIteratorExists = symbolIteratorExists && typeof Array.prototype[Symbol.iterator] === 'function';
|
|
2312
|
+
var arrayIteratorPrototype = arrayIteratorExists && Object.getPrototypeOf([][Symbol.iterator]());
|
|
2313
|
+
var stringIteratorExists = symbolIteratorExists && typeof String.prototype[Symbol.iterator] === 'function';
|
|
2314
|
+
var stringIteratorPrototype = stringIteratorExists && Object.getPrototypeOf(''[Symbol.iterator]());
|
|
2315
|
+
var toStringLeftSliceLength = 8;
|
|
2316
|
+
var toStringRightSliceLength = -1;
|
|
2317
|
+
/**
|
|
2318
|
+
* ### typeOf (obj)
|
|
2319
|
+
*
|
|
2320
|
+
* Uses `Object.prototype.toString` to determine the type of an object,
|
|
2321
|
+
* normalising behaviour across engine versions & well optimised.
|
|
2322
|
+
*
|
|
2323
|
+
* @param {Mixed} object
|
|
2324
|
+
* @return {String} object type
|
|
2325
|
+
* @api public
|
|
2326
|
+
*/
|
|
2327
|
+
function typeDetect(obj) {
|
|
2328
|
+
/* ! Speed optimisation
|
|
2329
|
+
* Pre:
|
|
2330
|
+
* string literal x 3,039,035 ops/sec ±1.62% (78 runs sampled)
|
|
2331
|
+
* boolean literal x 1,424,138 ops/sec ±4.54% (75 runs sampled)
|
|
2332
|
+
* number literal x 1,653,153 ops/sec ±1.91% (82 runs sampled)
|
|
2333
|
+
* undefined x 9,978,660 ops/sec ±1.92% (75 runs sampled)
|
|
2334
|
+
* function x 2,556,769 ops/sec ±1.73% (77 runs sampled)
|
|
2335
|
+
* Post:
|
|
2336
|
+
* string literal x 38,564,796 ops/sec ±1.15% (79 runs sampled)
|
|
2337
|
+
* boolean literal x 31,148,940 ops/sec ±1.10% (79 runs sampled)
|
|
2338
|
+
* number literal x 32,679,330 ops/sec ±1.90% (78 runs sampled)
|
|
2339
|
+
* undefined x 32,363,368 ops/sec ±1.07% (82 runs sampled)
|
|
2340
|
+
* function x 31,296,870 ops/sec ±0.96% (83 runs sampled)
|
|
2341
|
+
*/
|
|
2342
|
+
var typeofObj = typeof obj;
|
|
2343
|
+
if (typeofObj !== 'object') {
|
|
2344
|
+
return typeofObj;
|
|
2345
|
+
}
|
|
2346
|
+
|
|
2347
|
+
/* ! Speed optimisation
|
|
2348
|
+
* Pre:
|
|
2349
|
+
* null x 28,645,765 ops/sec ±1.17% (82 runs sampled)
|
|
2350
|
+
* Post:
|
|
2351
|
+
* null x 36,428,962 ops/sec ±1.37% (84 runs sampled)
|
|
2352
|
+
*/
|
|
2353
|
+
if (obj === null) {
|
|
2354
|
+
return 'null';
|
|
2355
|
+
}
|
|
2356
|
+
|
|
2357
|
+
/* ! Spec Conformance
|
|
2358
|
+
* Test: `Object.prototype.toString.call(window)``
|
|
2359
|
+
* - Node === "[object global]"
|
|
2360
|
+
* - Chrome === "[object global]"
|
|
2361
|
+
* - Firefox === "[object Window]"
|
|
2362
|
+
* - PhantomJS === "[object Window]"
|
|
2363
|
+
* - Safari === "[object Window]"
|
|
2364
|
+
* - IE 11 === "[object Window]"
|
|
2365
|
+
* - IE Edge === "[object Window]"
|
|
2366
|
+
* Test: `Object.prototype.toString.call(this)``
|
|
2367
|
+
* - Chrome Worker === "[object global]"
|
|
2368
|
+
* - Firefox Worker === "[object DedicatedWorkerGlobalScope]"
|
|
2369
|
+
* - Safari Worker === "[object DedicatedWorkerGlobalScope]"
|
|
2370
|
+
* - IE 11 Worker === "[object WorkerGlobalScope]"
|
|
2371
|
+
* - IE Edge Worker === "[object WorkerGlobalScope]"
|
|
2372
|
+
*/
|
|
2373
|
+
if (obj === globalObject) {
|
|
2374
|
+
return 'global';
|
|
2375
|
+
}
|
|
2376
|
+
|
|
2377
|
+
/* ! Speed optimisation
|
|
2378
|
+
* Pre:
|
|
2379
|
+
* array literal x 2,888,352 ops/sec ±0.67% (82 runs sampled)
|
|
2380
|
+
* Post:
|
|
2381
|
+
* array literal x 22,479,650 ops/sec ±0.96% (81 runs sampled)
|
|
2382
|
+
*/
|
|
2383
|
+
if (
|
|
2384
|
+
Array.isArray(obj) &&
|
|
2385
|
+
(symbolToStringTagExists === false || !(Symbol.toStringTag in obj))
|
|
2386
|
+
) {
|
|
2387
|
+
return 'Array';
|
|
2388
|
+
}
|
|
2389
|
+
|
|
2390
|
+
// Not caching existence of `window` and related properties due to potential
|
|
2391
|
+
// for `window` to be unset before tests in quasi-browser environments.
|
|
2392
|
+
if (typeof window === 'object' && window !== null) {
|
|
2393
|
+
/* ! Spec Conformance
|
|
2394
|
+
* (https://html.spec.whatwg.org/multipage/browsers.html#location)
|
|
2395
|
+
* WhatWG HTML$7.7.3 - The `Location` interface
|
|
2396
|
+
* Test: `Object.prototype.toString.call(window.location)``
|
|
2397
|
+
* - IE <=11 === "[object Object]"
|
|
2398
|
+
* - IE Edge <=13 === "[object Object]"
|
|
2399
|
+
*/
|
|
2400
|
+
if (typeof window.location === 'object' && obj === window.location) {
|
|
2401
|
+
return 'Location';
|
|
2402
|
+
}
|
|
2403
|
+
|
|
2404
|
+
/* ! Spec Conformance
|
|
2405
|
+
* (https://html.spec.whatwg.org/#document)
|
|
2406
|
+
* WhatWG HTML$3.1.1 - The `Document` object
|
|
2407
|
+
* Note: Most browsers currently adher to the W3C DOM Level 2 spec
|
|
2408
|
+
* (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-26809268)
|
|
2409
|
+
* which suggests that browsers should use HTMLTableCellElement for
|
|
2410
|
+
* both TD and TH elements. WhatWG separates these.
|
|
2411
|
+
* WhatWG HTML states:
|
|
2412
|
+
* > For historical reasons, Window objects must also have a
|
|
2413
|
+
* > writable, configurable, non-enumerable property named
|
|
2414
|
+
* > HTMLDocument whose value is the Document interface object.
|
|
2415
|
+
* Test: `Object.prototype.toString.call(document)``
|
|
2416
|
+
* - Chrome === "[object HTMLDocument]"
|
|
2417
|
+
* - Firefox === "[object HTMLDocument]"
|
|
2418
|
+
* - Safari === "[object HTMLDocument]"
|
|
2419
|
+
* - IE <=10 === "[object Document]"
|
|
2420
|
+
* - IE 11 === "[object HTMLDocument]"
|
|
2421
|
+
* - IE Edge <=13 === "[object HTMLDocument]"
|
|
2422
|
+
*/
|
|
2423
|
+
if (typeof window.document === 'object' && obj === window.document) {
|
|
2424
|
+
return 'Document';
|
|
2425
|
+
}
|
|
2426
|
+
|
|
2427
|
+
if (typeof window.navigator === 'object') {
|
|
2428
|
+
/* ! Spec Conformance
|
|
2429
|
+
* (https://html.spec.whatwg.org/multipage/webappapis.html#mimetypearray)
|
|
2430
|
+
* WhatWG HTML$8.6.1.5 - Plugins - Interface MimeTypeArray
|
|
2431
|
+
* Test: `Object.prototype.toString.call(navigator.mimeTypes)``
|
|
2432
|
+
* - IE <=10 === "[object MSMimeTypesCollection]"
|
|
2433
|
+
*/
|
|
2434
|
+
if (typeof window.navigator.mimeTypes === 'object' &&
|
|
2435
|
+
obj === window.navigator.mimeTypes) {
|
|
2436
|
+
return 'MimeTypeArray';
|
|
2437
|
+
}
|
|
2438
|
+
|
|
2439
|
+
/* ! Spec Conformance
|
|
2440
|
+
* (https://html.spec.whatwg.org/multipage/webappapis.html#pluginarray)
|
|
2441
|
+
* WhatWG HTML$8.6.1.5 - Plugins - Interface PluginArray
|
|
2442
|
+
* Test: `Object.prototype.toString.call(navigator.plugins)``
|
|
2443
|
+
* - IE <=10 === "[object MSPluginsCollection]"
|
|
2444
|
+
*/
|
|
2445
|
+
if (typeof window.navigator.plugins === 'object' &&
|
|
2446
|
+
obj === window.navigator.plugins) {
|
|
2447
|
+
return 'PluginArray';
|
|
2448
|
+
}
|
|
2449
|
+
}
|
|
2450
|
+
|
|
2451
|
+
if ((typeof window.HTMLElement === 'function' ||
|
|
2452
|
+
typeof window.HTMLElement === 'object') &&
|
|
2453
|
+
obj instanceof window.HTMLElement) {
|
|
2454
|
+
/* ! Spec Conformance
|
|
2455
|
+
* (https://html.spec.whatwg.org/multipage/webappapis.html#pluginarray)
|
|
2456
|
+
* WhatWG HTML$4.4.4 - The `blockquote` element - Interface `HTMLQuoteElement`
|
|
2457
|
+
* Test: `Object.prototype.toString.call(document.createElement('blockquote'))``
|
|
2458
|
+
* - IE <=10 === "[object HTMLBlockElement]"
|
|
2459
|
+
*/
|
|
2460
|
+
if (obj.tagName === 'BLOCKQUOTE') {
|
|
2461
|
+
return 'HTMLQuoteElement';
|
|
2462
|
+
}
|
|
2463
|
+
|
|
2464
|
+
/* ! Spec Conformance
|
|
2465
|
+
* (https://html.spec.whatwg.org/#htmltabledatacellelement)
|
|
2466
|
+
* WhatWG HTML$4.9.9 - The `td` element - Interface `HTMLTableDataCellElement`
|
|
2467
|
+
* Note: Most browsers currently adher to the W3C DOM Level 2 spec
|
|
2468
|
+
* (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-82915075)
|
|
2469
|
+
* which suggests that browsers should use HTMLTableCellElement for
|
|
2470
|
+
* both TD and TH elements. WhatWG separates these.
|
|
2471
|
+
* Test: Object.prototype.toString.call(document.createElement('td'))
|
|
2472
|
+
* - Chrome === "[object HTMLTableCellElement]"
|
|
2473
|
+
* - Firefox === "[object HTMLTableCellElement]"
|
|
2474
|
+
* - Safari === "[object HTMLTableCellElement]"
|
|
2475
|
+
*/
|
|
2476
|
+
if (obj.tagName === 'TD') {
|
|
2477
|
+
return 'HTMLTableDataCellElement';
|
|
2478
|
+
}
|
|
2479
|
+
|
|
2480
|
+
/* ! Spec Conformance
|
|
2481
|
+
* (https://html.spec.whatwg.org/#htmltableheadercellelement)
|
|
2482
|
+
* WhatWG HTML$4.9.9 - The `td` element - Interface `HTMLTableHeaderCellElement`
|
|
2483
|
+
* Note: Most browsers currently adher to the W3C DOM Level 2 spec
|
|
2484
|
+
* (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-82915075)
|
|
2485
|
+
* which suggests that browsers should use HTMLTableCellElement for
|
|
2486
|
+
* both TD and TH elements. WhatWG separates these.
|
|
2487
|
+
* Test: Object.prototype.toString.call(document.createElement('th'))
|
|
2488
|
+
* - Chrome === "[object HTMLTableCellElement]"
|
|
2489
|
+
* - Firefox === "[object HTMLTableCellElement]"
|
|
2490
|
+
* - Safari === "[object HTMLTableCellElement]"
|
|
2491
|
+
*/
|
|
2492
|
+
if (obj.tagName === 'TH') {
|
|
2493
|
+
return 'HTMLTableHeaderCellElement';
|
|
2494
|
+
}
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
|
|
2498
|
+
/* ! Speed optimisation
|
|
2499
|
+
* Pre:
|
|
2500
|
+
* Float64Array x 625,644 ops/sec ±1.58% (80 runs sampled)
|
|
2501
|
+
* Float32Array x 1,279,852 ops/sec ±2.91% (77 runs sampled)
|
|
2502
|
+
* Uint32Array x 1,178,185 ops/sec ±1.95% (83 runs sampled)
|
|
2503
|
+
* Uint16Array x 1,008,380 ops/sec ±2.25% (80 runs sampled)
|
|
2504
|
+
* Uint8Array x 1,128,040 ops/sec ±2.11% (81 runs sampled)
|
|
2505
|
+
* Int32Array x 1,170,119 ops/sec ±2.88% (80 runs sampled)
|
|
2506
|
+
* Int16Array x 1,176,348 ops/sec ±5.79% (86 runs sampled)
|
|
2507
|
+
* Int8Array x 1,058,707 ops/sec ±4.94% (77 runs sampled)
|
|
2508
|
+
* Uint8ClampedArray x 1,110,633 ops/sec ±4.20% (80 runs sampled)
|
|
2509
|
+
* Post:
|
|
2510
|
+
* Float64Array x 7,105,671 ops/sec ±13.47% (64 runs sampled)
|
|
2511
|
+
* Float32Array x 5,887,912 ops/sec ±1.46% (82 runs sampled)
|
|
2512
|
+
* Uint32Array x 6,491,661 ops/sec ±1.76% (79 runs sampled)
|
|
2513
|
+
* Uint16Array x 6,559,795 ops/sec ±1.67% (82 runs sampled)
|
|
2514
|
+
* Uint8Array x 6,463,966 ops/sec ±1.43% (85 runs sampled)
|
|
2515
|
+
* Int32Array x 5,641,841 ops/sec ±3.49% (81 runs sampled)
|
|
2516
|
+
* Int16Array x 6,583,511 ops/sec ±1.98% (80 runs sampled)
|
|
2517
|
+
* Int8Array x 6,606,078 ops/sec ±1.74% (81 runs sampled)
|
|
2518
|
+
* Uint8ClampedArray x 6,602,224 ops/sec ±1.77% (83 runs sampled)
|
|
2519
|
+
*/
|
|
2520
|
+
var stringTag = (symbolToStringTagExists && obj[Symbol.toStringTag]);
|
|
2521
|
+
if (typeof stringTag === 'string') {
|
|
2522
|
+
return stringTag;
|
|
2523
|
+
}
|
|
2524
|
+
|
|
2525
|
+
var objPrototype = Object.getPrototypeOf(obj);
|
|
2526
|
+
/* ! Speed optimisation
|
|
2527
|
+
* Pre:
|
|
2528
|
+
* regex literal x 1,772,385 ops/sec ±1.85% (77 runs sampled)
|
|
2529
|
+
* regex constructor x 2,143,634 ops/sec ±2.46% (78 runs sampled)
|
|
2530
|
+
* Post:
|
|
2531
|
+
* regex literal x 3,928,009 ops/sec ±0.65% (78 runs sampled)
|
|
2532
|
+
* regex constructor x 3,931,108 ops/sec ±0.58% (84 runs sampled)
|
|
2533
|
+
*/
|
|
2534
|
+
if (objPrototype === RegExp.prototype) {
|
|
2535
|
+
return 'RegExp';
|
|
2536
|
+
}
|
|
2537
|
+
|
|
2538
|
+
/* ! Speed optimisation
|
|
2539
|
+
* Pre:
|
|
2540
|
+
* date x 2,130,074 ops/sec ±4.42% (68 runs sampled)
|
|
2541
|
+
* Post:
|
|
2542
|
+
* date x 3,953,779 ops/sec ±1.35% (77 runs sampled)
|
|
2543
|
+
*/
|
|
2544
|
+
if (objPrototype === Date.prototype) {
|
|
2545
|
+
return 'Date';
|
|
2546
|
+
}
|
|
2547
|
+
|
|
2548
|
+
/* ! Spec Conformance
|
|
2549
|
+
* (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-promise.prototype-@@tostringtag)
|
|
2550
|
+
* ES6$25.4.5.4 - Promise.prototype[@@toStringTag] should be "Promise":
|
|
2551
|
+
* Test: `Object.prototype.toString.call(Promise.resolve())``
|
|
2552
|
+
* - Chrome <=47 === "[object Object]"
|
|
2553
|
+
* - Edge <=20 === "[object Object]"
|
|
2554
|
+
* - Firefox 29-Latest === "[object Promise]"
|
|
2555
|
+
* - Safari 7.1-Latest === "[object Promise]"
|
|
2556
|
+
*/
|
|
2557
|
+
if (promiseExists && objPrototype === Promise.prototype) {
|
|
2558
|
+
return 'Promise';
|
|
2559
|
+
}
|
|
2560
|
+
|
|
2561
|
+
/* ! Speed optimisation
|
|
2562
|
+
* Pre:
|
|
2563
|
+
* set x 2,222,186 ops/sec ±1.31% (82 runs sampled)
|
|
2564
|
+
* Post:
|
|
2565
|
+
* set x 4,545,879 ops/sec ±1.13% (83 runs sampled)
|
|
2566
|
+
*/
|
|
2567
|
+
if (setExists && objPrototype === Set.prototype) {
|
|
2568
|
+
return 'Set';
|
|
2569
|
+
}
|
|
2570
|
+
|
|
2571
|
+
/* ! Speed optimisation
|
|
2572
|
+
* Pre:
|
|
2573
|
+
* map x 2,396,842 ops/sec ±1.59% (81 runs sampled)
|
|
2574
|
+
* Post:
|
|
2575
|
+
* map x 4,183,945 ops/sec ±6.59% (82 runs sampled)
|
|
2576
|
+
*/
|
|
2577
|
+
if (mapExists && objPrototype === Map.prototype) {
|
|
2578
|
+
return 'Map';
|
|
2579
|
+
}
|
|
2580
|
+
|
|
2581
|
+
/* ! Speed optimisation
|
|
2582
|
+
* Pre:
|
|
2583
|
+
* weakset x 1,323,220 ops/sec ±2.17% (76 runs sampled)
|
|
2584
|
+
* Post:
|
|
2585
|
+
* weakset x 4,237,510 ops/sec ±2.01% (77 runs sampled)
|
|
2586
|
+
*/
|
|
2587
|
+
if (weakSetExists && objPrototype === WeakSet.prototype) {
|
|
2588
|
+
return 'WeakSet';
|
|
2589
|
+
}
|
|
2590
|
+
|
|
2591
|
+
/* ! Speed optimisation
|
|
2592
|
+
* Pre:
|
|
2593
|
+
* weakmap x 1,500,260 ops/sec ±2.02% (78 runs sampled)
|
|
2594
|
+
* Post:
|
|
2595
|
+
* weakmap x 3,881,384 ops/sec ±1.45% (82 runs sampled)
|
|
2596
|
+
*/
|
|
2597
|
+
if (weakMapExists && objPrototype === WeakMap.prototype) {
|
|
2598
|
+
return 'WeakMap';
|
|
2599
|
+
}
|
|
2600
|
+
|
|
2601
|
+
/* ! Spec Conformance
|
|
2602
|
+
* (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-dataview.prototype-@@tostringtag)
|
|
2603
|
+
* ES6$24.2.4.21 - DataView.prototype[@@toStringTag] should be "DataView":
|
|
2604
|
+
* Test: `Object.prototype.toString.call(new DataView(new ArrayBuffer(1)))``
|
|
2605
|
+
* - Edge <=13 === "[object Object]"
|
|
2606
|
+
*/
|
|
2607
|
+
if (dataViewExists && objPrototype === DataView.prototype) {
|
|
2608
|
+
return 'DataView';
|
|
2609
|
+
}
|
|
2610
|
+
|
|
2611
|
+
/* ! Spec Conformance
|
|
2612
|
+
* (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%mapiteratorprototype%-@@tostringtag)
|
|
2613
|
+
* ES6$23.1.5.2.2 - %MapIteratorPrototype%[@@toStringTag] should be "Map Iterator":
|
|
2614
|
+
* Test: `Object.prototype.toString.call(new Map().entries())``
|
|
2615
|
+
* - Edge <=13 === "[object Object]"
|
|
2616
|
+
*/
|
|
2617
|
+
if (mapExists && objPrototype === mapIteratorPrototype) {
|
|
2618
|
+
return 'Map Iterator';
|
|
2619
|
+
}
|
|
2620
|
+
|
|
2621
|
+
/* ! Spec Conformance
|
|
2622
|
+
* (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%setiteratorprototype%-@@tostringtag)
|
|
2623
|
+
* ES6$23.2.5.2.2 - %SetIteratorPrototype%[@@toStringTag] should be "Set Iterator":
|
|
2624
|
+
* Test: `Object.prototype.toString.call(new Set().entries())``
|
|
2625
|
+
* - Edge <=13 === "[object Object]"
|
|
2626
|
+
*/
|
|
2627
|
+
if (setExists && objPrototype === setIteratorPrototype) {
|
|
2628
|
+
return 'Set Iterator';
|
|
2629
|
+
}
|
|
2630
|
+
|
|
2631
|
+
/* ! Spec Conformance
|
|
2632
|
+
* (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%arrayiteratorprototype%-@@tostringtag)
|
|
2633
|
+
* ES6$22.1.5.2.2 - %ArrayIteratorPrototype%[@@toStringTag] should be "Array Iterator":
|
|
2634
|
+
* Test: `Object.prototype.toString.call([][Symbol.iterator]())``
|
|
2635
|
+
* - Edge <=13 === "[object Object]"
|
|
2636
|
+
*/
|
|
2637
|
+
if (arrayIteratorExists && objPrototype === arrayIteratorPrototype) {
|
|
2638
|
+
return 'Array Iterator';
|
|
2639
|
+
}
|
|
2640
|
+
|
|
2641
|
+
/* ! Spec Conformance
|
|
2642
|
+
* (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%stringiteratorprototype%-@@tostringtag)
|
|
2643
|
+
* ES6$21.1.5.2.2 - %StringIteratorPrototype%[@@toStringTag] should be "String Iterator":
|
|
2644
|
+
* Test: `Object.prototype.toString.call(''[Symbol.iterator]())``
|
|
2645
|
+
* - Edge <=13 === "[object Object]"
|
|
2646
|
+
*/
|
|
2647
|
+
if (stringIteratorExists && objPrototype === stringIteratorPrototype) {
|
|
2648
|
+
return 'String Iterator';
|
|
2649
|
+
}
|
|
2650
|
+
|
|
2651
|
+
/* ! Speed optimisation
|
|
2652
|
+
* Pre:
|
|
2653
|
+
* object from null x 2,424,320 ops/sec ±1.67% (76 runs sampled)
|
|
2654
|
+
* Post:
|
|
2655
|
+
* object from null x 5,838,000 ops/sec ±0.99% (84 runs sampled)
|
|
2656
|
+
*/
|
|
2657
|
+
if (objPrototype === null) {
|
|
2658
|
+
return 'Object';
|
|
2659
|
+
}
|
|
2660
|
+
|
|
2661
|
+
return Object
|
|
2662
|
+
.prototype
|
|
2663
|
+
.toString
|
|
2664
|
+
.call(obj)
|
|
2665
|
+
.slice(toStringLeftSliceLength, toStringRightSliceLength);
|
|
2666
|
+
}
|
|
2620
2667
|
|
|
2621
|
-
return typeDetect;
|
|
2668
|
+
return typeDetect;
|
|
2622
2669
|
|
|
2623
|
-
})));
|
|
2624
|
-
}(typeDetect));
|
|
2670
|
+
})));
|
|
2671
|
+
} (typeDetect));
|
|
2625
2672
|
|
|
2626
2673
|
var type = typeDetect.exports;
|
|
2627
2674
|
|
|
@@ -3089,6 +3136,7 @@ function withGlobal(_global) {
|
|
|
3089
3136
|
target.parse = source.parse;
|
|
3090
3137
|
target.UTC = source.UTC;
|
|
3091
3138
|
target.prototype.toUTCString = source.prototype.toUTCString;
|
|
3139
|
+
target.isFake = true;
|
|
3092
3140
|
|
|
3093
3141
|
return target;
|
|
3094
3142
|
}
|
|
@@ -4299,6 +4347,14 @@ function withGlobal(_global) {
|
|
|
4299
4347
|
);
|
|
4300
4348
|
}
|
|
4301
4349
|
|
|
4350
|
+
if (_global.Date.isFake === true) {
|
|
4351
|
+
// Timers are already faked; this is a problem.
|
|
4352
|
+
// Make the user reset timers before continuing.
|
|
4353
|
+
throw new TypeError(
|
|
4354
|
+
"Can't install fake timers twice on the same global object."
|
|
4355
|
+
);
|
|
4356
|
+
}
|
|
4357
|
+
|
|
4302
4358
|
// eslint-disable-next-line no-param-reassign
|
|
4303
4359
|
config = typeof config !== "undefined" ? config : {};
|
|
4304
4360
|
config.shouldAdvanceTime = config.shouldAdvanceTime || false;
|
|
@@ -4689,26 +4745,4 @@ function isWatchMode() {
|
|
|
4689
4745
|
return getRunningMode() === "watch";
|
|
4690
4746
|
}
|
|
4691
4747
|
|
|
4692
|
-
|
|
4693
|
-
__proto__: null,
|
|
4694
|
-
suite: suite,
|
|
4695
|
-
test: test,
|
|
4696
|
-
describe: describe,
|
|
4697
|
-
it: it,
|
|
4698
|
-
runOnce: runOnce,
|
|
4699
|
-
isFirstRun: isFirstRun,
|
|
4700
|
-
beforeAll: beforeAll,
|
|
4701
|
-
afterAll: afterAll,
|
|
4702
|
-
beforeEach: beforeEach,
|
|
4703
|
-
afterEach: afterEach,
|
|
4704
|
-
assert: assert,
|
|
4705
|
-
should: should,
|
|
4706
|
-
chai: chai$1,
|
|
4707
|
-
expect: expect,
|
|
4708
|
-
vitest: vitest,
|
|
4709
|
-
vi: vi,
|
|
4710
|
-
getRunningMode: getRunningMode,
|
|
4711
|
-
isWatchMode: isWatchMode
|
|
4712
|
-
});
|
|
4713
|
-
|
|
4714
|
-
export { RealDate as R, context as a, getSnapshotClient as b, clearContext as c, defaultSuite as d, setState as e, getFn as f, getHooks as g, getState as h, index as i, suite as j, describe as k, it as l, runOnce as m, isFirstRun as n, beforeAll as o, afterAll as p, beforeEach as q, resetRunOnceCounter as r, setHooks as s, test as t, afterEach as u, vi as v, expect as w, vitest as x, getRunningMode as y, isWatchMode as z };
|
|
4748
|
+
export { getState as A, RealDate as R, isFirstRun as a, beforeAll as b, afterAll as c, describe as d, beforeEach as e, afterEach as f, createExpect as g, expect as h, it as i, vi as j, getRunningMode as k, isWatchMode as l, resetRunOnceCounter as m, clearCollectorContext as n, defaultSuite as o, setHooks as p, getHooks as q, runOnce as r, suite as s, test as t, collectorContext as u, vitest as v, withCallback as w, getSnapshotClient as x, setState as y, getFn as z };
|