vitest 0.15.2 → 0.17.1
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/{chunk-api-setup.8cd5e92a.mjs → chunk-api-setup.c728e251.mjs} +4 -4
- package/dist/{chunk-constants.7b9cfc82.mjs → chunk-constants.27550afb.mjs} +8 -2
- package/dist/chunk-env-node.aa51c4cc.mjs +675 -0
- package/dist/{chunk-install-pkg.3fa50769.mjs → chunk-install-pkg.6f5930c3.mjs} +1 -1
- package/dist/{chunk-integrations-globals.d0c363a6.mjs → chunk-integrations-globals.3df36e26.mjs} +8 -8
- package/dist/{chunk-runtime-chain.7103058b.mjs → chunk-runtime-chain.6d23d202.mjs} +55 -188
- package/dist/{chunk-runtime-mocker.d3ca0a4e.mjs → chunk-runtime-mocker.34b9d585.mjs} +36 -62
- package/dist/{chunk-runtime-rpc.5e78af38.mjs → chunk-runtime-rpc.d986adb9.mjs} +1 -1
- package/dist/{chunk-utils-global.79a8b1cc.mjs → chunk-utils-global.4828c2e2.mjs} +66 -2
- package/dist/{chunk-utils-source-map.2556cba8.mjs → chunk-utils-source-map.a9047343.mjs} +9 -23
- package/dist/{chunk-vite-node-externalize.0ec89ad1.mjs → chunk-vite-node-externalize.0fc8ed68.mjs} +242 -206
- package/dist/{chunk-vite-node-utils.1bbdb2c1.mjs → chunk-vite-node-utils.0f776286.mjs} +29 -14
- package/dist/cli.mjs +12 -12
- package/dist/config.cjs +5 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.mjs +5 -1
- package/dist/entry.mjs +8 -8
- package/dist/index.d.ts +201 -24
- package/dist/index.mjs +4 -4
- package/dist/node.d.ts +187 -20
- package/dist/node.mjs +13 -13
- package/dist/{vendor-entry.efeeaa5c.mjs → vendor-entry.1ad8a08d.mjs} +18 -424
- package/dist/{vendor-index.e5dc6622.mjs → vendor-index.a2a385d8.mjs} +0 -0
- package/dist/worker.mjs +12 -11
- package/package.json +10 -5
- package/dist/chunk-defaults.dc6dc23d.mjs +0 -302
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
import { existsSync, promises } from 'fs';
|
|
2
|
-
import { createRequire } from 'module';
|
|
3
|
-
import { pathToFileURL } from 'url';
|
|
4
|
-
import { C as toArray, m as resolve } from './chunk-utils-global.79a8b1cc.mjs';
|
|
5
|
-
|
|
6
|
-
/*
|
|
7
|
-
How it works:
|
|
8
|
-
`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.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
class Node {
|
|
12
|
-
value;
|
|
13
|
-
next;
|
|
14
|
-
|
|
15
|
-
constructor(value) {
|
|
16
|
-
this.value = value;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
class Queue {
|
|
21
|
-
#head;
|
|
22
|
-
#tail;
|
|
23
|
-
#size;
|
|
24
|
-
|
|
25
|
-
constructor() {
|
|
26
|
-
this.clear();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
enqueue(value) {
|
|
30
|
-
const node = new Node(value);
|
|
31
|
-
|
|
32
|
-
if (this.#head) {
|
|
33
|
-
this.#tail.next = node;
|
|
34
|
-
this.#tail = node;
|
|
35
|
-
} else {
|
|
36
|
-
this.#head = node;
|
|
37
|
-
this.#tail = node;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
this.#size++;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
dequeue() {
|
|
44
|
-
const current = this.#head;
|
|
45
|
-
if (!current) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
this.#head = this.#head.next;
|
|
50
|
-
this.#size--;
|
|
51
|
-
return current.value;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
clear() {
|
|
55
|
-
this.#head = undefined;
|
|
56
|
-
this.#tail = undefined;
|
|
57
|
-
this.#size = 0;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
get size() {
|
|
61
|
-
return this.#size;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
* [Symbol.iterator]() {
|
|
65
|
-
let current = this.#head;
|
|
66
|
-
|
|
67
|
-
while (current) {
|
|
68
|
-
yield current.value;
|
|
69
|
-
current = current.next;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function pLimit(concurrency) {
|
|
75
|
-
if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
|
|
76
|
-
throw new TypeError('Expected `concurrency` to be a number from 1 and up');
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const queue = new Queue();
|
|
80
|
-
let activeCount = 0;
|
|
81
|
-
|
|
82
|
-
const next = () => {
|
|
83
|
-
activeCount--;
|
|
84
|
-
|
|
85
|
-
if (queue.size > 0) {
|
|
86
|
-
queue.dequeue()();
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const run = async (fn, resolve, args) => {
|
|
91
|
-
activeCount++;
|
|
92
|
-
|
|
93
|
-
const result = (async () => fn(...args))();
|
|
94
|
-
|
|
95
|
-
resolve(result);
|
|
96
|
-
|
|
97
|
-
try {
|
|
98
|
-
await result;
|
|
99
|
-
} catch {}
|
|
100
|
-
|
|
101
|
-
next();
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
const enqueue = (fn, resolve, args) => {
|
|
105
|
-
queue.enqueue(run.bind(undefined, fn, resolve, args));
|
|
106
|
-
|
|
107
|
-
(async () => {
|
|
108
|
-
// This function needs to wait until the next microtask before comparing
|
|
109
|
-
// `activeCount` to `concurrency`, because `activeCount` is updated asynchronously
|
|
110
|
-
// when the run function is dequeued and called. The comparison in the if-statement
|
|
111
|
-
// needs to happen asynchronously as well to get an up-to-date value for `activeCount`.
|
|
112
|
-
await Promise.resolve();
|
|
113
|
-
|
|
114
|
-
if (activeCount < concurrency && queue.size > 0) {
|
|
115
|
-
queue.dequeue()();
|
|
116
|
-
}
|
|
117
|
-
})();
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
const generator = (fn, ...args) => new Promise(resolve => {
|
|
121
|
-
enqueue(fn, resolve, args);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
Object.defineProperties(generator, {
|
|
125
|
-
activeCount: {
|
|
126
|
-
get: () => activeCount,
|
|
127
|
-
},
|
|
128
|
-
pendingCount: {
|
|
129
|
-
get: () => queue.size,
|
|
130
|
-
},
|
|
131
|
-
clearQueue: {
|
|
132
|
-
value: () => {
|
|
133
|
-
queue.clear();
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
return generator;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const defaultInclude = ["**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"];
|
|
142
|
-
const defaultExclude = ["**/node_modules/**", "**/dist/**", "**/cypress/**", "**/.{idea,git,cache,output,temp}/**"];
|
|
143
|
-
const defaultCoverageExcludes = [
|
|
144
|
-
"coverage/**",
|
|
145
|
-
"packages/*/test{,s}/**",
|
|
146
|
-
"**/*.d.ts",
|
|
147
|
-
"cypress/**",
|
|
148
|
-
"test{,s}/**",
|
|
149
|
-
"test{,-*}.{js,cjs,mjs,ts,tsx,jsx}",
|
|
150
|
-
"**/*{.,-}test.{js,cjs,mjs,ts,tsx,jsx}",
|
|
151
|
-
"**/__tests__/**",
|
|
152
|
-
"**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc}.config.{js,cjs,mjs,ts}",
|
|
153
|
-
"**/.{eslint,mocha,prettier}rc.{js,cjs,yml}"
|
|
154
|
-
];
|
|
155
|
-
const coverageConfigDefaults = {
|
|
156
|
-
enabled: false,
|
|
157
|
-
clean: true,
|
|
158
|
-
cleanOnRerun: false,
|
|
159
|
-
reportsDirectory: "./coverage",
|
|
160
|
-
excludeNodeModules: true,
|
|
161
|
-
exclude: defaultCoverageExcludes,
|
|
162
|
-
reporter: ["text", "html"],
|
|
163
|
-
allowExternal: false,
|
|
164
|
-
extension: [".js", ".cjs", ".mjs", ".ts", ".tsx", ".jsx", ".vue", ".svelte"]
|
|
165
|
-
};
|
|
166
|
-
const fakeTimersDefaults = {
|
|
167
|
-
loopLimit: 1e4,
|
|
168
|
-
shouldClearNativeTimers: true,
|
|
169
|
-
toFake: [
|
|
170
|
-
"setTimeout",
|
|
171
|
-
"clearTimeout",
|
|
172
|
-
"setInterval",
|
|
173
|
-
"clearInterval",
|
|
174
|
-
"setImmediate",
|
|
175
|
-
"clearImmediate",
|
|
176
|
-
"Date"
|
|
177
|
-
]
|
|
178
|
-
};
|
|
179
|
-
const config = {
|
|
180
|
-
allowOnly: !process.env.CI,
|
|
181
|
-
watch: !process.env.CI,
|
|
182
|
-
globals: false,
|
|
183
|
-
environment: "node",
|
|
184
|
-
threads: true,
|
|
185
|
-
clearMocks: false,
|
|
186
|
-
restoreMocks: false,
|
|
187
|
-
mockReset: false,
|
|
188
|
-
include: defaultInclude,
|
|
189
|
-
exclude: defaultExclude,
|
|
190
|
-
testTimeout: 5e3,
|
|
191
|
-
hookTimeout: 1e4,
|
|
192
|
-
isolate: true,
|
|
193
|
-
watchExclude: ["**/node_modules/**", "**/dist/**"],
|
|
194
|
-
forceRerunTriggers: [],
|
|
195
|
-
update: false,
|
|
196
|
-
reporters: [],
|
|
197
|
-
silent: false,
|
|
198
|
-
api: false,
|
|
199
|
-
ui: false,
|
|
200
|
-
uiBase: "/__vitest__/",
|
|
201
|
-
open: true,
|
|
202
|
-
css: {
|
|
203
|
-
include: [/\.module\./]
|
|
204
|
-
},
|
|
205
|
-
coverage: coverageConfigDefaults,
|
|
206
|
-
fakeTimers: fakeTimersDefaults,
|
|
207
|
-
maxConcurrency: 5
|
|
208
|
-
};
|
|
209
|
-
const configDefaults = Object.freeze(config);
|
|
210
|
-
|
|
211
|
-
var __defProp = Object.defineProperty;
|
|
212
|
-
var __defProps = Object.defineProperties;
|
|
213
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
214
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
215
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
216
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
217
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
218
|
-
var __spreadValues = (a, b) => {
|
|
219
|
-
for (var prop in b || (b = {}))
|
|
220
|
-
if (__hasOwnProp.call(b, prop))
|
|
221
|
-
__defNormalProp(a, prop, b[prop]);
|
|
222
|
-
if (__getOwnPropSymbols)
|
|
223
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
224
|
-
if (__propIsEnum.call(b, prop))
|
|
225
|
-
__defNormalProp(a, prop, b[prop]);
|
|
226
|
-
}
|
|
227
|
-
return a;
|
|
228
|
-
};
|
|
229
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
230
|
-
function resolveC8Options(options, root) {
|
|
231
|
-
const resolved = __spreadValues(__spreadValues({}, configDefaults.coverage), options);
|
|
232
|
-
resolved.reporter = toArray(resolved.reporter);
|
|
233
|
-
resolved.reportsDirectory = resolve(root, resolved.reportsDirectory);
|
|
234
|
-
resolved.tempDirectory = process.env.NODE_V8_COVERAGE || resolve(resolved.reportsDirectory, "tmp");
|
|
235
|
-
return resolved;
|
|
236
|
-
}
|
|
237
|
-
async function cleanCoverage(options, clean = true) {
|
|
238
|
-
if (clean && existsSync(options.reportsDirectory))
|
|
239
|
-
await promises.rm(options.reportsDirectory, { recursive: true, force: true });
|
|
240
|
-
if (!existsSync(options.tempDirectory))
|
|
241
|
-
await promises.mkdir(options.tempDirectory, { recursive: true });
|
|
242
|
-
}
|
|
243
|
-
const require2 = createRequire(import.meta.url);
|
|
244
|
-
function takeCoverage() {
|
|
245
|
-
const v8 = require2("v8");
|
|
246
|
-
if (v8.takeCoverage == null)
|
|
247
|
-
console.warn("[Vitest] takeCoverage is not available in this NodeJs version.\nCoverage could be incomplete. Update to NodeJs 14.18.");
|
|
248
|
-
else
|
|
249
|
-
v8.takeCoverage();
|
|
250
|
-
}
|
|
251
|
-
async function reportCoverage(ctx) {
|
|
252
|
-
takeCoverage();
|
|
253
|
-
const createReport = require2("c8/lib/report");
|
|
254
|
-
const report = createReport(ctx.config.coverage);
|
|
255
|
-
const sourceMapMeta = {};
|
|
256
|
-
await Promise.all(Array.from(ctx.vitenode.fetchCache.entries()).filter((i) => !i[0].includes("/node_modules/")).map(async ([file, { result }]) => {
|
|
257
|
-
const map = result.map;
|
|
258
|
-
if (!map)
|
|
259
|
-
return;
|
|
260
|
-
const url = pathToFileURL(file).href;
|
|
261
|
-
let code;
|
|
262
|
-
try {
|
|
263
|
-
code = (await promises.readFile(file)).toString();
|
|
264
|
-
} catch {
|
|
265
|
-
}
|
|
266
|
-
const sources = [url];
|
|
267
|
-
sourceMapMeta[url] = {
|
|
268
|
-
source: result.code,
|
|
269
|
-
map: __spreadProps(__spreadValues({
|
|
270
|
-
sourcesContent: code ? [code] : void 0
|
|
271
|
-
}, map), {
|
|
272
|
-
sources
|
|
273
|
-
})
|
|
274
|
-
};
|
|
275
|
-
}));
|
|
276
|
-
const offset = 224;
|
|
277
|
-
report._getSourceMap = (coverage) => {
|
|
278
|
-
const path = pathToFileURL(coverage.url).href;
|
|
279
|
-
const data = sourceMapMeta[path];
|
|
280
|
-
if (!data)
|
|
281
|
-
return {};
|
|
282
|
-
return {
|
|
283
|
-
sourceMap: {
|
|
284
|
-
sourcemap: data.map
|
|
285
|
-
},
|
|
286
|
-
source: Array(offset).fill(".").join("") + data.source
|
|
287
|
-
};
|
|
288
|
-
};
|
|
289
|
-
await report.run();
|
|
290
|
-
if (ctx.config.coverage.enabled) {
|
|
291
|
-
if (ctx.config.coverage["100"]) {
|
|
292
|
-
ctx.config.coverage.lines = 100;
|
|
293
|
-
ctx.config.coverage.functions = 100;
|
|
294
|
-
ctx.config.coverage.branches = 100;
|
|
295
|
-
ctx.config.coverage.statements = 100;
|
|
296
|
-
}
|
|
297
|
-
const { checkCoverages } = require2("c8/lib/commands/check-coverage");
|
|
298
|
-
await checkCoverages(ctx.config.coverage, report);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
export { cleanCoverage as a, reportCoverage as b, configDefaults as c, pLimit as p, resolveC8Options as r, takeCoverage as t };
|