vitest 0.0.109 → 0.0.113
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +8 -6
- package/dist/{constants-e762cbc5.js → constants-900abe4a.js} +1 -1
- package/dist/{diff-46ee5d7d.js → diff-9c43ab50.js} +3300 -3298
- package/dist/entry.js +91 -465
- package/dist/{global-e0d00047.js → global-75208c77.js} +8 -7
- package/dist/{utils-d97bd6d9.js → index-041e627e.js} +5 -186
- package/dist/{index-0961cf69.js → index-09437c50.js} +12 -5
- package/dist/index-1488b423.js +186 -0
- package/dist/{index-a727b58c.js → index-c3f2f9fe.js} +845 -1690
- package/dist/index.d.ts +192 -21
- package/dist/index.js +5 -6
- package/dist/{jest-mock-8498c46d.js → jest-mock-a57b745c.js} +1 -4
- package/dist/magic-string.es-94000aea.js +1360 -0
- package/dist/{middleware-093a3bde.js → middleware-0ebc5238.js} +2 -4
- package/dist/node.d.ts +63 -1
- package/dist/node.js +8 -6
- package/dist/utils.js +3 -2
- package/dist/vi-51946984.js +1018 -0
- package/dist/worker.js +145 -74
- package/package.json +6 -6
- package/dist/vi-9754296d.js +0 -557
package/dist/vi-9754296d.js
DELETED
|
@@ -1,557 +0,0 @@
|
|
|
1
|
-
import { n as nanoid, a as spyOn, f as fn, s as spies } from './jest-mock-8498c46d.js';
|
|
2
|
-
import { n as noop } from './utils-d97bd6d9.js';
|
|
3
|
-
import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers-c9e3b764.js';
|
|
4
|
-
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __defProps = Object.defineProperties;
|
|
7
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
8
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
-
var __spreadValues = (a, b) => {
|
|
13
|
-
for (var prop in b || (b = {}))
|
|
14
|
-
if (__hasOwnProp.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
if (__getOwnPropSymbols)
|
|
17
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
-
if (__propIsEnum.call(b, prop))
|
|
19
|
-
__defNormalProp(a, prop, b[prop]);
|
|
20
|
-
}
|
|
21
|
-
return a;
|
|
22
|
-
};
|
|
23
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
-
function createChainable(keys, fn) {
|
|
25
|
-
function create(obj) {
|
|
26
|
-
const chain2 = function(...args) {
|
|
27
|
-
return fn.apply(obj, args);
|
|
28
|
-
};
|
|
29
|
-
for (const key of keys) {
|
|
30
|
-
Object.defineProperty(chain2, key, {
|
|
31
|
-
get() {
|
|
32
|
-
return create(__spreadProps(__spreadValues({}, obj), { [key]: true }));
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
return chain2;
|
|
37
|
-
}
|
|
38
|
-
const chain = create({});
|
|
39
|
-
chain.fn = fn;
|
|
40
|
-
return chain;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const context = {
|
|
44
|
-
tasks: [],
|
|
45
|
-
currentSuite: null
|
|
46
|
-
};
|
|
47
|
-
function collectTask(task) {
|
|
48
|
-
var _a;
|
|
49
|
-
(_a = context.currentSuite) == null ? void 0 : _a.tasks.push(task);
|
|
50
|
-
}
|
|
51
|
-
async function runWithSuite(suite, fn) {
|
|
52
|
-
const prev = context.currentSuite;
|
|
53
|
-
context.currentSuite = suite;
|
|
54
|
-
await fn();
|
|
55
|
-
context.currentSuite = prev;
|
|
56
|
-
}
|
|
57
|
-
function getDefaultTestTimeout() {
|
|
58
|
-
return process.__vitest_worker__.config.testTimeout;
|
|
59
|
-
}
|
|
60
|
-
function getDefaultHookTimeout() {
|
|
61
|
-
return process.__vitest_worker__.config.hookTimeout;
|
|
62
|
-
}
|
|
63
|
-
function withTimeout(fn, _timeout) {
|
|
64
|
-
const timeout = _timeout ?? getDefaultTestTimeout();
|
|
65
|
-
if (timeout <= 0 || timeout === Infinity)
|
|
66
|
-
return fn;
|
|
67
|
-
return (...args) => {
|
|
68
|
-
return Promise.race([fn(...args), new Promise((resolve, reject) => {
|
|
69
|
-
const timer = setTimeout(() => {
|
|
70
|
-
clearTimeout(timer);
|
|
71
|
-
reject(new Error(`Test timed out in ${timeout}ms.`));
|
|
72
|
-
}, timeout);
|
|
73
|
-
timer.unref();
|
|
74
|
-
})]);
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
function ensureAsyncTest(fn) {
|
|
78
|
-
if (!fn.length)
|
|
79
|
-
return fn;
|
|
80
|
-
return () => new Promise((resolve, reject) => {
|
|
81
|
-
const done = (...args) => args[0] ? reject(args[0]) : resolve();
|
|
82
|
-
fn(done);
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
function normalizeTest(fn, timeout) {
|
|
86
|
-
return withTimeout(ensureAsyncTest(fn), timeout);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const fnMap = /* @__PURE__ */ new WeakMap();
|
|
90
|
-
const hooksMap = /* @__PURE__ */ new WeakMap();
|
|
91
|
-
function setFn(key, fn) {
|
|
92
|
-
fnMap.set(key, fn);
|
|
93
|
-
}
|
|
94
|
-
function getFn(key) {
|
|
95
|
-
return fnMap.get(key);
|
|
96
|
-
}
|
|
97
|
-
function setHooks(key, hooks) {
|
|
98
|
-
hooksMap.set(key, hooks);
|
|
99
|
-
}
|
|
100
|
-
function getHooks(key) {
|
|
101
|
-
return hooksMap.get(key);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const suite = createSuite();
|
|
105
|
-
const test = createChainable(["concurrent", "skip", "only", "todo", "fails"], function(name, fn, timeout) {
|
|
106
|
-
getCurrentSuite().test.fn.call(this, name, fn, timeout);
|
|
107
|
-
});
|
|
108
|
-
const describe = suite;
|
|
109
|
-
const it = test;
|
|
110
|
-
const defaultSuite = suite("");
|
|
111
|
-
function clearContext() {
|
|
112
|
-
context.tasks.length = 0;
|
|
113
|
-
defaultSuite.clear();
|
|
114
|
-
context.currentSuite = defaultSuite;
|
|
115
|
-
}
|
|
116
|
-
function getCurrentSuite() {
|
|
117
|
-
return context.currentSuite || defaultSuite;
|
|
118
|
-
}
|
|
119
|
-
function createSuiteHooks() {
|
|
120
|
-
return {
|
|
121
|
-
beforeAll: [],
|
|
122
|
-
afterAll: [],
|
|
123
|
-
beforeEach: [],
|
|
124
|
-
afterEach: []
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
function createSuiteCollector(name, factory = () => {
|
|
128
|
-
}, mode, suiteComputeMode) {
|
|
129
|
-
const tasks = [];
|
|
130
|
-
const factoryQueue = [];
|
|
131
|
-
let suite2;
|
|
132
|
-
initSuite();
|
|
133
|
-
const test2 = createChainable(["concurrent", "skip", "only", "todo", "fails"], function(name2, fn, timeout) {
|
|
134
|
-
const mode2 = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
|
|
135
|
-
const computeMode = this.concurrent ? "concurrent" : void 0;
|
|
136
|
-
const test3 = {
|
|
137
|
-
id: nanoid(),
|
|
138
|
-
type: "test",
|
|
139
|
-
name: name2,
|
|
140
|
-
mode: mode2,
|
|
141
|
-
computeMode: computeMode ?? (suiteComputeMode ?? "serial"),
|
|
142
|
-
suite: void 0,
|
|
143
|
-
fails: this.fails
|
|
144
|
-
};
|
|
145
|
-
setFn(test3, normalizeTest(fn || noop, timeout));
|
|
146
|
-
tasks.push(test3);
|
|
147
|
-
});
|
|
148
|
-
const collector = {
|
|
149
|
-
type: "collector",
|
|
150
|
-
name,
|
|
151
|
-
mode,
|
|
152
|
-
test: test2,
|
|
153
|
-
tasks,
|
|
154
|
-
collect,
|
|
155
|
-
clear,
|
|
156
|
-
on: addHook
|
|
157
|
-
};
|
|
158
|
-
function addHook(name2, ...fn) {
|
|
159
|
-
getHooks(suite2)[name2].push(...fn);
|
|
160
|
-
}
|
|
161
|
-
function initSuite() {
|
|
162
|
-
suite2 = {
|
|
163
|
-
id: nanoid(),
|
|
164
|
-
type: "suite",
|
|
165
|
-
computeMode: "serial",
|
|
166
|
-
name,
|
|
167
|
-
mode,
|
|
168
|
-
tasks: []
|
|
169
|
-
};
|
|
170
|
-
setHooks(suite2, createSuiteHooks());
|
|
171
|
-
}
|
|
172
|
-
function clear() {
|
|
173
|
-
tasks.length = 0;
|
|
174
|
-
factoryQueue.length = 0;
|
|
175
|
-
initSuite();
|
|
176
|
-
}
|
|
177
|
-
async function collect(file) {
|
|
178
|
-
factoryQueue.length = 0;
|
|
179
|
-
if (factory)
|
|
180
|
-
await runWithSuite(collector, () => factory(test2));
|
|
181
|
-
const allChildren = await Promise.all([...factoryQueue, ...tasks].map((i) => i.type === "collector" ? i.collect(file) : i));
|
|
182
|
-
suite2.file = file;
|
|
183
|
-
suite2.tasks = allChildren;
|
|
184
|
-
allChildren.forEach((task) => {
|
|
185
|
-
task.suite = suite2;
|
|
186
|
-
if (file)
|
|
187
|
-
task.file = file;
|
|
188
|
-
});
|
|
189
|
-
return suite2;
|
|
190
|
-
}
|
|
191
|
-
collectTask(collector);
|
|
192
|
-
return collector;
|
|
193
|
-
}
|
|
194
|
-
function createSuite() {
|
|
195
|
-
return createChainable(["concurrent", "skip", "only", "todo"], function(name, factory) {
|
|
196
|
-
const mode = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
|
|
197
|
-
const computeMode = this.concurrent ? "concurrent" : void 0;
|
|
198
|
-
return createSuiteCollector(name, factory, mode, computeMode);
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
var mockdate$1 = {exports: {}};
|
|
203
|
-
|
|
204
|
-
(function (module, exports) {
|
|
205
|
-
(function (global, factory) {
|
|
206
|
-
factory(exports) ;
|
|
207
|
-
}(commonjsGlobal, (function (exports) {
|
|
208
|
-
/*! *****************************************************************************
|
|
209
|
-
Copyright (c) Microsoft Corporation.
|
|
210
|
-
|
|
211
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
212
|
-
purpose with or without fee is hereby granted.
|
|
213
|
-
|
|
214
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
215
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
216
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
217
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
218
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
219
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
220
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
221
|
-
***************************************************************************** */
|
|
222
|
-
/* global Reflect, Promise */
|
|
223
|
-
|
|
224
|
-
var extendStatics = function(d, b) {
|
|
225
|
-
extendStatics = Object.setPrototypeOf ||
|
|
226
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
227
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
228
|
-
return extendStatics(d, b);
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
function __extends(d, b) {
|
|
232
|
-
if (typeof b !== "function" && b !== null)
|
|
233
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
234
|
-
extendStatics(d, b);
|
|
235
|
-
function __() { this.constructor = d; }
|
|
236
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
var RealDate = Date;
|
|
240
|
-
var now = null;
|
|
241
|
-
var MockDate = /** @class */ (function (_super) {
|
|
242
|
-
__extends(Date, _super);
|
|
243
|
-
function Date(y, m, d, h, M, s, ms) {
|
|
244
|
-
_super.call(this) || this;
|
|
245
|
-
var date;
|
|
246
|
-
switch (arguments.length) {
|
|
247
|
-
case 0:
|
|
248
|
-
if (now !== null) {
|
|
249
|
-
date = new RealDate(now.valueOf());
|
|
250
|
-
}
|
|
251
|
-
else {
|
|
252
|
-
date = new RealDate();
|
|
253
|
-
}
|
|
254
|
-
break;
|
|
255
|
-
case 1:
|
|
256
|
-
date = new RealDate(y);
|
|
257
|
-
break;
|
|
258
|
-
default:
|
|
259
|
-
d = typeof d === 'undefined' ? 1 : d;
|
|
260
|
-
h = h || 0;
|
|
261
|
-
M = M || 0;
|
|
262
|
-
s = s || 0;
|
|
263
|
-
ms = ms || 0;
|
|
264
|
-
date = new RealDate(y, m, d, h, M, s, ms);
|
|
265
|
-
break;
|
|
266
|
-
}
|
|
267
|
-
return date;
|
|
268
|
-
}
|
|
269
|
-
return Date;
|
|
270
|
-
}(RealDate));
|
|
271
|
-
MockDate.prototype = RealDate.prototype;
|
|
272
|
-
MockDate.UTC = RealDate.UTC;
|
|
273
|
-
MockDate.now = function () {
|
|
274
|
-
return new MockDate().valueOf();
|
|
275
|
-
};
|
|
276
|
-
MockDate.parse = function (dateString) {
|
|
277
|
-
return RealDate.parse(dateString);
|
|
278
|
-
};
|
|
279
|
-
MockDate.toString = function () {
|
|
280
|
-
return RealDate.toString();
|
|
281
|
-
};
|
|
282
|
-
function set(date) {
|
|
283
|
-
var dateObj = new Date(date.valueOf());
|
|
284
|
-
if (isNaN(dateObj.getTime())) {
|
|
285
|
-
throw new TypeError('mockdate: The time set is an invalid date: ' + date);
|
|
286
|
-
}
|
|
287
|
-
// @ts-ignore
|
|
288
|
-
Date = MockDate;
|
|
289
|
-
now = dateObj.valueOf();
|
|
290
|
-
}
|
|
291
|
-
function reset() {
|
|
292
|
-
Date = RealDate;
|
|
293
|
-
}
|
|
294
|
-
var mockdate = {
|
|
295
|
-
set: set,
|
|
296
|
-
reset: reset,
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
exports.default = mockdate;
|
|
300
|
-
exports.reset = reset;
|
|
301
|
-
exports.set = set;
|
|
302
|
-
|
|
303
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
304
|
-
|
|
305
|
-
})));
|
|
306
|
-
}(mockdate$1, mockdate$1.exports));
|
|
307
|
-
|
|
308
|
-
var mockdate = /*@__PURE__*/getDefaultExportFromCjs(mockdate$1.exports);
|
|
309
|
-
|
|
310
|
-
const originalSetTimeout = global.setTimeout;
|
|
311
|
-
const originalSetInterval = global.setInterval;
|
|
312
|
-
const originalClearTimeout = global.clearTimeout;
|
|
313
|
-
const originalClearInterval = global.clearInterval;
|
|
314
|
-
const MAX_LOOPS = 1e4;
|
|
315
|
-
const assertEvery = (assertions, message) => {
|
|
316
|
-
if (assertions.some((a) => !a))
|
|
317
|
-
throw new Error(message);
|
|
318
|
-
};
|
|
319
|
-
const assertMaxLoop = (times) => {
|
|
320
|
-
if (times >= MAX_LOOPS)
|
|
321
|
-
throw new Error("setTimeout/setInterval called 10 000 times. It's possible it stuck in an infinite loop.");
|
|
322
|
-
};
|
|
323
|
-
const getNodeTimeout = (id) => {
|
|
324
|
-
const timer = {
|
|
325
|
-
ref: () => timer,
|
|
326
|
-
unref: () => timer,
|
|
327
|
-
hasRef: () => true,
|
|
328
|
-
refresh: () => timer,
|
|
329
|
-
[Symbol.toPrimitive]: () => id
|
|
330
|
-
};
|
|
331
|
-
return timer;
|
|
332
|
-
};
|
|
333
|
-
class FakeTimers {
|
|
334
|
-
constructor() {
|
|
335
|
-
this._advancedTime = 0;
|
|
336
|
-
this._nestedTime = {};
|
|
337
|
-
this._scopeId = 0;
|
|
338
|
-
this._isNested = false;
|
|
339
|
-
this._isOnlyPending = false;
|
|
340
|
-
this._spyid = 0;
|
|
341
|
-
this._isMocked = false;
|
|
342
|
-
this._tasksQueue = [];
|
|
343
|
-
this._queueCount = 0;
|
|
344
|
-
}
|
|
345
|
-
useFakeTimers() {
|
|
346
|
-
this._isMocked = true;
|
|
347
|
-
this.reset();
|
|
348
|
-
const spyFactory = (spyType, resultBuilder) => {
|
|
349
|
-
return (cb, ms = 0) => {
|
|
350
|
-
const id = ++this._spyid;
|
|
351
|
-
const nestedTo = Object.entries(this._nestedTime).filter(([key]) => Number(key) <= this._scopeId);
|
|
352
|
-
const nestedMs = nestedTo.reduce((total, [, ms2]) => total + ms2, ms);
|
|
353
|
-
const call = { id, cb, ms, nestedMs, scopeId: this._scopeId };
|
|
354
|
-
const task = { type: spyType, call, nested: this._isNested };
|
|
355
|
-
this.pushTask(task);
|
|
356
|
-
return resultBuilder(id, cb);
|
|
357
|
-
};
|
|
358
|
-
};
|
|
359
|
-
this._setTimeout = spyOn(global, "setTimeout").mockImplementation(spyFactory("timeout" /* Timeout */, getNodeTimeout));
|
|
360
|
-
this._setInterval = spyOn(global, "setInterval").mockImplementation(spyFactory("interval" /* Interval */, getNodeTimeout));
|
|
361
|
-
const clearTimerFactory = (spyType) => (id) => {
|
|
362
|
-
if (id === void 0)
|
|
363
|
-
return;
|
|
364
|
-
const index = this._tasksQueue.findIndex(({ call, type }) => type === spyType && call.id === Number(id));
|
|
365
|
-
if (index !== -1)
|
|
366
|
-
this._tasksQueue.splice(index, 1);
|
|
367
|
-
};
|
|
368
|
-
this._clearTimeout = spyOn(global, "clearTimeout").mockImplementation(clearTimerFactory("timeout" /* Timeout */));
|
|
369
|
-
this._clearInterval = spyOn(global, "clearInterval").mockImplementation(clearTimerFactory("interval" /* Interval */));
|
|
370
|
-
}
|
|
371
|
-
useRealTimers() {
|
|
372
|
-
this._isMocked = false;
|
|
373
|
-
this.reset();
|
|
374
|
-
global.setTimeout = originalSetTimeout;
|
|
375
|
-
global.setInterval = originalSetInterval;
|
|
376
|
-
global.clearTimeout = originalClearTimeout;
|
|
377
|
-
global.clearInterval = originalClearInterval;
|
|
378
|
-
}
|
|
379
|
-
runOnlyPendingTimers() {
|
|
380
|
-
this.assertMocked();
|
|
381
|
-
this._isOnlyPending = true;
|
|
382
|
-
this.runQueue();
|
|
383
|
-
}
|
|
384
|
-
runAllTimers() {
|
|
385
|
-
this.assertMocked();
|
|
386
|
-
this.runQueue();
|
|
387
|
-
}
|
|
388
|
-
advanceTimersByTime(ms) {
|
|
389
|
-
this.assertMocked();
|
|
390
|
-
this._advancedTime += ms;
|
|
391
|
-
this.runQueue();
|
|
392
|
-
}
|
|
393
|
-
advanceTimersToNextTimer() {
|
|
394
|
-
this.assertMocked();
|
|
395
|
-
this.callQueueItem(0);
|
|
396
|
-
}
|
|
397
|
-
getTimerCount() {
|
|
398
|
-
this.assertMocked();
|
|
399
|
-
return this._tasksQueue.length;
|
|
400
|
-
}
|
|
401
|
-
reset() {
|
|
402
|
-
var _a, _b, _c, _d;
|
|
403
|
-
this._advancedTime = 0;
|
|
404
|
-
this._nestedTime = {};
|
|
405
|
-
this._isNested = false;
|
|
406
|
-
this._isOnlyPending = false;
|
|
407
|
-
this._spyid = 0;
|
|
408
|
-
this._queueCount = 0;
|
|
409
|
-
this._tasksQueue = [];
|
|
410
|
-
(_a = this._clearInterval) == null ? void 0 : _a.mockRestore();
|
|
411
|
-
(_b = this._clearTimeout) == null ? void 0 : _b.mockRestore();
|
|
412
|
-
(_c = this._setInterval) == null ? void 0 : _c.mockRestore();
|
|
413
|
-
(_d = this._setTimeout) == null ? void 0 : _d.mockRestore();
|
|
414
|
-
}
|
|
415
|
-
callQueueItem(index) {
|
|
416
|
-
var _a, _b;
|
|
417
|
-
const task = this._tasksQueue[index];
|
|
418
|
-
if (!task)
|
|
419
|
-
return;
|
|
420
|
-
const { call, type } = task;
|
|
421
|
-
this._scopeId = call.id;
|
|
422
|
-
this._isNested = true;
|
|
423
|
-
(_a = this._nestedTime)[_b = call.id] ?? (_a[_b] = 0);
|
|
424
|
-
this._nestedTime[call.id] += call.ms;
|
|
425
|
-
if (type === "timeout") {
|
|
426
|
-
this.removeTask(index);
|
|
427
|
-
} else if (type === "interval") {
|
|
428
|
-
call.nestedMs += call.ms;
|
|
429
|
-
const nestedMs = call.nestedMs;
|
|
430
|
-
const closestTask = this._tasksQueue.findIndex(({ type: type2, call: call2 }) => type2 === "interval" && call2.nestedMs < nestedMs);
|
|
431
|
-
if (closestTask !== -1 && closestTask !== index)
|
|
432
|
-
this.ensureQueueOrder();
|
|
433
|
-
}
|
|
434
|
-
call.cb();
|
|
435
|
-
this._queueCount++;
|
|
436
|
-
}
|
|
437
|
-
runQueue() {
|
|
438
|
-
let index = 0;
|
|
439
|
-
while (this._tasksQueue[index]) {
|
|
440
|
-
assertMaxLoop(this._queueCount);
|
|
441
|
-
const { call, nested } = this._tasksQueue[index];
|
|
442
|
-
if (this._advancedTime && call.nestedMs > this._advancedTime)
|
|
443
|
-
break;
|
|
444
|
-
if (this._isOnlyPending && nested) {
|
|
445
|
-
index++;
|
|
446
|
-
continue;
|
|
447
|
-
}
|
|
448
|
-
this.callQueueItem(index);
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
removeTask(index) {
|
|
452
|
-
if (index === 0)
|
|
453
|
-
this._tasksQueue.shift();
|
|
454
|
-
else
|
|
455
|
-
this._tasksQueue.splice(index, 1);
|
|
456
|
-
}
|
|
457
|
-
pushTask(task) {
|
|
458
|
-
this._tasksQueue.push(task);
|
|
459
|
-
this.ensureQueueOrder();
|
|
460
|
-
}
|
|
461
|
-
ensureQueueOrder() {
|
|
462
|
-
this._tasksQueue.sort((t1, t2) => {
|
|
463
|
-
const diff = t1.call.nestedMs - t2.call.nestedMs;
|
|
464
|
-
if (diff === 0) {
|
|
465
|
-
if (t1.type === "immediate" /* Immediate */ && t2.type !== "immediate" /* Immediate */)
|
|
466
|
-
return 1;
|
|
467
|
-
return 0;
|
|
468
|
-
}
|
|
469
|
-
return diff;
|
|
470
|
-
});
|
|
471
|
-
}
|
|
472
|
-
assertMocked() {
|
|
473
|
-
assertEvery([
|
|
474
|
-
this._isMocked,
|
|
475
|
-
this._setTimeout,
|
|
476
|
-
this._setInterval,
|
|
477
|
-
this._clearTimeout,
|
|
478
|
-
this._clearInterval
|
|
479
|
-
], 'timers are not mocked. try calling "vitest.useFakeTimers()" first');
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
class VitestUtils {
|
|
484
|
-
constructor() {
|
|
485
|
-
this.spyOn = spyOn;
|
|
486
|
-
this.fn = fn;
|
|
487
|
-
this._timers = new FakeTimers();
|
|
488
|
-
this._mockedDate = null;
|
|
489
|
-
}
|
|
490
|
-
useFakeTimers() {
|
|
491
|
-
return this._timers.useFakeTimers();
|
|
492
|
-
}
|
|
493
|
-
useRealTimers() {
|
|
494
|
-
return this._timers.useRealTimers();
|
|
495
|
-
}
|
|
496
|
-
runOnlyPendingTimers() {
|
|
497
|
-
return this._timers.runOnlyPendingTimers();
|
|
498
|
-
}
|
|
499
|
-
runAllTimers() {
|
|
500
|
-
return this._timers.runAllTimers();
|
|
501
|
-
}
|
|
502
|
-
advanceTimersByTime(ms) {
|
|
503
|
-
return this._timers.advanceTimersByTime(ms);
|
|
504
|
-
}
|
|
505
|
-
advanceTimersToNextTimer() {
|
|
506
|
-
return this._timers.advanceTimersToNextTimer();
|
|
507
|
-
}
|
|
508
|
-
getTimerCount() {
|
|
509
|
-
return this._timers.getTimerCount();
|
|
510
|
-
}
|
|
511
|
-
mockCurrentDate(date) {
|
|
512
|
-
this._mockedDate = date;
|
|
513
|
-
mockdate.set(date);
|
|
514
|
-
}
|
|
515
|
-
restoreCurrentDate() {
|
|
516
|
-
this._mockedDate = null;
|
|
517
|
-
mockdate.reset();
|
|
518
|
-
}
|
|
519
|
-
getMockedDate() {
|
|
520
|
-
return this._mockedDate;
|
|
521
|
-
}
|
|
522
|
-
mock(path) {
|
|
523
|
-
}
|
|
524
|
-
unmock(path) {
|
|
525
|
-
}
|
|
526
|
-
async importActual(path) {
|
|
527
|
-
return {};
|
|
528
|
-
}
|
|
529
|
-
async importMock(path) {
|
|
530
|
-
return {};
|
|
531
|
-
}
|
|
532
|
-
mocked(item, _deep = false) {
|
|
533
|
-
return item;
|
|
534
|
-
}
|
|
535
|
-
isMockFunction(fn2) {
|
|
536
|
-
return typeof fn2 === "function" && "__isSpy" in fn2 && fn2.__isSpy;
|
|
537
|
-
}
|
|
538
|
-
clearAllMocks() {
|
|
539
|
-
__vitest__clearMocks__({ clearMocks: true });
|
|
540
|
-
spies.forEach((spy) => spy.mockClear());
|
|
541
|
-
return this;
|
|
542
|
-
}
|
|
543
|
-
resetAllMocks() {
|
|
544
|
-
__vitest__clearMocks__({ mockReset: true });
|
|
545
|
-
spies.forEach((spy) => spy.mockReset());
|
|
546
|
-
return this;
|
|
547
|
-
}
|
|
548
|
-
restoreAllMocks() {
|
|
549
|
-
__vitest__clearMocks__({ restoreMocks: true });
|
|
550
|
-
spies.forEach((spy) => spy.mockRestore());
|
|
551
|
-
return this;
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
const vitest = new VitestUtils();
|
|
555
|
-
const vi = vitest;
|
|
556
|
-
|
|
557
|
-
export { getDefaultHookTimeout as a, vi as b, clearContext as c, describe as d, defaultSuite as e, setHooks as f, getCurrentSuite as g, getHooks as h, it as i, context as j, getFn as k, suite as s, test as t, vitest as v, withTimeout as w };
|