vitest 0.33.0 → 0.34.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/LICENSE.md +0 -83
- package/dist/browser.d.ts +3 -2
- package/dist/browser.js +4 -8
- package/dist/child.js +43 -29
- package/dist/{chunk-api-setup.8f785c4a.js → chunk-api-setup.644415c3.js} +13 -7
- package/dist/{chunk-install-pkg.23da664c.js → chunk-install-pkg.dd40cbef.js} +14 -13
- package/dist/{chunk-integrations-globals.0093e2ed.js → chunk-integrations-globals.877c84db.js} +7 -6
- package/dist/chunk-runtime-console.ea222ffb.js +108 -0
- package/dist/cli.js +14 -15
- package/dist/config.cjs +4 -3
- package/dist/config.d.ts +15 -19
- package/dist/config.js +4 -3
- package/dist/coverage.d.ts +3 -2
- package/dist/entry-vm.js +60 -0
- package/dist/entry.js +34 -213
- package/dist/environments.d.ts +3 -2
- package/dist/environments.js +4 -2
- package/dist/execute.js +15 -0
- package/dist/index.d.ts +12 -7
- package/dist/index.js +8 -7
- package/dist/loader.js +6 -4
- package/dist/node.d.ts +6 -53
- package/dist/node.js +16 -19
- package/dist/runners.d.ts +3 -2
- package/dist/runners.js +6 -5
- package/dist/{types-198fd1d9.d.ts → types-3c7dbfa5.d.ts} +139 -121
- package/dist/vendor-base.9c08bbd0.js +96 -0
- package/dist/{vendor-coverage.2e41927a.js → vendor-coverage.78040316.js} +1 -2
- package/dist/vendor-date.6e993429.js +50 -0
- package/dist/{vendor-environments.392ddf08.js → vendor-environments.443ecd82.js} +199 -3
- package/dist/vendor-execute.9ab1c1a7.js +978 -0
- package/dist/{vendor-global.6795f91f.js → vendor-global.97e4527c.js} +2 -1
- package/dist/{vendor-index.23ac4e13.js → vendor-index.087d1af7.js} +2 -20
- package/dist/vendor-index.9378c9a4.js +89 -0
- package/dist/vendor-index.b271ebe4.js +92 -0
- package/dist/{vendor-index.2af39fbb.js → vendor-index.eff408fd.js} +2 -3
- package/dist/{vendor-cli-api.bf4b62a8.js → vendor-node.caa511fc.js} +539 -836
- package/dist/{vendor-rpc.ad5b08c7.js → vendor-rpc.cbd8e972.js} +7 -4
- package/dist/{vendor-run-once.1fa85ba7.js → vendor-run-once.3e5ef7d7.js} +1 -2
- package/dist/vendor-source-map.e6c1997b.js +747 -0
- package/dist/{vendor-vi.dd6706cb.js → vendor-vi.271667ef.js} +26 -59
- package/dist/vm.js +114 -0
- package/dist/worker.js +39 -27
- package/execute.d.ts +1 -0
- package/package.json +12 -9
- package/suppress-warnings.cjs +2 -0
- package/dist/vendor-execute.3576af13.js +0 -421
- package/dist/vendor-index.cc463d9e.js +0 -189
- package/dist/vendor-tasks.f9d75aed.js +0 -14
|
@@ -1,8 +1,96 @@
|
|
|
1
|
+
import { pathToFileURL } from 'node:url';
|
|
2
|
+
import { resolve, normalize } from 'pathe';
|
|
3
|
+
import { importModule, resolveModule } from 'local-pkg';
|
|
1
4
|
import { Console } from 'node:console';
|
|
2
|
-
import { importModule } from 'local-pkg';
|
|
3
5
|
|
|
6
|
+
const denyList = /* @__PURE__ */ new Set([
|
|
7
|
+
"GLOBAL",
|
|
8
|
+
"root",
|
|
9
|
+
"global",
|
|
10
|
+
"Buffer",
|
|
11
|
+
"ArrayBuffer",
|
|
12
|
+
"Uint8Array"
|
|
13
|
+
]);
|
|
14
|
+
const nodeGlobals = new Map(
|
|
15
|
+
Object.getOwnPropertyNames(globalThis).filter((global) => !denyList.has(global)).map((nodeGlobalsKey) => {
|
|
16
|
+
const descriptor = Object.getOwnPropertyDescriptor(
|
|
17
|
+
globalThis,
|
|
18
|
+
nodeGlobalsKey
|
|
19
|
+
);
|
|
20
|
+
if (!descriptor) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
`No property descriptor for ${nodeGlobalsKey}, this is a bug in Vitest.`
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
return [nodeGlobalsKey, descriptor];
|
|
26
|
+
})
|
|
27
|
+
);
|
|
4
28
|
var node = {
|
|
5
29
|
name: "node",
|
|
30
|
+
transformMode: "ssr",
|
|
31
|
+
// this is largely copied from jest's node environment
|
|
32
|
+
async setupVM() {
|
|
33
|
+
const vm = await import('node:vm');
|
|
34
|
+
const context = vm.createContext();
|
|
35
|
+
const global = vm.runInContext(
|
|
36
|
+
"this",
|
|
37
|
+
context
|
|
38
|
+
);
|
|
39
|
+
const contextGlobals = new Set(Object.getOwnPropertyNames(global));
|
|
40
|
+
for (const [nodeGlobalsKey, descriptor] of nodeGlobals) {
|
|
41
|
+
if (!contextGlobals.has(nodeGlobalsKey)) {
|
|
42
|
+
if (descriptor.configurable) {
|
|
43
|
+
Object.defineProperty(global, nodeGlobalsKey, {
|
|
44
|
+
configurable: true,
|
|
45
|
+
enumerable: descriptor.enumerable,
|
|
46
|
+
get() {
|
|
47
|
+
const val = globalThis[nodeGlobalsKey];
|
|
48
|
+
Object.defineProperty(global, nodeGlobalsKey, {
|
|
49
|
+
configurable: true,
|
|
50
|
+
enumerable: descriptor.enumerable,
|
|
51
|
+
value: val,
|
|
52
|
+
writable: descriptor.writable === true || nodeGlobalsKey === "performance"
|
|
53
|
+
});
|
|
54
|
+
return val;
|
|
55
|
+
},
|
|
56
|
+
set(val) {
|
|
57
|
+
Object.defineProperty(global, nodeGlobalsKey, {
|
|
58
|
+
configurable: true,
|
|
59
|
+
enumerable: descriptor.enumerable,
|
|
60
|
+
value: val,
|
|
61
|
+
writable: true
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
} else if ("value" in descriptor) {
|
|
66
|
+
Object.defineProperty(global, nodeGlobalsKey, {
|
|
67
|
+
configurable: false,
|
|
68
|
+
enumerable: descriptor.enumerable,
|
|
69
|
+
value: descriptor.value,
|
|
70
|
+
writable: descriptor.writable
|
|
71
|
+
});
|
|
72
|
+
} else {
|
|
73
|
+
Object.defineProperty(global, nodeGlobalsKey, {
|
|
74
|
+
configurable: false,
|
|
75
|
+
enumerable: descriptor.enumerable,
|
|
76
|
+
get: descriptor.get,
|
|
77
|
+
set: descriptor.set
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
global.global = global;
|
|
83
|
+
global.Buffer = Buffer;
|
|
84
|
+
global.ArrayBuffer = ArrayBuffer;
|
|
85
|
+
global.Uint8Array = Uint8Array;
|
|
86
|
+
return {
|
|
87
|
+
getVmContext() {
|
|
88
|
+
return context;
|
|
89
|
+
},
|
|
90
|
+
teardown() {
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
},
|
|
6
94
|
async setup(global) {
|
|
7
95
|
global.console.Console = Console;
|
|
8
96
|
return {
|
|
@@ -252,7 +340,8 @@ const skipKeys = [
|
|
|
252
340
|
"window",
|
|
253
341
|
"self",
|
|
254
342
|
"top",
|
|
255
|
-
"parent"
|
|
343
|
+
"parent",
|
|
344
|
+
"URL"
|
|
256
345
|
];
|
|
257
346
|
function getWindowKeys(global, win) {
|
|
258
347
|
const keys = new Set(KEYS.concat(Object.getOwnPropertyNames(win)).filter((k) => {
|
|
@@ -336,6 +425,57 @@ function catchWindowErrors(window) {
|
|
|
336
425
|
}
|
|
337
426
|
var jsdom = {
|
|
338
427
|
name: "jsdom",
|
|
428
|
+
transformMode: "web",
|
|
429
|
+
async setupVM({ jsdom = {} }) {
|
|
430
|
+
const {
|
|
431
|
+
CookieJar,
|
|
432
|
+
JSDOM,
|
|
433
|
+
ResourceLoader,
|
|
434
|
+
VirtualConsole
|
|
435
|
+
} = await importModule("jsdom");
|
|
436
|
+
const {
|
|
437
|
+
html = "<!DOCTYPE html>",
|
|
438
|
+
userAgent,
|
|
439
|
+
url = "http://localhost:3000",
|
|
440
|
+
contentType = "text/html",
|
|
441
|
+
pretendToBeVisual = true,
|
|
442
|
+
includeNodeLocations = false,
|
|
443
|
+
runScripts = "dangerously",
|
|
444
|
+
resources,
|
|
445
|
+
console = false,
|
|
446
|
+
cookieJar = false,
|
|
447
|
+
...restOptions
|
|
448
|
+
} = jsdom;
|
|
449
|
+
const dom = new JSDOM(
|
|
450
|
+
html,
|
|
451
|
+
{
|
|
452
|
+
pretendToBeVisual,
|
|
453
|
+
resources: resources ?? (userAgent ? new ResourceLoader({ userAgent }) : void 0),
|
|
454
|
+
runScripts,
|
|
455
|
+
url,
|
|
456
|
+
virtualConsole: console && globalThis.console ? new VirtualConsole().sendTo(globalThis.console) : void 0,
|
|
457
|
+
cookieJar: cookieJar ? new CookieJar() : void 0,
|
|
458
|
+
includeNodeLocations,
|
|
459
|
+
contentType,
|
|
460
|
+
userAgent,
|
|
461
|
+
...restOptions
|
|
462
|
+
}
|
|
463
|
+
);
|
|
464
|
+
const clearWindowErrors = catchWindowErrors(dom.window);
|
|
465
|
+
dom.window.Buffer = Buffer;
|
|
466
|
+
dom.window.Uint8Array = Uint8Array;
|
|
467
|
+
if (typeof structuredClone !== "undefined" && !dom.window.structuredClone)
|
|
468
|
+
dom.window.structuredClone = structuredClone;
|
|
469
|
+
return {
|
|
470
|
+
getVmContext() {
|
|
471
|
+
return dom.getInternalVMContext();
|
|
472
|
+
},
|
|
473
|
+
teardown() {
|
|
474
|
+
clearWindowErrors();
|
|
475
|
+
dom.window.close();
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
},
|
|
339
479
|
async setup(global, { jsdom = {} }) {
|
|
340
480
|
const {
|
|
341
481
|
CookieJar,
|
|
@@ -386,6 +526,23 @@ var jsdom = {
|
|
|
386
526
|
|
|
387
527
|
var happy = {
|
|
388
528
|
name: "happy-dom",
|
|
529
|
+
transformMode: "web",
|
|
530
|
+
async setupVM() {
|
|
531
|
+
const { Window } = await importModule("happy-dom");
|
|
532
|
+
const win = new Window();
|
|
533
|
+
win.Buffer = Buffer;
|
|
534
|
+
win.Uint8Array = Uint8Array;
|
|
535
|
+
if (typeof structuredClone !== "undefined" && !win.structuredClone)
|
|
536
|
+
win.structuredClone = structuredClone;
|
|
537
|
+
return {
|
|
538
|
+
getVmContext() {
|
|
539
|
+
return win;
|
|
540
|
+
},
|
|
541
|
+
teardown() {
|
|
542
|
+
win.happyDOM.cancelAsync();
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
},
|
|
389
546
|
async setup(global) {
|
|
390
547
|
const { Window, GlobalWindow } = await importModule("happy-dom");
|
|
391
548
|
const win = new (GlobalWindow || Window)();
|
|
@@ -402,6 +559,24 @@ var happy = {
|
|
|
402
559
|
|
|
403
560
|
var edge = {
|
|
404
561
|
name: "edge-runtime",
|
|
562
|
+
transformMode: "ssr",
|
|
563
|
+
async setupVM() {
|
|
564
|
+
const { EdgeVM } = await importModule("@edge-runtime/vm");
|
|
565
|
+
const vm = new EdgeVM({
|
|
566
|
+
extend: (context) => {
|
|
567
|
+
context.global = context;
|
|
568
|
+
context.Buffer = Buffer;
|
|
569
|
+
return context;
|
|
570
|
+
}
|
|
571
|
+
});
|
|
572
|
+
return {
|
|
573
|
+
getVmContext() {
|
|
574
|
+
return vm.context;
|
|
575
|
+
},
|
|
576
|
+
teardown() {
|
|
577
|
+
}
|
|
578
|
+
};
|
|
579
|
+
},
|
|
405
580
|
async setup(global) {
|
|
406
581
|
const { EdgeVM } = await importModule("@edge-runtime/vm");
|
|
407
582
|
const vm = new EdgeVM({
|
|
@@ -432,6 +607,9 @@ const envPackageNames = {
|
|
|
432
607
|
"happy-dom": "happy-dom",
|
|
433
608
|
"edge-runtime": "@edge-runtime/vm"
|
|
434
609
|
};
|
|
610
|
+
function isBuiltinEnvironment(env) {
|
|
611
|
+
return env in environments;
|
|
612
|
+
}
|
|
435
613
|
function getEnvPackageName(env) {
|
|
436
614
|
if (env === "node")
|
|
437
615
|
return null;
|
|
@@ -439,5 +617,23 @@ function getEnvPackageName(env) {
|
|
|
439
617
|
return envPackageNames[env];
|
|
440
618
|
return `vitest-environment-${env}`;
|
|
441
619
|
}
|
|
620
|
+
async function loadEnvironment(name, root) {
|
|
621
|
+
if (isBuiltinEnvironment(name))
|
|
622
|
+
return environments[name];
|
|
623
|
+
const packageId = name[0] === "." || name[0] === "/" ? resolve(root, name) : resolveModule(`vitest-environment-${name}`, { paths: [root] }) ?? resolve(root, name);
|
|
624
|
+
const pkg = await import(pathToFileURL(normalize(packageId)).href);
|
|
625
|
+
if (!pkg || !pkg.default || typeof pkg.default !== "object") {
|
|
626
|
+
throw new TypeError(
|
|
627
|
+
`Environment "${name}" is not a valid environment. Path "${packageId}" should export default object with a "setup" or/and "setupVM" method.`
|
|
628
|
+
);
|
|
629
|
+
}
|
|
630
|
+
const environment = pkg.default;
|
|
631
|
+
if (environment.transformMode !== "web" && environment.transformMode !== "ssr") {
|
|
632
|
+
throw new TypeError(
|
|
633
|
+
`Environment "${name}" is not a valid environment. Path "${packageId}" should export default object with a "transformMode" method equal to "ssr" or "web".`
|
|
634
|
+
);
|
|
635
|
+
}
|
|
636
|
+
return environment;
|
|
637
|
+
}
|
|
442
638
|
|
|
443
|
-
export { environments as e, getEnvPackageName as g, populateGlobal as p };
|
|
639
|
+
export { environments as e, getEnvPackageName as g, loadEnvironment as l, populateGlobal as p };
|