vitest 0.25.8 → 0.26.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.
Files changed (45) hide show
  1. package/LICENSE.md +0 -142
  2. package/browser.d.ts +1 -0
  3. package/dist/browser.d.ts +8 -5
  4. package/dist/browser.js +17 -16
  5. package/dist/{chunk-api-setup.dc71e384.js → chunk-api-setup.adeab271.js} +45 -46
  6. package/dist/{chunk-env-node.67948209.js → chunk-env-node.b3664da2.js} +1 -1
  7. package/dist/{chunk-install-pkg.579a5a27.js → chunk-install-pkg.6dd2bae6.js} +19 -19
  8. package/dist/chunk-integrations-globals.96914902.js +27 -0
  9. package/dist/{chunk-node-git.5a1b1656.js → chunk-node-git.a90c0582.js} +10 -6
  10. package/dist/{chunk-runtime-chain.f86e5250.js → chunk-runtime-chain.4cd984be.js} +8 -8
  11. package/dist/{chunk-runtime-error.616e92ca.js → chunk-runtime-error.f5c8aaf2.js} +10 -8
  12. package/dist/{chunk-runtime-mocker.99b910d0.js → chunk-runtime-mocker.3fa602ba.js} +73 -65
  13. package/dist/{chunk-runtime-rpc.42aebbb9.js → chunk-runtime-rpc.54d72169.js} +2 -2
  14. package/dist/{chunk-runtime-setup.5398e2c4.js → chunk-runtime-setup.9cdedce6.js} +21 -34
  15. package/dist/{chunk-vite-node-externalize.b9495318.js → chunk-snapshot-manager.e54d78b8.js} +82 -358
  16. package/dist/{chunk-typecheck-constants.ed987901.js → chunk-typecheck-constants.06e1fe5b.js} +8 -7
  17. package/dist/{chunk-utils-env.03f840f2.js → chunk-utils-env.3fdc1793.js} +8 -8
  18. package/dist/{chunk-runtime-test-state.3f86f48f.js → chunk-utils-import.afe2ffde.js} +50 -19
  19. package/dist/{chunk-utils-source-map.29ff1088.js → chunk-utils-source-map.59ba6b0a.js} +6 -4
  20. package/dist/{chunk-utils-timers.793fd179.js → chunk-utils-timers.715da787.js} +31 -15
  21. package/dist/cli-wrapper.js +10 -5
  22. package/dist/cli.js +30 -25
  23. package/dist/config.d.ts +6 -3
  24. package/dist/entry.js +18 -16
  25. package/dist/environments.d.ts +6 -3
  26. package/dist/environments.js +2 -2
  27. package/dist/{index-5aad25c1.d.ts → index-1e9f7f83.d.ts} +1 -1
  28. package/dist/index.d.ts +30 -12
  29. package/dist/index.js +12 -10
  30. package/dist/loader.js +12 -7
  31. package/dist/node.d.ts +21 -20
  32. package/dist/node.js +33 -25
  33. package/dist/suite.js +10 -8
  34. package/dist/{types-71ccd11d.d.ts → types-c41bae41.d.ts} +39 -279
  35. package/dist/vendor-index.2e96c50b.js +215 -0
  36. package/dist/vendor-index.783e7f3e.js +71 -0
  37. package/dist/{vendor-index.e1d4cf84.js → vendor-index.7a2cebfe.js} +16 -16
  38. package/dist/{vendor-index.737c3cff.js → vendor-index.b2fdde54.js} +9 -8
  39. package/dist/worker.js +21 -18
  40. package/environments.d.ts +1 -0
  41. package/package.json +4 -4
  42. package/dist/chunk-integrations-globals.4d261bb8.js +0 -25
  43. package/dist/chunk-vite-node-source-map.b4ea5792.js +0 -446
  44. package/dist/chunk-vite-node-utils.0e4a6a88.js +0 -1385
  45. package/dist/vendor-source-map-support.1ce17397.js +0 -707
