vitest 0.21.1 → 0.23.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 +61 -33
- package/dist/browser.d.ts +5 -5
- package/dist/browser.mjs +12 -10
- package/dist/{chunk-api-setup.7a6ba7fb.mjs → chunk-api-setup.5fc06d1d.mjs} +94 -91
- package/dist/chunk-constants.6196597b.mjs +284 -0
- package/dist/chunk-env-node.ceb43f1c.mjs +403 -0
- package/dist/{chunk-install-pkg.6c6dc0c2.mjs → chunk-install-pkg.e081fc1b.mjs} +2 -1
- package/dist/chunk-integrations-coverage.99c020eb.mjs +166 -0
- package/dist/{chunk-integrations-globals.44a8f047.mjs → chunk-integrations-globals.ef598c23.mjs} +8 -9
- package/dist/{chunk-magic-string.efe26975.mjs → chunk-magic-string.56b2b543.mjs} +30 -10
- package/dist/chunk-mock-date.0d86eaa5.mjs +332 -0
- package/dist/chunk-node-git.6f289b0a.mjs +84 -0
- package/dist/{chunk-runtime-chain.98d42d89.mjs → chunk-runtime-chain.2af36ddf.mjs} +507 -172
- package/dist/{chunk-runtime-error.87a2b5a2.mjs → chunk-runtime-error.ed9b4f70.mjs} +208 -76
- package/dist/{chunk-runtime-hooks.453f8858.mjs → chunk-runtime-hooks.75ce0575.mjs} +18 -12
- package/dist/{chunk-runtime-mocker.23b62bfa.mjs → chunk-runtime-mocker.fc76f21d.mjs} +18 -11
- package/dist/{chunk-runtime-rpc.b50ab560.mjs → chunk-runtime-rpc.3fe371e9.mjs} +1 -2
- package/dist/{chunk-utils-source-map.94107ee8.mjs → chunk-utils-source-map.70ee97e1.mjs} +11 -4
- package/dist/{chunk-vite-node-client.fdd9592c.mjs → chunk-vite-node-client.74ebe3d5.mjs} +97 -31
- package/dist/{chunk-vite-node-debug.09afb76f.mjs → chunk-vite-node-debug.2d8a1dc3.mjs} +3 -3
- package/dist/{chunk-vite-node-externalize.27aee038.mjs → chunk-vite-node-externalize.41bf722e.mjs} +644 -222
- package/dist/{chunk-vite-node-utils.f34df9d3.mjs → chunk-vite-node-utils.68573626.mjs} +60 -42
- package/dist/cli-wrapper.mjs +128 -0
- package/dist/cli.mjs +29 -20
- package/dist/config.cjs +5 -2
- package/dist/config.d.ts +8 -4
- package/dist/config.mjs +4 -3
- package/dist/entry.mjs +20 -15
- package/dist/environments.d.ts +23 -0
- package/dist/environments.mjs +3 -0
- package/dist/{global-60f880c6.d.ts → global-ea084c9f.d.ts} +627 -178
- package/dist/{index-4a906fa4.d.ts → index-5f09f4d0.d.ts} +3 -50
- package/dist/index.d.ts +6 -6
- package/dist/index.mjs +7 -6
- package/dist/loader.mjs +3 -3
- package/dist/node.d.ts +5 -4
- package/dist/node.mjs +19 -16
- package/dist/suite.mjs +6 -5
- package/dist/vendor-index.0557b03a.mjs +147 -0
- package/dist/vendor-index.13e3bda3.mjs +61 -0
- package/dist/{chunk-node-git.c2be9c49.mjs → vendor-index.4aeeb598.mjs} +4 -72
- package/dist/{vendor-index.61438b77.mjs → vendor-index.731a22f2.mjs} +1 -61
- package/dist/worker.mjs +20 -18
- package/package.json +19 -16
- package/vitest.mjs +1 -1
- package/dist/chunk-constants.26dc9f85.mjs +0 -38
- package/dist/chunk-defaults.02abff90.mjs +0 -680
- package/dist/chunk-mock-date.bc81a3ac.mjs +0 -555
- package/dist/chunk-utils-global.fa20c2f6.mjs +0 -5
- package/dist/mocker-5e2a8e41.d.ts +0 -3
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { importModule } from 'local-pkg';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
How it works:
|
|
5
|
+
`this.#head` is an instance of `Node` which keeps track of its current value and nests another instance of `Node` that keeps the value that comes after it. When a value is provided to `.enqueue()`, the code needs to iterate through `this.#head`, going deeper and deeper to find the last value. However, iterating through every single item is slow. This problem is solved by saving a reference to the last value as `this.#tail` so that it can reference it to add a new value.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
class Node {
|
|
9
|
+
value;
|
|
10
|
+
next;
|
|
11
|
+
|
|
12
|
+
constructor(value) {
|
|
13
|
+
this.value = value;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
class Queue {
|
|
18
|
+
#head;
|
|
19
|
+
#tail;
|
|
20
|
+
#size;
|
|
21
|
+
|
|
22
|
+
constructor() {
|
|
23
|
+
this.clear();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
enqueue(value) {
|
|
27
|
+
const node = new Node(value);
|
|
28
|
+
|
|
29
|
+
if (this.#head) {
|
|
30
|
+
this.#tail.next = node;
|
|
31
|
+
this.#tail = node;
|
|
32
|
+
} else {
|
|
33
|
+
this.#head = node;
|
|
34
|
+
this.#tail = node;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
this.#size++;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
dequeue() {
|
|
41
|
+
const current = this.#head;
|
|
42
|
+
if (!current) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
this.#head = this.#head.next;
|
|
47
|
+
this.#size--;
|
|
48
|
+
return current.value;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
clear() {
|
|
52
|
+
this.#head = undefined;
|
|
53
|
+
this.#tail = undefined;
|
|
54
|
+
this.#size = 0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
get size() {
|
|
58
|
+
return this.#size;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
* [Symbol.iterator]() {
|
|
62
|
+
let current = this.#head;
|
|
63
|
+
|
|
64
|
+
while (current) {
|
|
65
|
+
yield current.value;
|
|
66
|
+
current = current.next;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function pLimit(concurrency) {
|
|
72
|
+
if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
|
|
73
|
+
throw new TypeError('Expected `concurrency` to be a number from 1 and up');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const queue = new Queue();
|
|
77
|
+
let activeCount = 0;
|
|
78
|
+
|
|
79
|
+
const next = () => {
|
|
80
|
+
activeCount--;
|
|
81
|
+
|
|
82
|
+
if (queue.size > 0) {
|
|
83
|
+
queue.dequeue()();
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const run = async (fn, resolve, args) => {
|
|
88
|
+
activeCount++;
|
|
89
|
+
|
|
90
|
+
const result = (async () => fn(...args))();
|
|
91
|
+
|
|
92
|
+
resolve(result);
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
await result;
|
|
96
|
+
} catch {}
|
|
97
|
+
|
|
98
|
+
next();
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const enqueue = (fn, resolve, args) => {
|
|
102
|
+
queue.enqueue(run.bind(undefined, fn, resolve, args));
|
|
103
|
+
|
|
104
|
+
(async () => {
|
|
105
|
+
// This function needs to wait until the next microtask before comparing
|
|
106
|
+
// `activeCount` to `concurrency`, because `activeCount` is updated asynchronously
|
|
107
|
+
// when the run function is dequeued and called. The comparison in the if-statement
|
|
108
|
+
// needs to happen asynchronously as well to get an up-to-date value for `activeCount`.
|
|
109
|
+
await Promise.resolve();
|
|
110
|
+
|
|
111
|
+
if (activeCount < concurrency && queue.size > 0) {
|
|
112
|
+
queue.dequeue()();
|
|
113
|
+
}
|
|
114
|
+
})();
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const generator = (fn, ...args) => new Promise(resolve => {
|
|
118
|
+
enqueue(fn, resolve, args);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
Object.defineProperties(generator, {
|
|
122
|
+
activeCount: {
|
|
123
|
+
get: () => activeCount,
|
|
124
|
+
},
|
|
125
|
+
pendingCount: {
|
|
126
|
+
get: () => queue.size,
|
|
127
|
+
},
|
|
128
|
+
clearQueue: {
|
|
129
|
+
value: () => {
|
|
130
|
+
queue.clear();
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
return generator;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const CoverageProviderMap = {
|
|
139
|
+
c8: "@vitest/coverage-c8",
|
|
140
|
+
istanbul: "@vitest/coverage-istanbul"
|
|
141
|
+
};
|
|
142
|
+
async function resolveCoverageProvider(provider) {
|
|
143
|
+
if (typeof provider === "string") {
|
|
144
|
+
const pkg = CoverageProviderMap[provider];
|
|
145
|
+
if (!pkg)
|
|
146
|
+
throw new Error(`Unknown coverage provider: ${provider}`);
|
|
147
|
+
return await importModule(pkg);
|
|
148
|
+
} else {
|
|
149
|
+
return provider;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
async function getCoverageProvider(options) {
|
|
153
|
+
if ((options == null ? void 0 : options.enabled) && (options == null ? void 0 : options.provider)) {
|
|
154
|
+
const { getProvider } = await resolveCoverageProvider(options.provider);
|
|
155
|
+
return await getProvider();
|
|
156
|
+
}
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
async function takeCoverageInsideWorker(options) {
|
|
160
|
+
if (options.enabled && options.provider) {
|
|
161
|
+
const { takeCoverage } = await resolveCoverageProvider(options.provider);
|
|
162
|
+
return await (takeCoverage == null ? void 0 : takeCoverage());
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export { CoverageProviderMap as C, getCoverageProvider as g, pLimit as p, takeCoverageInsideWorker as t };
|
package/dist/{chunk-integrations-globals.44a8f047.mjs → chunk-integrations-globals.ef598c23.mjs}
RENAMED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as index } from './chunk-runtime-hooks.
|
|
1
|
+
import { k as globalApis } from './chunk-constants.6196597b.mjs';
|
|
2
|
+
import { i as index } from './chunk-runtime-hooks.75ce0575.mjs';
|
|
3
|
+
import 'tty';
|
|
3
4
|
import 'url';
|
|
4
|
-
import './chunk-mock-date.bc81a3ac.mjs';
|
|
5
5
|
import 'path';
|
|
6
|
-
import '
|
|
7
|
-
import 'local-pkg';
|
|
8
|
-
import './chunk-runtime-chain.98d42d89.mjs';
|
|
6
|
+
import './chunk-runtime-chain.2af36ddf.mjs';
|
|
9
7
|
import 'util';
|
|
8
|
+
import './chunk-mock-date.0d86eaa5.mjs';
|
|
9
|
+
import 'local-pkg';
|
|
10
10
|
import 'chai';
|
|
11
11
|
import './vendor-_commonjsHelpers.4da45ef5.mjs';
|
|
12
|
-
import './chunk-runtime-rpc.
|
|
13
|
-
import './chunk-utils-global.fa20c2f6.mjs';
|
|
12
|
+
import './chunk-runtime-rpc.3fe371e9.mjs';
|
|
14
13
|
import './chunk-utils-timers.b48455ed.mjs';
|
|
15
14
|
import 'fs';
|
|
16
|
-
import './chunk-utils-source-map.
|
|
15
|
+
import './chunk-utils-source-map.70ee97e1.mjs';
|
|
17
16
|
import './spy.mjs';
|
|
18
17
|
import 'tinyspy';
|
|
19
18
|
|
|
@@ -219,15 +219,20 @@ class Chunk {
|
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
if (typeof
|
|
226
|
-
|
|
227
|
-
} else
|
|
228
|
-
|
|
222
|
+
function getBtoa () {
|
|
223
|
+
if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
|
|
224
|
+
return (str) => window.btoa(unescape(encodeURIComponent(str)));
|
|
225
|
+
} else if (typeof Buffer === 'function') {
|
|
226
|
+
return (str) => Buffer.from(str, 'utf-8').toString('base64');
|
|
227
|
+
} else {
|
|
228
|
+
return () => {
|
|
229
|
+
throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
|
|
230
|
+
};
|
|
231
|
+
}
|
|
229
232
|
}
|
|
230
233
|
|
|
234
|
+
const btoa = /*#__PURE__*/ getBtoa();
|
|
235
|
+
|
|
231
236
|
class SourceMap {
|
|
232
237
|
constructor(properties) {
|
|
233
238
|
this.version = 3;
|
|
@@ -419,7 +424,7 @@ class MagicString {
|
|
|
419
424
|
indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
|
|
420
425
|
sourcemapLocations: { writable: true, value: new BitSet() },
|
|
421
426
|
storedNames: { writable: true, value: {} },
|
|
422
|
-
indentStr: { writable: true, value:
|
|
427
|
+
indentStr: { writable: true, value: undefined },
|
|
423
428
|
});
|
|
424
429
|
|
|
425
430
|
this.byStart[0] = chunk;
|
|
@@ -549,7 +554,19 @@ class MagicString {
|
|
|
549
554
|
return new SourceMap(this.generateDecodedMap(options));
|
|
550
555
|
}
|
|
551
556
|
|
|
557
|
+
_ensureindentStr() {
|
|
558
|
+
if (this.indentStr === undefined) {
|
|
559
|
+
this.indentStr = guessIndent(this.original);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
_getRawIndentString() {
|
|
564
|
+
this._ensureindentStr();
|
|
565
|
+
return this.indentStr;
|
|
566
|
+
}
|
|
567
|
+
|
|
552
568
|
getIndentString() {
|
|
569
|
+
this._ensureindentStr();
|
|
553
570
|
return this.indentStr === null ? '\t' : this.indentStr;
|
|
554
571
|
}
|
|
555
572
|
|
|
@@ -561,7 +578,10 @@ class MagicString {
|
|
|
561
578
|
indentStr = undefined;
|
|
562
579
|
}
|
|
563
580
|
|
|
564
|
-
|
|
581
|
+
if (indentStr === undefined) {
|
|
582
|
+
this._ensureindentStr();
|
|
583
|
+
indentStr = this.indentStr || '\t';
|
|
584
|
+
}
|
|
565
585
|
|
|
566
586
|
if (indentStr === '') return this; // noop
|
|
567
587
|
|
|
@@ -1277,7 +1297,7 @@ class Bundle {
|
|
|
1277
1297
|
const indentStringCounts = {};
|
|
1278
1298
|
|
|
1279
1299
|
this.sources.forEach((source) => {
|
|
1280
|
-
const indentStr = source.content.
|
|
1300
|
+
const indentStr = source.content._getRawIndentString();
|
|
1281
1301
|
|
|
1282
1302
|
if (indentStr === null) return;
|
|
1283
1303
|
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { relative } from 'path';
|
|
2
|
+
import { r as relative$1, p as picocolors, E as EXIT_CODE_RESTART } from './chunk-constants.6196597b.mjs';
|
|
3
|
+
import { isPackageExists } from 'local-pkg';
|
|
4
|
+
|
|
5
|
+
const RealDate = Date;
|
|
6
|
+
let now = null;
|
|
7
|
+
class MockDate extends RealDate {
|
|
8
|
+
constructor(y, m, d, h, M, s, ms) {
|
|
9
|
+
super();
|
|
10
|
+
let date;
|
|
11
|
+
switch (arguments.length) {
|
|
12
|
+
case 0:
|
|
13
|
+
if (now !== null)
|
|
14
|
+
date = new RealDate(now.valueOf());
|
|
15
|
+
else
|
|
16
|
+
date = new RealDate();
|
|
17
|
+
break;
|
|
18
|
+
case 1:
|
|
19
|
+
date = new RealDate(y);
|
|
20
|
+
break;
|
|
21
|
+
default:
|
|
22
|
+
d = typeof d === "undefined" ? 1 : d;
|
|
23
|
+
h = h || 0;
|
|
24
|
+
M = M || 0;
|
|
25
|
+
s = s || 0;
|
|
26
|
+
ms = ms || 0;
|
|
27
|
+
date = new RealDate(y, m, d, h, M, s, ms);
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
return date;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
MockDate.UTC = RealDate.UTC;
|
|
34
|
+
MockDate.now = function() {
|
|
35
|
+
return new MockDate().valueOf();
|
|
36
|
+
};
|
|
37
|
+
MockDate.parse = function(dateString) {
|
|
38
|
+
return RealDate.parse(dateString);
|
|
39
|
+
};
|
|
40
|
+
MockDate.toString = function() {
|
|
41
|
+
return RealDate.toString();
|
|
42
|
+
};
|
|
43
|
+
function mockDate(date) {
|
|
44
|
+
const dateObj = new RealDate(date.valueOf());
|
|
45
|
+
if (isNaN(dateObj.getTime()))
|
|
46
|
+
throw new TypeError(`mockdate: The time set is an invalid date: ${date}`);
|
|
47
|
+
globalThis.Date = MockDate;
|
|
48
|
+
now = dateObj.valueOf();
|
|
49
|
+
}
|
|
50
|
+
function resetDate() {
|
|
51
|
+
globalThis.Date = RealDate;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function isFinalObj(obj) {
|
|
55
|
+
return obj === Object.prototype || obj === Function.prototype || obj === RegExp.prototype;
|
|
56
|
+
}
|
|
57
|
+
function collectOwnProperties(obj, collector) {
|
|
58
|
+
const collect = typeof collector === "function" ? collector : (key) => collector.add(key);
|
|
59
|
+
Object.getOwnPropertyNames(obj).forEach(collect);
|
|
60
|
+
Object.getOwnPropertySymbols(obj).forEach(collect);
|
|
61
|
+
}
|
|
62
|
+
function getAllMockableProperties(obj) {
|
|
63
|
+
const allProps = /* @__PURE__ */ new Set();
|
|
64
|
+
let curr = obj;
|
|
65
|
+
do {
|
|
66
|
+
if (isFinalObj(curr))
|
|
67
|
+
break;
|
|
68
|
+
collectOwnProperties(curr, (key) => {
|
|
69
|
+
const descriptor = Object.getOwnPropertyDescriptor(curr, key);
|
|
70
|
+
if (descriptor)
|
|
71
|
+
allProps.add({ key, descriptor });
|
|
72
|
+
});
|
|
73
|
+
} while (curr = Object.getPrototypeOf(curr));
|
|
74
|
+
return Array.from(allProps);
|
|
75
|
+
}
|
|
76
|
+
function notNullish(v) {
|
|
77
|
+
return v != null;
|
|
78
|
+
}
|
|
79
|
+
function slash(str) {
|
|
80
|
+
return str.replace(/\\/g, "/");
|
|
81
|
+
}
|
|
82
|
+
function mergeSlashes(str) {
|
|
83
|
+
return str.replace(/\/\//g, "/");
|
|
84
|
+
}
|
|
85
|
+
const noop = () => {
|
|
86
|
+
};
|
|
87
|
+
function getType(value) {
|
|
88
|
+
return Object.prototype.toString.apply(value).slice(8, -1);
|
|
89
|
+
}
|
|
90
|
+
function getOwnProperties(obj) {
|
|
91
|
+
const ownProps = /* @__PURE__ */ new Set();
|
|
92
|
+
if (isFinalObj(obj))
|
|
93
|
+
return [];
|
|
94
|
+
collectOwnProperties(obj, ownProps);
|
|
95
|
+
return Array.from(ownProps);
|
|
96
|
+
}
|
|
97
|
+
function deepClone(val) {
|
|
98
|
+
const seen = /* @__PURE__ */ new WeakMap();
|
|
99
|
+
return clone(val, seen);
|
|
100
|
+
}
|
|
101
|
+
function clone(val, seen) {
|
|
102
|
+
let k, out;
|
|
103
|
+
if (seen.has(val))
|
|
104
|
+
return seen.get(val);
|
|
105
|
+
if (Array.isArray(val)) {
|
|
106
|
+
out = Array(k = val.length);
|
|
107
|
+
seen.set(val, out);
|
|
108
|
+
while (k--)
|
|
109
|
+
out[k] = clone(val[k], seen);
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
112
|
+
if (Object.prototype.toString.call(val) === "[object Object]") {
|
|
113
|
+
out = Object.create(Object.getPrototypeOf(val));
|
|
114
|
+
seen.set(val, out);
|
|
115
|
+
const props = getOwnProperties(val);
|
|
116
|
+
for (const k2 of props)
|
|
117
|
+
out[k2] = clone(val[k2], seen);
|
|
118
|
+
return out;
|
|
119
|
+
}
|
|
120
|
+
return val;
|
|
121
|
+
}
|
|
122
|
+
function toArray(array) {
|
|
123
|
+
if (array === null || array === void 0)
|
|
124
|
+
array = [];
|
|
125
|
+
if (Array.isArray(array))
|
|
126
|
+
return array;
|
|
127
|
+
return [array];
|
|
128
|
+
}
|
|
129
|
+
const toString = (v) => Object.prototype.toString.call(v);
|
|
130
|
+
const isPlainObject = (val) => toString(val) === "[object Object]" && (!val.constructor || val.constructor.name === "Object");
|
|
131
|
+
function isObject(item) {
|
|
132
|
+
return item != null && typeof item === "object" && !Array.isArray(item);
|
|
133
|
+
}
|
|
134
|
+
function deepMerge(target, ...sources) {
|
|
135
|
+
if (!sources.length)
|
|
136
|
+
return target;
|
|
137
|
+
const source = sources.shift();
|
|
138
|
+
if (source === void 0)
|
|
139
|
+
return target;
|
|
140
|
+
if (isMergeableObject(target) && isMergeableObject(source)) {
|
|
141
|
+
Object.keys(source).forEach((key) => {
|
|
142
|
+
if (isMergeableObject(source[key])) {
|
|
143
|
+
if (!target[key])
|
|
144
|
+
target[key] = {};
|
|
145
|
+
deepMerge(target[key], source[key]);
|
|
146
|
+
} else {
|
|
147
|
+
target[key] = source[key];
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return deepMerge(target, ...sources);
|
|
152
|
+
}
|
|
153
|
+
function isMergeableObject(item) {
|
|
154
|
+
return isPlainObject(item) && !Array.isArray(item);
|
|
155
|
+
}
|
|
156
|
+
function assertTypes(value, name, types) {
|
|
157
|
+
const receivedType = typeof value;
|
|
158
|
+
const pass = types.includes(receivedType);
|
|
159
|
+
if (!pass)
|
|
160
|
+
throw new TypeError(`${name} value must be ${types.join(" or ")}, received "${receivedType}"`);
|
|
161
|
+
}
|
|
162
|
+
function stdout() {
|
|
163
|
+
return console._stdout || process.stdout;
|
|
164
|
+
}
|
|
165
|
+
function random(seed) {
|
|
166
|
+
const x = Math.sin(seed++) * 1e4;
|
|
167
|
+
return x - Math.floor(x);
|
|
168
|
+
}
|
|
169
|
+
function shuffle(array, seed = RealDate.now()) {
|
|
170
|
+
let length = array.length;
|
|
171
|
+
while (length) {
|
|
172
|
+
const index = Math.floor(random(seed) * length--);
|
|
173
|
+
const previous = array[length];
|
|
174
|
+
array[length] = array[index];
|
|
175
|
+
array[index] = previous;
|
|
176
|
+
++seed;
|
|
177
|
+
}
|
|
178
|
+
return array;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function isAtomTest(s) {
|
|
182
|
+
return s.type === "test" || s.type === "benchmark";
|
|
183
|
+
}
|
|
184
|
+
function getTests(suite) {
|
|
185
|
+
return toArray(suite).flatMap((s) => isAtomTest(s) ? [s] : s.tasks.flatMap((c) => isAtomTest(c) ? [c] : getTests(c)));
|
|
186
|
+
}
|
|
187
|
+
function getSuites(suite) {
|
|
188
|
+
return toArray(suite).flatMap((s) => s.type === "suite" ? [s, ...getSuites(s.tasks)] : []);
|
|
189
|
+
}
|
|
190
|
+
function hasTests(suite) {
|
|
191
|
+
return toArray(suite).some((s) => s.tasks.some((c) => isAtomTest(c) || hasTests(c)));
|
|
192
|
+
}
|
|
193
|
+
function hasFailed(suite) {
|
|
194
|
+
return toArray(suite).some((s) => {
|
|
195
|
+
var _a;
|
|
196
|
+
return ((_a = s.result) == null ? void 0 : _a.state) === "fail" || s.type === "suite" && hasFailed(s.tasks);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
function hasFailedSnapshot(suite) {
|
|
200
|
+
return getTests(suite).some((s) => {
|
|
201
|
+
var _a, _b;
|
|
202
|
+
const message = (_b = (_a = s.result) == null ? void 0 : _a.error) == null ? void 0 : _b.message;
|
|
203
|
+
return message == null ? void 0 : message.match(/Snapshot .* mismatched/);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
function getNames(task) {
|
|
207
|
+
const names = [task.name];
|
|
208
|
+
let current = task;
|
|
209
|
+
while ((current == null ? void 0 : current.suite) || (current == null ? void 0 : current.file)) {
|
|
210
|
+
current = current.suite || current.file;
|
|
211
|
+
if (current == null ? void 0 : current.name)
|
|
212
|
+
names.unshift(current.name);
|
|
213
|
+
}
|
|
214
|
+
return names;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function getWorkerState() {
|
|
218
|
+
return globalThis.__vitest_worker__;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
var _a;
|
|
222
|
+
const isNode = typeof process < "u" && typeof process.stdout < "u" && !((_a = process.versions) == null ? void 0 : _a.deno) && !globalThis.window;
|
|
223
|
+
const isBrowser = typeof window !== "undefined";
|
|
224
|
+
const isWindows = isNode && process.platform === "win32";
|
|
225
|
+
const getRunMode = () => getWorkerState().config.mode;
|
|
226
|
+
const isRunningInTest = () => getRunMode() === "test";
|
|
227
|
+
const isRunningInBenchmark = () => getRunMode() === "benchmark";
|
|
228
|
+
const relativePath = isBrowser ? relative : relative$1;
|
|
229
|
+
function partitionSuiteChildren(suite) {
|
|
230
|
+
let tasksGroup = [];
|
|
231
|
+
const tasksGroups = [];
|
|
232
|
+
for (const c2 of suite.tasks) {
|
|
233
|
+
if (tasksGroup.length === 0 || c2.concurrent === tasksGroup[0].concurrent) {
|
|
234
|
+
tasksGroup.push(c2);
|
|
235
|
+
} else {
|
|
236
|
+
tasksGroups.push(tasksGroup);
|
|
237
|
+
tasksGroup = [c2];
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (tasksGroup.length > 0)
|
|
241
|
+
tasksGroups.push(tasksGroup);
|
|
242
|
+
return tasksGroups;
|
|
243
|
+
}
|
|
244
|
+
function resetModules(modules, resetMocks = false) {
|
|
245
|
+
const skipPaths = [
|
|
246
|
+
/\/vitest\/dist\//,
|
|
247
|
+
/vitest-virtual-\w+\/dist/,
|
|
248
|
+
/@vitest\/dist/,
|
|
249
|
+
...!resetMocks ? [/^mock:/] : []
|
|
250
|
+
];
|
|
251
|
+
modules.forEach((_, path) => {
|
|
252
|
+
if (skipPaths.some((re) => re.test(path)))
|
|
253
|
+
return;
|
|
254
|
+
modules.delete(path);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
function getFullName(task) {
|
|
258
|
+
return getNames(task).join(picocolors.exports.dim(" > "));
|
|
259
|
+
}
|
|
260
|
+
async function ensurePackageInstalled(dependency, root) {
|
|
261
|
+
if (isPackageExists(dependency, { paths: [root] }))
|
|
262
|
+
return true;
|
|
263
|
+
const promptInstall = !process.env.CI && process.stdout.isTTY;
|
|
264
|
+
process.stderr.write(picocolors.exports.red(`${picocolors.exports.inverse(picocolors.exports.red(" MISSING DEP "))} Can not find dependency '${dependency}'
|
|
265
|
+
|
|
266
|
+
`));
|
|
267
|
+
if (!promptInstall)
|
|
268
|
+
return false;
|
|
269
|
+
const prompts = await import('./vendor-index.ae96af6e.mjs').then(function (n) { return n.i; });
|
|
270
|
+
const { install } = await prompts.prompt({
|
|
271
|
+
type: "confirm",
|
|
272
|
+
name: "install",
|
|
273
|
+
message: picocolors.exports.reset(`Do you want to install ${picocolors.exports.green(dependency)}?`)
|
|
274
|
+
});
|
|
275
|
+
if (install) {
|
|
276
|
+
await (await import('./chunk-install-pkg.e081fc1b.mjs')).installPackage(dependency, { dev: true });
|
|
277
|
+
process.stderr.write(picocolors.exports.yellow(`
|
|
278
|
+
Package ${dependency} installed, re-run the command to start.
|
|
279
|
+
`));
|
|
280
|
+
process.exit(EXIT_CODE_RESTART);
|
|
281
|
+
return true;
|
|
282
|
+
}
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
function getCallLastIndex(code) {
|
|
286
|
+
let charIndex = -1;
|
|
287
|
+
let inString = null;
|
|
288
|
+
let startedBracers = 0;
|
|
289
|
+
let endedBracers = 0;
|
|
290
|
+
let beforeChar = null;
|
|
291
|
+
while (charIndex <= code.length) {
|
|
292
|
+
beforeChar = code[charIndex];
|
|
293
|
+
charIndex++;
|
|
294
|
+
const char = code[charIndex];
|
|
295
|
+
const isCharString = char === '"' || char === "'" || char === "`";
|
|
296
|
+
if (isCharString && beforeChar !== "\\") {
|
|
297
|
+
if (inString === char)
|
|
298
|
+
inString = null;
|
|
299
|
+
else if (!inString)
|
|
300
|
+
inString = char;
|
|
301
|
+
}
|
|
302
|
+
if (!inString) {
|
|
303
|
+
if (char === "(")
|
|
304
|
+
startedBracers++;
|
|
305
|
+
if (char === ")")
|
|
306
|
+
endedBracers++;
|
|
307
|
+
}
|
|
308
|
+
if (startedBracers && endedBracers && startedBracers === endedBracers)
|
|
309
|
+
return charIndex;
|
|
310
|
+
}
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
isNode ? relative$1 : relative;
|
|
314
|
+
class AggregateErrorPonyfill extends Error {
|
|
315
|
+
constructor(errors, message = "") {
|
|
316
|
+
super(message);
|
|
317
|
+
this.errors = [...errors];
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
function createDefer() {
|
|
321
|
+
let resolve2 = null;
|
|
322
|
+
let reject = null;
|
|
323
|
+
const p = new Promise((_resolve, _reject) => {
|
|
324
|
+
resolve2 = _resolve;
|
|
325
|
+
reject = _reject;
|
|
326
|
+
});
|
|
327
|
+
p.resolve = resolve2;
|
|
328
|
+
p.reject = reject;
|
|
329
|
+
return p;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
export { AggregateErrorPonyfill as A, hasFailedSnapshot as B, getSuites as C, deepMerge as D, ensurePackageInstalled as E, stdout as F, isWindows as G, mergeSlashes as H, getAllMockableProperties as I, RealDate as R, resetModules as a, getCallLastIndex as b, getNames as c, assertTypes as d, getFullName as e, isRunningInTest as f, getWorkerState as g, isRunningInBenchmark as h, isObject as i, notNullish as j, deepClone as k, getType as l, mockDate as m, noop as n, isNode as o, relativePath as p, isBrowser as q, resetDate as r, slash as s, toArray as t, partitionSuiteChildren as u, shuffle as v, hasTests as w, hasFailed as x, createDefer as y, getTests as z };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { a as resolve } from './chunk-constants.6196597b.mjs';
|
|
2
|
+
import { e as execa } from './vendor-index.4aeeb598.mjs';
|
|
3
|
+
import 'tty';
|
|
4
|
+
import 'url';
|
|
5
|
+
import 'path';
|
|
6
|
+
import 'buffer';
|
|
7
|
+
import 'child_process';
|
|
8
|
+
import 'process';
|
|
9
|
+
import './vendor-index.62ce5c33.mjs';
|
|
10
|
+
import './vendor-_commonjsHelpers.4da45ef5.mjs';
|
|
11
|
+
import 'fs';
|
|
12
|
+
import 'stream';
|
|
13
|
+
import 'util';
|
|
14
|
+
import 'os';
|
|
15
|
+
import './vendor-index.731a22f2.mjs';
|
|
16
|
+
import 'assert';
|
|
17
|
+
import 'events';
|
|
18
|
+
|
|
19
|
+
class VitestGit {
|
|
20
|
+
constructor(cwd) {
|
|
21
|
+
this.cwd = cwd;
|
|
22
|
+
}
|
|
23
|
+
async resolveFilesWithGitCommand(args) {
|
|
24
|
+
let result;
|
|
25
|
+
try {
|
|
26
|
+
result = await execa("git", args, { cwd: this.root });
|
|
27
|
+
} catch (e) {
|
|
28
|
+
e.message = e.stderr;
|
|
29
|
+
throw e;
|
|
30
|
+
}
|
|
31
|
+
return result.stdout.split("\n").filter((s) => s !== "").map((changedPath) => resolve(this.root, changedPath));
|
|
32
|
+
}
|
|
33
|
+
async findChangedFiles(options) {
|
|
34
|
+
const root = await this.getRoot(this.cwd);
|
|
35
|
+
if (!root)
|
|
36
|
+
return null;
|
|
37
|
+
this.root = root;
|
|
38
|
+
const changedSince = options.changedSince;
|
|
39
|
+
if (typeof changedSince === "string") {
|
|
40
|
+
const [committed, staged2, unstaged2] = await Promise.all([
|
|
41
|
+
this.getFilesSince(changedSince),
|
|
42
|
+
this.getStagedFiles(),
|
|
43
|
+
this.getUnstagedFiles()
|
|
44
|
+
]);
|
|
45
|
+
return [...committed, ...staged2, ...unstaged2];
|
|
46
|
+
}
|
|
47
|
+
const [staged, unstaged] = await Promise.all([
|
|
48
|
+
this.getStagedFiles(),
|
|
49
|
+
this.getUnstagedFiles()
|
|
50
|
+
]);
|
|
51
|
+
return [...staged, ...unstaged];
|
|
52
|
+
}
|
|
53
|
+
getFilesSince(hash) {
|
|
54
|
+
return this.resolveFilesWithGitCommand(
|
|
55
|
+
["diff", "--name-only", `${hash}...HEAD`]
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
getStagedFiles() {
|
|
59
|
+
return this.resolveFilesWithGitCommand(
|
|
60
|
+
["diff", "--cached", "--name-only"]
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
getUnstagedFiles() {
|
|
64
|
+
return this.resolveFilesWithGitCommand(
|
|
65
|
+
[
|
|
66
|
+
"ls-files",
|
|
67
|
+
"--other",
|
|
68
|
+
"--modified",
|
|
69
|
+
"--exclude-standard"
|
|
70
|
+
]
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
async getRoot(cwd) {
|
|
74
|
+
const options = ["rev-parse", "--show-cdup"];
|
|
75
|
+
try {
|
|
76
|
+
const result = await execa("git", options, { cwd });
|
|
77
|
+
return resolve(cwd, result.stdout);
|
|
78
|
+
} catch {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export { VitestGit };
|