vitest 0.0.105 → 0.0.109

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.
@@ -1,814 +0,0 @@
1
- import require$$0 from 'tty';
2
- import { isPackageExists } from 'local-pkg';
3
- import path from 'path';
4
- import { util } from 'chai';
5
- import * as tinyspy from 'tinyspy';
6
-
7
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
8
-
9
- function getDefaultExportFromCjs (x) {
10
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
11
- }
12
-
13
- function commonjsRequire (path) {
14
- 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.');
15
- }
16
-
17
- var picocolors = {exports: {}};
18
-
19
- let tty = require$$0;
20
-
21
- let isColorSupported =
22
- !("NO_COLOR" in process.env || process.argv.includes("--no-color")) &&
23
- ("FORCE_COLOR" in process.env ||
24
- process.argv.includes("--color") ||
25
- process.platform === "win32" ||
26
- (tty.isatty(1) && process.env.TERM !== "dumb") ||
27
- "CI" in process.env);
28
-
29
- let formatter =
30
- (open, close, replace = open) =>
31
- input => {
32
- let string = "" + input;
33
- let index = string.indexOf(close, open.length);
34
- return ~index
35
- ? open + replaceClose(string, close, replace, index) + close
36
- : open + string + close
37
- };
38
-
39
- let replaceClose = (string, close, replace, index) => {
40
- let start = string.substring(0, index) + replace;
41
- let end = string.substring(index + close.length);
42
- let nextIndex = end.indexOf(close);
43
- return ~nextIndex ? start + replaceClose(end, close, replace, nextIndex) : start + end
44
- };
45
-
46
- let createColors = (enabled = isColorSupported) => ({
47
- isColorSupported: enabled,
48
- reset: enabled ? s => `\x1b[0m${s}\x1b[0m` : String,
49
- bold: enabled ? formatter("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m") : String,
50
- dim: enabled ? formatter("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m") : String,
51
- italic: enabled ? formatter("\x1b[3m", "\x1b[23m") : String,
52
- underline: enabled ? formatter("\x1b[4m", "\x1b[24m") : String,
53
- inverse: enabled ? formatter("\x1b[7m", "\x1b[27m") : String,
54
- hidden: enabled ? formatter("\x1b[8m", "\x1b[28m") : String,
55
- strikethrough: enabled ? formatter("\x1b[9m", "\x1b[29m") : String,
56
- black: enabled ? formatter("\x1b[30m", "\x1b[39m") : String,
57
- red: enabled ? formatter("\x1b[31m", "\x1b[39m") : String,
58
- green: enabled ? formatter("\x1b[32m", "\x1b[39m") : String,
59
- yellow: enabled ? formatter("\x1b[33m", "\x1b[39m") : String,
60
- blue: enabled ? formatter("\x1b[34m", "\x1b[39m") : String,
61
- magenta: enabled ? formatter("\x1b[35m", "\x1b[39m") : String,
62
- cyan: enabled ? formatter("\x1b[36m", "\x1b[39m") : String,
63
- white: enabled ? formatter("\x1b[37m", "\x1b[39m") : String,
64
- gray: enabled ? formatter("\x1b[90m", "\x1b[39m") : String,
65
- bgBlack: enabled ? formatter("\x1b[40m", "\x1b[49m") : String,
66
- bgRed: enabled ? formatter("\x1b[41m", "\x1b[49m") : String,
67
- bgGreen: enabled ? formatter("\x1b[42m", "\x1b[49m") : String,
68
- bgYellow: enabled ? formatter("\x1b[43m", "\x1b[49m") : String,
69
- bgBlue: enabled ? formatter("\x1b[44m", "\x1b[49m") : String,
70
- bgMagenta: enabled ? formatter("\x1b[45m", "\x1b[49m") : String,
71
- bgCyan: enabled ? formatter("\x1b[46m", "\x1b[49m") : String,
72
- bgWhite: enabled ? formatter("\x1b[47m", "\x1b[49m") : String,
73
- });
74
-
75
- picocolors.exports = createColors();
76
- picocolors.exports.createColors = createColors;
77
-
78
- var c = picocolors.exports;
79
-
80
- function normalizeWindowsPath(input = "") {
81
- if (!input.includes("\\")) {
82
- return input;
83
- }
84
- return input.replace(/\\/g, "/");
85
- }
86
-
87
- const _UNC_REGEX = /^[/][/]/;
88
- const _UNC_DRIVE_REGEX = /^[/][/]([.]{1,2}[/])?([a-zA-Z]):[/]/;
89
- const _IS_ABSOLUTE_RE = /^\/|^\\|^[a-zA-Z]:[/\\]/;
90
- const sep = "/";
91
- const delimiter = ":";
92
- const normalize = function(path2) {
93
- if (path2.length === 0) {
94
- return ".";
95
- }
96
- path2 = normalizeWindowsPath(path2);
97
- const isUNCPath = path2.match(_UNC_REGEX);
98
- const hasUNCDrive = isUNCPath && path2.match(_UNC_DRIVE_REGEX);
99
- const isPathAbsolute = isAbsolute(path2);
100
- const trailingSeparator = path2[path2.length - 1] === "/";
101
- path2 = normalizeString(path2, !isPathAbsolute);
102
- if (path2.length === 0) {
103
- if (isPathAbsolute) {
104
- return "/";
105
- }
106
- return trailingSeparator ? "./" : ".";
107
- }
108
- if (trailingSeparator) {
109
- path2 += "/";
110
- }
111
- if (isUNCPath) {
112
- if (hasUNCDrive) {
113
- return `//./${path2}`;
114
- }
115
- return `//${path2}`;
116
- }
117
- return isPathAbsolute && !isAbsolute(path2) ? `/${path2}` : path2;
118
- };
119
- const join = function(...args) {
120
- if (args.length === 0) {
121
- return ".";
122
- }
123
- let joined;
124
- for (let i = 0; i < args.length; ++i) {
125
- const arg = args[i];
126
- if (arg.length > 0) {
127
- if (joined === void 0) {
128
- joined = arg;
129
- } else {
130
- joined += `/${arg}`;
131
- }
132
- }
133
- }
134
- if (joined === void 0) {
135
- return ".";
136
- }
137
- return normalize(joined);
138
- };
139
- const resolve = function(...args) {
140
- args = args.map((arg) => normalizeWindowsPath(arg));
141
- let resolvedPath = "";
142
- let resolvedAbsolute = false;
143
- for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
144
- const path2 = i >= 0 ? args[i] : process.cwd();
145
- if (path2.length === 0) {
146
- continue;
147
- }
148
- resolvedPath = `${path2}/${resolvedPath}`;
149
- resolvedAbsolute = isAbsolute(path2);
150
- }
151
- resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
152
- if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
153
- return `/${resolvedPath}`;
154
- }
155
- return resolvedPath.length > 0 ? resolvedPath : ".";
156
- };
157
- function normalizeString(path2, allowAboveRoot) {
158
- let res = "";
159
- let lastSegmentLength = 0;
160
- let lastSlash = -1;
161
- let dots = 0;
162
- let char = null;
163
- for (let i = 0; i <= path2.length; ++i) {
164
- if (i < path2.length) {
165
- char = path2[i];
166
- } else if (char === "/") {
167
- break;
168
- } else {
169
- char = "/";
170
- }
171
- if (char === "/") {
172
- if (lastSlash === i - 1 || dots === 1) ; else if (dots === 2) {
173
- if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
174
- if (res.length > 2) {
175
- const lastSlashIndex = res.lastIndexOf("/");
176
- if (lastSlashIndex === -1) {
177
- res = "";
178
- lastSegmentLength = 0;
179
- } else {
180
- res = res.slice(0, lastSlashIndex);
181
- lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
182
- }
183
- lastSlash = i;
184
- dots = 0;
185
- continue;
186
- } else if (res.length !== 0) {
187
- res = "";
188
- lastSegmentLength = 0;
189
- lastSlash = i;
190
- dots = 0;
191
- continue;
192
- }
193
- }
194
- if (allowAboveRoot) {
195
- res += res.length > 0 ? "/.." : "..";
196
- lastSegmentLength = 2;
197
- }
198
- } else {
199
- if (res.length > 0) {
200
- res += `/${path2.slice(lastSlash + 1, i)}`;
201
- } else {
202
- res = path2.slice(lastSlash + 1, i);
203
- }
204
- lastSegmentLength = i - lastSlash - 1;
205
- }
206
- lastSlash = i;
207
- dots = 0;
208
- } else if (char === "." && dots !== -1) {
209
- ++dots;
210
- } else {
211
- dots = -1;
212
- }
213
- }
214
- return res;
215
- }
216
- const isAbsolute = function(p) {
217
- return _IS_ABSOLUTE_RE.test(p);
218
- };
219
- const toNamespacedPath = function(p) {
220
- return normalizeWindowsPath(p);
221
- };
222
- const extname = function(p) {
223
- return path.posix.extname(normalizeWindowsPath(p));
224
- };
225
- const relative = function(from, to) {
226
- return path.posix.relative(normalizeWindowsPath(from), normalizeWindowsPath(to));
227
- };
228
- const dirname = function(p) {
229
- return path.posix.dirname(normalizeWindowsPath(p));
230
- };
231
- const format = function(p) {
232
- return normalizeWindowsPath(path.posix.format(p));
233
- };
234
- const basename = function(p, ext) {
235
- return path.posix.basename(normalizeWindowsPath(p), ext);
236
- };
237
- const parse = function(p) {
238
- return path.posix.parse(normalizeWindowsPath(p));
239
- };
240
-
241
- const _path = /*#__PURE__*/Object.freeze({
242
- __proto__: null,
243
- sep: sep,
244
- delimiter: delimiter,
245
- normalize: normalize,
246
- join: join,
247
- resolve: resolve,
248
- normalizeString: normalizeString,
249
- isAbsolute: isAbsolute,
250
- toNamespacedPath: toNamespacedPath,
251
- extname: extname,
252
- relative: relative,
253
- dirname: dirname,
254
- format: format,
255
- basename: basename,
256
- parse: parse
257
- });
258
-
259
- const index = {
260
- ..._path
261
- };
262
-
263
- var mockdate$1 = {exports: {}};
264
-
265
- (function (module, exports) {
266
- (function (global, factory) {
267
- factory(exports) ;
268
- }(commonjsGlobal, (function (exports) {
269
- /*! *****************************************************************************
270
- Copyright (c) Microsoft Corporation.
271
-
272
- Permission to use, copy, modify, and/or distribute this software for any
273
- purpose with or without fee is hereby granted.
274
-
275
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
276
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
277
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
278
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
279
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
280
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
281
- PERFORMANCE OF THIS SOFTWARE.
282
- ***************************************************************************** */
283
- /* global Reflect, Promise */
284
-
285
- var extendStatics = function(d, b) {
286
- extendStatics = Object.setPrototypeOf ||
287
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
288
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
289
- return extendStatics(d, b);
290
- };
291
-
292
- function __extends(d, b) {
293
- if (typeof b !== "function" && b !== null)
294
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
295
- extendStatics(d, b);
296
- function __() { this.constructor = d; }
297
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
298
- }
299
-
300
- var RealDate = Date;
301
- var now = null;
302
- var MockDate = /** @class */ (function (_super) {
303
- __extends(Date, _super);
304
- function Date(y, m, d, h, M, s, ms) {
305
- _super.call(this) || this;
306
- var date;
307
- switch (arguments.length) {
308
- case 0:
309
- if (now !== null) {
310
- date = new RealDate(now.valueOf());
311
- }
312
- else {
313
- date = new RealDate();
314
- }
315
- break;
316
- case 1:
317
- date = new RealDate(y);
318
- break;
319
- default:
320
- d = typeof d === 'undefined' ? 1 : d;
321
- h = h || 0;
322
- M = M || 0;
323
- s = s || 0;
324
- ms = ms || 0;
325
- date = new RealDate(y, m, d, h, M, s, ms);
326
- break;
327
- }
328
- return date;
329
- }
330
- return Date;
331
- }(RealDate));
332
- MockDate.prototype = RealDate.prototype;
333
- MockDate.UTC = RealDate.UTC;
334
- MockDate.now = function () {
335
- return new MockDate().valueOf();
336
- };
337
- MockDate.parse = function (dateString) {
338
- return RealDate.parse(dateString);
339
- };
340
- MockDate.toString = function () {
341
- return RealDate.toString();
342
- };
343
- function set(date) {
344
- var dateObj = new Date(date.valueOf());
345
- if (isNaN(dateObj.getTime())) {
346
- throw new TypeError('mockdate: The time set is an invalid date: ' + date);
347
- }
348
- // @ts-ignore
349
- Date = MockDate;
350
- now = dateObj.valueOf();
351
- }
352
- function reset() {
353
- Date = RealDate;
354
- }
355
- var mockdate = {
356
- set: set,
357
- reset: reset,
358
- };
359
-
360
- exports.default = mockdate;
361
- exports.reset = reset;
362
- exports.set = set;
363
-
364
- Object.defineProperty(exports, '__esModule', { value: true });
365
-
366
- })));
367
- }(mockdate$1, mockdate$1.exports));
368
-
369
- var mockdate = /*@__PURE__*/getDefaultExportFromCjs(mockdate$1.exports);
370
-
371
- const spies = /* @__PURE__ */ new Set();
372
- function spyOn(obj, method, accessType) {
373
- const dictionary = {
374
- get: "getter",
375
- set: "setter"
376
- };
377
- const objMethod = accessType ? { [dictionary[accessType]]: method } : method;
378
- const stub = tinyspy.spyOn(obj, objMethod);
379
- return enhanceSpy(stub);
380
- }
381
- function enhanceSpy(spy) {
382
- const stub = spy;
383
- let implementation;
384
- const instances = [];
385
- const mockContext = {
386
- get calls() {
387
- return stub.calls;
388
- },
389
- get instances() {
390
- return instances;
391
- },
392
- get invocationCallOrder() {
393
- return [];
394
- },
395
- get results() {
396
- return stub.results.map(([callType, value]) => {
397
- const type = callType === "error" ? "throw" : "return";
398
- return { type, value };
399
- });
400
- }
401
- };
402
- let onceImplementations = [];
403
- let name = "";
404
- Object.defineProperty(stub, "name", {
405
- get: () => name
406
- });
407
- stub.getMockName = () => name || "vi.fn()";
408
- stub.mockName = (n) => {
409
- name = n;
410
- return stub;
411
- };
412
- stub.mockClear = () => {
413
- stub.reset();
414
- return stub;
415
- };
416
- stub.mockReset = () => {
417
- stub.reset();
418
- implementation = () => void 0;
419
- onceImplementations = [];
420
- return stub;
421
- };
422
- stub.mockRestore = () => {
423
- stub.mockReset();
424
- implementation = void 0;
425
- return stub;
426
- };
427
- stub.getMockImplementation = () => implementation;
428
- stub.mockImplementation = (fn2) => {
429
- implementation = fn2;
430
- return stub;
431
- };
432
- stub.mockImplementationOnce = (fn2) => {
433
- onceImplementations.push(fn2);
434
- return stub;
435
- };
436
- stub.mockReturnThis = () => stub.mockImplementation(function() {
437
- return this;
438
- });
439
- stub.mockReturnValue = (val) => stub.mockImplementation(() => val);
440
- stub.mockReturnValueOnce = (val) => stub.mockImplementationOnce(() => val);
441
- stub.mockResolvedValue = (val) => stub.mockImplementation(() => Promise.resolve(val));
442
- stub.mockResolvedValueOnce = (val) => stub.mockImplementationOnce(() => Promise.resolve(val));
443
- stub.mockRejectedValue = (val) => stub.mockImplementation(() => Promise.reject(val));
444
- stub.mockRejectedValueOnce = (val) => stub.mockImplementationOnce(() => Promise.reject(val));
445
- util.addProperty(stub, "mock", () => mockContext);
446
- stub.willCall(function(...args) {
447
- instances.push(this);
448
- const impl = onceImplementations.shift() || implementation || stub.getOriginal() || (() => {
449
- });
450
- return impl.apply(this, args);
451
- });
452
- spies.add(stub);
453
- return stub;
454
- }
455
- function fn(implementation) {
456
- return enhanceSpy(tinyspy.spyOn({ fn: implementation || (() => {
457
- }) }, "fn"));
458
- }
459
-
460
- const originalSetTimeout = global.setTimeout;
461
- const originalSetInterval = global.setInterval;
462
- const originalClearTimeout = global.clearTimeout;
463
- const originalClearInterval = global.clearInterval;
464
- const MAX_LOOPS = 1e4;
465
- const assertEvery = (assertions, message) => {
466
- if (assertions.some((a) => !a))
467
- throw new Error(message);
468
- };
469
- const assertMaxLoop = (times) => {
470
- if (times >= MAX_LOOPS)
471
- throw new Error("setTimeout/setInterval called 10 000 times. It's possible it stuck in an infinite loop.");
472
- };
473
- const getNodeTimeout = (id) => {
474
- const timer = {
475
- ref: () => timer,
476
- unref: () => timer,
477
- hasRef: () => true,
478
- refresh: () => timer,
479
- [Symbol.toPrimitive]: () => id
480
- };
481
- return timer;
482
- };
483
- class FakeTimers {
484
- constructor() {
485
- this._advancedTime = 0;
486
- this._nestedTime = {};
487
- this._scopeId = 0;
488
- this._isNested = false;
489
- this._isOnlyPending = false;
490
- this._spyid = 0;
491
- this._isMocked = false;
492
- this._tasksQueue = [];
493
- this._queueCount = 0;
494
- }
495
- useFakeTimers() {
496
- this._isMocked = true;
497
- this.reset();
498
- const spyFactory = (spyType, resultBuilder) => {
499
- return (cb, ms = 0) => {
500
- const id = ++this._spyid;
501
- const nestedTo = Object.entries(this._nestedTime).filter(([key]) => Number(key) <= this._scopeId);
502
- const nestedMs = nestedTo.reduce((total, [, ms2]) => total + ms2, ms);
503
- const call = { id, cb, ms, nestedMs, scopeId: this._scopeId };
504
- const task = { type: spyType, call, nested: this._isNested };
505
- this.pushTask(task);
506
- return resultBuilder(id, cb);
507
- };
508
- };
509
- this._setTimeout = spyOn(global, "setTimeout").mockImplementation(spyFactory("timeout" /* Timeout */, getNodeTimeout));
510
- this._setInterval = spyOn(global, "setInterval").mockImplementation(spyFactory("interval" /* Interval */, getNodeTimeout));
511
- const clearTimerFactory = (spyType) => (id) => {
512
- if (id === void 0)
513
- return;
514
- const index = this._tasksQueue.findIndex(({ call, type }) => type === spyType && call.id === Number(id));
515
- if (index !== -1)
516
- this._tasksQueue.splice(index, 1);
517
- };
518
- this._clearTimeout = spyOn(global, "clearTimeout").mockImplementation(clearTimerFactory("timeout" /* Timeout */));
519
- this._clearInterval = spyOn(global, "clearInterval").mockImplementation(clearTimerFactory("interval" /* Interval */));
520
- }
521
- useRealTimers() {
522
- this._isMocked = false;
523
- this.reset();
524
- global.setTimeout = originalSetTimeout;
525
- global.setInterval = originalSetInterval;
526
- global.clearTimeout = originalClearTimeout;
527
- global.clearInterval = originalClearInterval;
528
- }
529
- runOnlyPendingTimers() {
530
- this.assertMocked();
531
- this._isOnlyPending = true;
532
- this.runQueue();
533
- }
534
- runAllTimers() {
535
- this.assertMocked();
536
- this.runQueue();
537
- }
538
- advanceTimersByTime(ms) {
539
- this.assertMocked();
540
- this._advancedTime += ms;
541
- this.runQueue();
542
- }
543
- advanceTimersToNextTimer() {
544
- this.assertMocked();
545
- this.callQueueItem(0);
546
- }
547
- getTimerCount() {
548
- this.assertMocked();
549
- return this._tasksQueue.length;
550
- }
551
- reset() {
552
- var _a, _b, _c, _d;
553
- this._advancedTime = 0;
554
- this._nestedTime = {};
555
- this._isNested = false;
556
- this._isOnlyPending = false;
557
- this._spyid = 0;
558
- this._queueCount = 0;
559
- this._tasksQueue = [];
560
- (_a = this._clearInterval) == null ? void 0 : _a.mockRestore();
561
- (_b = this._clearTimeout) == null ? void 0 : _b.mockRestore();
562
- (_c = this._setInterval) == null ? void 0 : _c.mockRestore();
563
- (_d = this._setTimeout) == null ? void 0 : _d.mockRestore();
564
- }
565
- callQueueItem(index) {
566
- var _a, _b;
567
- const task = this._tasksQueue[index];
568
- if (!task)
569
- return;
570
- const { call, type } = task;
571
- this._scopeId = call.id;
572
- this._isNested = true;
573
- (_a = this._nestedTime)[_b = call.id] ?? (_a[_b] = 0);
574
- this._nestedTime[call.id] += call.ms;
575
- if (type === "timeout") {
576
- this.removeTask(index);
577
- } else if (type === "interval") {
578
- call.nestedMs += call.ms;
579
- const nestedMs = call.nestedMs;
580
- const closestTask = this._tasksQueue.findIndex(({ type: type2, call: call2 }) => type2 === "interval" && call2.nestedMs < nestedMs);
581
- if (closestTask !== -1 && closestTask !== index)
582
- this.ensureQueueOrder();
583
- }
584
- call.cb();
585
- this._queueCount++;
586
- }
587
- runQueue() {
588
- let index = 0;
589
- while (this._tasksQueue[index]) {
590
- assertMaxLoop(this._queueCount);
591
- const { call, nested } = this._tasksQueue[index];
592
- if (this._advancedTime && call.nestedMs > this._advancedTime)
593
- break;
594
- if (this._isOnlyPending && nested) {
595
- index++;
596
- continue;
597
- }
598
- this.callQueueItem(index);
599
- }
600
- }
601
- removeTask(index) {
602
- if (index === 0)
603
- this._tasksQueue.shift();
604
- else
605
- this._tasksQueue.splice(index, 1);
606
- }
607
- pushTask(task) {
608
- this._tasksQueue.push(task);
609
- this.ensureQueueOrder();
610
- }
611
- ensureQueueOrder() {
612
- this._tasksQueue.sort((t1, t2) => {
613
- const diff = t1.call.nestedMs - t2.call.nestedMs;
614
- if (diff === 0) {
615
- if (t1.type === "immediate" /* Immediate */ && t2.type !== "immediate" /* Immediate */)
616
- return 1;
617
- return 0;
618
- }
619
- return diff;
620
- });
621
- }
622
- assertMocked() {
623
- assertEvery([
624
- this._isMocked,
625
- this._setTimeout,
626
- this._setInterval,
627
- this._clearTimeout,
628
- this._clearInterval
629
- ], 'timers are not mocked. try calling "vitest.useFakeTimers()" first');
630
- }
631
- }
632
-
633
- class VitestUtils {
634
- constructor() {
635
- this.spyOn = spyOn;
636
- this.fn = fn;
637
- this._timers = new FakeTimers();
638
- this._systemDate = null;
639
- }
640
- useFakeTimers() {
641
- return this._timers.useFakeTimers();
642
- }
643
- useRealTimers() {
644
- return this._timers.useRealTimers();
645
- }
646
- runOnlyPendingTimers() {
647
- return this._timers.runOnlyPendingTimers();
648
- }
649
- runAllTimers() {
650
- return this._timers.runAllTimers();
651
- }
652
- advanceTimersByTime(ms) {
653
- return this._timers.advanceTimersByTime(ms);
654
- }
655
- advanceTimersToNextTimer() {
656
- return this._timers.advanceTimersToNextTimer();
657
- }
658
- getTimerCount() {
659
- return this._timers.getTimerCount();
660
- }
661
- setSystemDate(date) {
662
- this._systemDate = date;
663
- mockdate.set(date);
664
- }
665
- resetSystemDate() {
666
- this._systemDate = null;
667
- mockdate.reset();
668
- }
669
- getSystemDate() {
670
- return this._systemDate || Date.now();
671
- }
672
- mock(path) {
673
- }
674
- unmock(path) {
675
- }
676
- async importActual(path) {
677
- return {};
678
- }
679
- async importMock(path) {
680
- return {};
681
- }
682
- mocked(item, _deep = false) {
683
- return item;
684
- }
685
- isMockFunction(fn2) {
686
- return typeof fn2 === "function" && "__isSpy" in fn2 && fn2.__isSpy;
687
- }
688
- clearAllMocks() {
689
- __vitest__clearMocks__({ clearMocks: true });
690
- spies.forEach((spy) => spy.mockClear());
691
- return this;
692
- }
693
- resetAllMocks() {
694
- __vitest__clearMocks__({ mockReset: true });
695
- spies.forEach((spy) => spy.mockReset());
696
- return this;
697
- }
698
- restoreAllMocks() {
699
- __vitest__clearMocks__({ restoreMocks: true });
700
- spies.forEach((spy) => spy.mockRestore());
701
- return this;
702
- }
703
- }
704
- const vitest = new VitestUtils();
705
- const vi = vitest;
706
-
707
- function toArray(array) {
708
- array = array || [];
709
- if (Array.isArray(array))
710
- return array;
711
- return [array];
712
- }
713
- function notNullish(v) {
714
- return v != null;
715
- }
716
- function slash(str) {
717
- return str.replace(/\\/g, "/");
718
- }
719
- function mergeSlashes(str) {
720
- return str.replace(/\/\//g, "/");
721
- }
722
- const noop = () => {
723
- };
724
- function partitionSuiteChildren(suite) {
725
- let tasksGroup = [];
726
- const tasksGroups = [];
727
- for (const c2 of suite.tasks) {
728
- if (tasksGroup.length === 0 || c2.computeMode === tasksGroup[0].computeMode) {
729
- tasksGroup.push(c2);
730
- } else {
731
- tasksGroups.push(tasksGroup);
732
- tasksGroup = [c2];
733
- }
734
- }
735
- if (tasksGroup.length > 0)
736
- tasksGroups.push(tasksGroup);
737
- return tasksGroups;
738
- }
739
- function interpretOnlyMode(tasks) {
740
- if (tasks.some((t) => t.mode === "only")) {
741
- tasks.forEach((t) => {
742
- if (t.mode === "run")
743
- t.mode = "skip";
744
- else if (t.mode === "only")
745
- t.mode = "run";
746
- });
747
- }
748
- tasks.forEach((t) => {
749
- if (t.type === "suite") {
750
- if (t.mode === "skip")
751
- t.tasks.forEach((c2) => c2.mode === "run" && (c2.mode = "skip"));
752
- else
753
- interpretOnlyMode(t.tasks);
754
- }
755
- });
756
- }
757
- function getTests(suite) {
758
- return toArray(suite).flatMap((s) => s.tasks.flatMap((c2) => c2.type === "test" ? [c2] : getTests(c2)));
759
- }
760
- function getTasks(tasks) {
761
- return toArray(tasks).flatMap((s) => s.type === "test" ? [s] : [s, ...getTasks(s.tasks)]);
762
- }
763
- function getSuites(suite) {
764
- return toArray(suite).flatMap((s) => s.type === "suite" ? [s, ...getSuites(s.tasks)] : []);
765
- }
766
- function hasTests(suite) {
767
- return toArray(suite).some((s) => s.tasks.some((c2) => c2.type === "test" || hasTests(c2)));
768
- }
769
- function hasFailed(suite) {
770
- return toArray(suite).some((s) => {
771
- var _a;
772
- return ((_a = s.result) == null ? void 0 : _a.state) === "fail" || s.type === "suite" && hasFailed(s.tasks);
773
- });
774
- }
775
- function getNames(task) {
776
- const names = [task.name];
777
- let current = task;
778
- while ((current == null ? void 0 : current.suite) || (current == null ? void 0 : current.file)) {
779
- current = current.suite || current.file;
780
- if (current == null ? void 0 : current.name)
781
- names.unshift(current.name);
782
- }
783
- return names;
784
- }
785
- async function ensurePackageInstalled(dependency, promptInstall = !process.env.CI && process.stdout.isTTY) {
786
- if (isPackageExists(dependency))
787
- return true;
788
- console.log(c.red(`${c.inverse(c.red(" MISSING DEP "))} Can not find dependency '${dependency}'
789
- `));
790
- if (!promptInstall)
791
- return false;
792
- const prompts = await import('./index-fa899e66.js').then(function (n) { return n.i; });
793
- const { install } = await prompts.prompt({
794
- type: "confirm",
795
- name: "install",
796
- message: c.reset(`Do you want to install ${c.green(dependency)}?`)
797
- });
798
- if (install) {
799
- await (await import('./index-5d224425.js')).installPackage(dependency, { dev: true });
800
- return true;
801
- }
802
- return false;
803
- }
804
- function clearModuleMocks() {
805
- const { clearMocks, mockReset, restoreMocks } = process.__vitest_worker__.config;
806
- if (restoreMocks)
807
- vi.restoreAllMocks();
808
- else if (mockReset)
809
- vi.resetAllMocks();
810
- else if (clearMocks)
811
- vi.clearAllMocks();
812
- }
813
-
814
- export { hasTests as A, clearModuleMocks as B, getTasks as C, spyOn as a, vi as b, c, slash as d, ensurePackageInstalled as e, fn as f, getNames as g, getTests as h, isAbsolute as i, dirname as j, basename as k, getSuites as l, resolve as m, noop as n, hasFailed as o, notNullish as p, commonjsGlobal as q, relative as r, spies as s, toArray as t, mergeSlashes as u, vitest as v, commonjsRequire as w, index as x, interpretOnlyMode as y, partitionSuiteChildren as z };