@@ -1,446 +0,0 @@
1
- import { createRequire } from 'module';
2
- import { pathToFileURL, fileURLToPath } from 'url';
3
- import vm from 'vm';
4
- import { b as resolve, d as dirname, g as isAbsolute, l as extname } from './chunk-utils-env.03f840f2.js';
5
- import { s as slash, c as normalizeRequestId, b as toFilePath, d as cleanUrl, e as isPrimitive, i as isNodeBuiltin, n as normalizeModuleId } from './chunk-vite-node-utils.0e4a6a88.js';
6
- import createDebug from 'debug';
7
- import './vendor-source-map-support.1ce17397.js';
8
-
9
- let SOURCEMAPPING_URL = "sourceMa";
10
- SOURCEMAPPING_URL += "ppingURL";
11
- const VITE_NODE_SOURCEMAPPING_SOURCE = "//# sourceMappingSource=vite-node";
12
- const VITE_NODE_SOURCEMAPPING_URL = `${SOURCEMAPPING_URL}=data:application/json;charset=utf-8`;
13
- const VITE_NODE_SOURCEMAPPING_REGEXP = new RegExp(`//# ${VITE_NODE_SOURCEMAPPING_URL};base64,(.+)`);
14
- async function withInlineSourcemap(result) {
15
- const map = result.map;
16
- let code = result.code;
17
- if (!map || code.includes(VITE_NODE_SOURCEMAPPING_SOURCE))
18
- return result;
19
- const OTHER_SOURCE_MAP_REGEXP = new RegExp(`//# ${SOURCEMAPPING_URL}=data:application/json[^,]+base64,(.+)`, "g");
20
- while (OTHER_SOURCE_MAP_REGEXP.test(code))
21
- code = code.replace(OTHER_SOURCE_MAP_REGEXP, "");
22
- const sourceMap = Buffer.from(JSON.stringify(map), "utf-8").toString("base64");
23
- result.code = `${code.trimEnd()}
24
-
25
- ${VITE_NODE_SOURCEMAPPING_SOURCE}
26
- //# ${VITE_NODE_SOURCEMAPPING_URL};base64,${sourceMap}
27
- `;
28
- return result;
29
- }
30
- function extractSourceMap(code) {
31
- var _a;
32
- const mapString = (_a = code.match(VITE_NODE_SOURCEMAPPING_REGEXP)) == null ? void 0 : _a[1];
33
- if (mapString)
34
- return JSON.parse(Buffer.from(mapString, "base64").toString("utf-8"));
35
- return null;
36
- }
37
-
38
- const debugExecute = createDebug("vite-node:client:execute");
39
- const debugNative = createDebug("vite-node:client:native");
40
- const DEFAULT_REQUEST_STUBS = {
41
- "/@vite/client": {
42
- injectQuery: (id) => id,
43
- createHotContext() {
44
- return {
45
- accept: () => {
46
- },
47
- prune: () => {
48
- },
49
- dispose: () => {
50
- },
51
- decline: () => {
52
- },
53
- invalidate: () => {
54
- },
55
- on: () => {
56
- }
57
- };
58
- },
59
- updateStyle(id, css) {
60
- if (typeof document === "undefined")
61
- return;
62
- const element = document.getElementById(id);
63
- if (element)
64
- element.remove();
65
- const head = document.querySelector("head");
66
- const style = document.createElement("style");
67
- style.setAttribute("type", "text/css");
68
- style.id = id;
69
- style.innerHTML = css;
70
- head == null ? void 0 : head.appendChild(style);
71
- }
72
- }
73
- };
74
- class ModuleCacheMap extends Map {
75
- normalizePath(fsPath) {
76
- return normalizeModuleId(fsPath);
77
- }
78
- update(fsPath, mod) {
79
- fsPath = this.normalizePath(fsPath);
80
- if (!super.has(fsPath))
81
- super.set(fsPath, mod);
82
- else
83
- Object.assign(super.get(fsPath), mod);
84
- return this;
85
- }
86
- set(fsPath, mod) {
87
- fsPath = this.normalizePath(fsPath);
88
- return super.set(fsPath, mod);
89
- }
90
- get(fsPath) {
91
- fsPath = this.normalizePath(fsPath);
92
- if (!super.has(fsPath))
93
- super.set(fsPath, {});
94
- return super.get(fsPath);
95
- }
96
- delete(fsPath) {
97
- fsPath = this.normalizePath(fsPath);
98
- return super.delete(fsPath);
99
- }
100
- invalidateDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
101
- for (const _id of ids) {
102
- const id = this.normalizePath(_id);
103
- if (invalidated.has(id))
104
- continue;
105
- invalidated.add(id);
106
- const mod = super.get(id);
107
- if (mod == null ? void 0 : mod.importers)
108
- this.invalidateDepTree(mod.importers, invalidated);
109
- super.delete(id);
110
- }
111
- return invalidated;
112
- }
113
- invalidateSubDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
114
- for (const _id of ids) {
115
- const id = this.normalizePath(_id);
116
- if (invalidated.has(id))
117
- continue;
118
- invalidated.add(id);
119
- const subIds = Array.from(super.entries()).filter(([, mod]) => {
120
- var _a;
121
- return (_a = mod.importers) == null ? void 0 : _a.has(id);
122
- }).map(([key]) => key);
123
- subIds.length && this.invalidateSubDepTree(subIds, invalidated);
124
- super.delete(id);
125
- }
126
- return invalidated;
127
- }
128
- getSourceMap(id) {
129
- const cache = this.get(id);
130
- if (cache.map)
131
- return cache.map;
132
- const map = cache.code && extractSourceMap(cache.code);
133
- if (map) {
134
- cache.map = map;
135
- return map;
136
- }
137
- return null;
138
- }
139
- }
140
- class ViteNodeRunner {
141
- constructor(options) {
142
- this.options = options;
143
- this.root = options.root ?? process.cwd();
144
- this.moduleCache = options.moduleCache ?? new ModuleCacheMap();
145
- this.debug = options.debug ?? (typeof process !== "undefined" ? !!process.env.VITE_NODE_DEBUG_RUNNER : false);
146
- }
147
- async executeFile(file) {
148
- return await this.cachedRequest(`/@fs/${slash(resolve(file))}`, []);
149
- }
150
- async executeId(id) {
151
- return await this.cachedRequest(id, []);
152
- }
153
- getSourceMap(id) {
154
- return this.moduleCache.getSourceMap(id);
155
- }
156
- async cachedRequest(rawId, callstack) {
157
- const id = normalizeRequestId(rawId, this.options.base);
158
- const fsPath = toFilePath(id, this.root);
159
- const mod = this.moduleCache.get(fsPath);
160
- const importee = callstack[callstack.length - 1];
161
- if (!mod.importers)
162
- mod.importers = /* @__PURE__ */ new Set();
163
- if (importee)
164
- mod.importers.add(importee);
165
- if (callstack.includes(fsPath) && mod.exports)
166
- return mod.exports;
167
- if (mod.promise)
168
- return mod.promise;
169
- const promise = this.directRequest(id, fsPath, callstack);
170
- Object.assign(mod, { promise, evaluated: false });
171
- try {
172
- return await promise;
173
- } finally {
174
- mod.evaluated = true;
175
- }
176
- }
177
- async directRequest(id, fsPath, _callstack) {
178
- const callstack = [..._callstack, fsPath];
179
- let mod = this.moduleCache.get(fsPath);
180
- const request = async (dep2) => {
181
- var _a;
182
- const depFsPath = toFilePath(normalizeRequestId(dep2, this.options.base), this.root);
183
- const getStack = () => {
184
- return `stack:
185
- ${[...callstack, depFsPath].reverse().map((p) => `- ${p}`).join("\n")}`;
186
- };
187
- let debugTimer;
188
- if (this.debug)
189
- debugTimer = setTimeout(() => console.warn(() => `module ${depFsPath} takes over 2s to load.
190
- ${getStack()}`), 2e3);
191
- try {
192
- if (callstack.includes(depFsPath)) {
193
- const depExports = (_a = this.moduleCache.get(depFsPath)) == null ? void 0 : _a.exports;
194
- if (depExports)
195
- return depExports;
196
- throw new Error(`[vite-node] Failed to resolve circular dependency, ${getStack()}`);
197
- }
198
- return await this.cachedRequest(dep2, callstack);
199
- } finally {
200
- if (debugTimer)
201
- clearTimeout(debugTimer);
202
- }
203
- };
204
- Object.defineProperty(request, "callstack", { get: () => callstack });
205
- const resolveId = async (dep2, callstackPosition = 1) => {
206
- if (this.options.resolveId && this.shouldResolveId(dep2)) {
207
- let importer = callstack[callstack.length - callstackPosition];
208
- if (importer && !dep2.startsWith("."))
209
- importer = void 0;
210
- if (importer && importer.startsWith("mock:"))
211
- importer = importer.slice(5);
212
- const resolved = await this.options.resolveId(normalizeRequestId(dep2), importer);
213
- return [dep2, resolved == null ? void 0 : resolved.id];
214
- }
215
- return [dep2, void 0];
216
- };
217
- const [dep, resolvedId] = await resolveId(id, 2);
218
- const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
219
- if (id in requestStubs)
220
- return requestStubs[id];
221
- let { code: transformed, externalize } = await this.options.fetchModule(resolvedId || dep);
222
- if (resolvedId && !fsPath.includes("?") && fsPath !== resolvedId) {
223
- if (this.moduleCache.has(resolvedId)) {
224
- mod = this.moduleCache.get(resolvedId);
225
- this.moduleCache.set(fsPath, mod);
226
- if (mod.promise)
227
- return mod.promise;
228
- if (mod.exports)
229
- return mod.exports;
230
- } else {
231
- this.moduleCache.set(resolvedId, mod);
232
- }
233
- }
234
- if (externalize) {
235
- debugNative(externalize);
236
- const exports2 = await this.interopedImport(externalize);
237
- mod.exports = exports2;
238
- return exports2;
239
- }
240
- if (transformed == null)
241
- throw new Error(`[vite-node] Failed to load ${id}`);
242
- const file = cleanUrl(resolvedId || fsPath);
243
- const url = pathToFileURL(file).href;
244
- const meta = { url };
245
- const exports = /* @__PURE__ */ Object.create(null);
246
- Object.defineProperty(exports, Symbol.toStringTag, {
247
- value: "Module",
248
- enumerable: false,
249
- configurable: false
250
- });
251
- const cjsExports = new Proxy(exports, {
252
- set(_, p, value) {
253
- if (!Reflect.has(exports, "default"))
254
- exports.default = {};
255
- if (isPrimitive(exports.default)) {
256
- defineExport(exports, p, () => void 0);
257
- return true;
258
- }
259
- exports.default[p] = value;
260
- if (p !== "default")
261
- defineExport(exports, p, () => value);
262
- return true;
263
- }
264
- });
265
- Object.assign(mod, { code: transformed, exports });
266
- const __filename = fileURLToPath(url);
267
- const moduleProxy = {
268
- set exports(value) {
269
- exportAll(cjsExports, value);
270
- exports.default = value;
271
- },
272
- get exports() {
273
- return cjsExports;
274
- }
275
- };
276
- let hotContext;
277
- if (this.options.createHotContext) {
278
- Object.defineProperty(meta, "hot", {
279
- enumerable: true,
280
- get: () => {
281
- var _a, _b;
282
- hotContext || (hotContext = (_b = (_a = this.options).createHotContext) == null ? void 0 : _b.call(_a, this, `/@fs/${fsPath}`));
283
- return hotContext;
284
- }
285
- });
286
- }
287
- const context = this.prepareContext({
288
- __vite_ssr_import__: request,
289
- __vite_ssr_dynamic_import__: request,
290
- __vite_ssr_exports__: exports,
291
- __vite_ssr_exportAll__: (obj) => exportAll(exports, obj),
292
- __vite_ssr_import_meta__: meta,
293
- __vitest_resolve_id__: resolveId,
294
- require: createRequire(url),
295
- exports: cjsExports,
296
- module: moduleProxy,
297
- __filename,
298
- __dirname: dirname(__filename)
299
- });
300
- debugExecute(__filename);
301
- if (transformed[0] === "#")
302
- transformed = transformed.replace(/^\#\!.*/, (s) => " ".repeat(s.length));
303
- const codeDefinition = `'use strict';async (${Object.keys(context).join(",")})=>{{`;
304
- const code = `${codeDefinition}${transformed}
305
- }}`;
306
- const fn = vm.runInThisContext(code, {
307
- filename: __filename,
308
- lineOffset: 0,
309
- columnOffset: -codeDefinition.length
310
- });
311
- await fn(...Object.values(context));
312
- return exports;
313
- }
314
- prepareContext(context) {
315
- return context;
316
- }
317
- shouldResolveId(dep) {
318
- if (isNodeBuiltin(dep) || dep in (this.options.requestStubs || DEFAULT_REQUEST_STUBS) || dep.startsWith("/@vite"))
319
- return false;
320
- return !isAbsolute(dep) || !extname(dep);
321
- }
322
- shouldInterop(path, mod) {
323
- if (this.options.interopDefault === false)
324
- return false;
325
- return !path.endsWith(".mjs") && "default" in mod;
326
- }
327
- async interopedImport(path) {
328
- const mod = await import(path);
329
- if (this.shouldInterop(path, mod)) {
330
- const tryDefault = this.hasNestedDefault(mod);
331
- return new Proxy(mod, {
332
- get: proxyMethod("get", tryDefault),
333
- set: proxyMethod("set", tryDefault),
334
- has: proxyMethod("has", tryDefault),
335
- deleteProperty: proxyMethod("deleteProperty", tryDefault)
336
- });
337
- }
338
- return mod;
339
- }
340
- hasNestedDefault(target) {
341
- return "__esModule" in target && target.__esModule && "default" in target.default;
342
- }
343
- }
344
- function proxyMethod(name, tryDefault) {
345
- return function(target, key, ...args) {
346
- const result = Reflect[name](target, key, ...args);
347
- if (isPrimitive(target.default))
348
- return result;
349
- if (tryDefault && key === "default" || typeof result === "undefined")
350
- return Reflect[name](target.default, key, ...args);
351
- return result;
352
- };
353
- }
354
- function defineExport(exports, key, value) {
355
- Object.defineProperty(exports, key, {
356
- enumerable: true,
357
- configurable: true,
358
- get: value
359
- });
360
- }
361
- function exportAll(exports, sourceModule) {
362
- if (exports === sourceModule)
363
- return;
364
- if (isPrimitive(sourceModule) || Array.isArray(sourceModule))
365
- return;
366
- for (const key in sourceModule) {
367
- if (key !== "default") {
368
- try {
369
- defineExport(exports, key, () => sourceModule[key]);
370
- } catch (_err) {
371
- }
372
- }
373
- }
374
- }
375
-
376
- const DEFAULT_TIMEOUT = 6e4;
377
- function createBirpc(functions, options) {
378
- const {
379
- post,
380
- on,
381
- eventNames = [],
382
- serialize = (i) => i,
383
- deserialize = (i) => i,
384
- timeout = DEFAULT_TIMEOUT
385
- } = options;
386
- const rpcPromiseMap = /* @__PURE__ */ new Map();
387
- const rpc = new Proxy({}, {
388
- get(_, method) {
389
- const sendEvent = (...args) => {
390
- post(serialize({ m: method, a: args, t: "q" }));
391
- };
392
- if (eventNames.includes(method)) {
393
- sendEvent.asEvent = sendEvent;
394
- return sendEvent;
395
- }
396
- const sendCall = (...args) => {
397
- return new Promise((resolve, reject) => {
398
- const id = nanoid();
399
- rpcPromiseMap.set(id, { resolve, reject });
400
- post(serialize({ m: method, a: args, i: id, t: "q" }));
401
- if (timeout >= 0) {
402
- setTimeout(() => {
403
- reject(new Error(`[birpc] timeout on calling "${method}"`));
404
- rpcPromiseMap.delete(id);
405
- }, timeout);
406
- }
407
- });
408
- };
409
- sendCall.asEvent = sendEvent;
410
- return sendCall;
411
- }
412
- });
413
- on(async (data, ...extra) => {
414
- const msg = deserialize(data);
415
- if (msg.t === "q") {
416
- const { m: method, a: args } = msg;
417
- let result, error;
418
- try {
419
- result = await functions[method].apply(rpc, args);
420
- } catch (e) {
421
- error = e;
422
- }
423
- if (msg.i)
424
- post(serialize({ t: "s", i: msg.i, r: result, e: error }), ...extra);
425
- } else {
426
- const { i: ack, r: result, e: error } = msg;
427
- const promise = rpcPromiseMap.get(ack);
428
- if (error)
429
- promise?.reject(error);
430
- else
431
- promise?.resolve(result);
432
- rpcPromiseMap.delete(ack);
433
- }
434
- });
435
- return rpc;
436
- }
437
- const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
438
- function nanoid(size = 21) {
439
- let id = "";
440
- let i = size;
441
- while (i--)
442
- id += urlAlphabet[Math.random() * 64 | 0];
443
- return id;
444
- }
445
-
446
- export { ModuleCacheMap as M, ViteNodeRunner as V, createBirpc as c, withInlineSourcemap as w };