vitest 3.2.0-beta.3 → 3.2.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 +29 -0
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +2 -2
- package/dist/chunks/{base.D4119yLM.js → base.Cg0miDlQ.js} +10 -14
- package/dist/chunks/{benchmark.Cf_PACH1.js → benchmark.CYdenmiT.js} +4 -6
- package/dist/chunks/{cac.DWaWHIIE.js → cac.C8BzMmTW.js} +66 -136
- package/dist/chunks/{cli-api.CnmEXkxs.js → cli-api.DmupRhea.js} +1251 -1336
- package/dist/chunks/{console.Cwr-MFPV.js → console.CtFJOzRO.js} +24 -45
- package/dist/chunks/{coverage.0iPg4Wrz.js → coverage.DVF1vEu8.js} +4 -12
- package/dist/chunks/{coverage.C73DaDgS.js → coverage.EIiagJJP.js} +484 -1003
- package/dist/chunks/{creator.C8WKy2eW.js → creator.GK6I-cL4.js} +29 -76
- package/dist/chunks/{date.ByMsSlOr.js → date.Bq6ZW5rf.js} +3 -8
- package/dist/chunks/{defaults.DpVH7vbg.js → defaults.B7q_naMc.js} +1 -1
- package/dist/chunks/{env.Dq0hM4Xv.js → env.D4Lgay0q.js} +1 -1
- package/dist/chunks/{execute.B3q-2LPV.js → execute.B7h3T_Hc.js} +104 -220
- package/dist/chunks/{git.DXfdBEfR.js → git.BVQ8w_Sw.js} +1 -3
- package/dist/chunks/{global.d.BNLIi6yo.d.ts → global.d.MAmajcmJ.d.ts} +2 -0
- package/dist/chunks/{globals.CI21aWXF.js → globals.DEHgCU4V.js} +5 -5
- package/dist/chunks/{index.Bter3jj9.js → index.BZ0g1JD2.js} +366 -628
- package/dist/chunks/{index.CbT4iuwc.js → index.BbB8_kAK.js} +22 -24
- package/dist/chunks/{index.JOzufsrU.js → index.CIyJn3t1.js} +37 -82
- package/dist/chunks/{index.DNgLEKsQ.js → index.CdQS2e2Q.js} +2 -2
- package/dist/chunks/{index.2jgTs_Q5.js → index.CmSc2RE5.js} +69 -107
- package/dist/chunks/{inspector.BFsh5KO0.js → inspector.C914Efll.js} +1 -1
- package/dist/chunks/{node.Be-ntJnD.js → node.fjCdwEIl.js} +1 -1
- package/dist/chunks/{reporters.d.Bt4IGtsa.d.ts → reporters.d.C1ogPriE.d.ts} +24 -4
- package/dist/chunks/{rpc.BKExFSRG.js → rpc.Iovn4oWe.js} +9 -19
- package/dist/chunks/{runBaseTests.B_M1TTsK.js → runBaseTests.Dd85QTll.js} +18 -31
- package/dist/chunks/{setup-common.CF-O-dZX.js → setup-common.Dd054P77.js} +15 -42
- package/dist/chunks/{typechecker.BgzF-6iO.js → typechecker.DRKU1-1g.js} +106 -186
- package/dist/chunks/{utils.DPCq3gzW.js → utils.CAioKnHs.js} +6 -14
- package/dist/chunks/{utils.BlI4TC7Y.js → utils.XdZDrNZV.js} +5 -13
- package/dist/chunks/{vi.pkoYCV6A.js → vi.bdSIJ99Y.js} +118 -267
- package/dist/chunks/{vite.d.B-Kx3KCF.d.ts → vite.d.DqE4-hhK.d.ts} +1 -1
- package/dist/chunks/{vm.DPYem2so.js → vm.BThCzidc.js} +98 -214
- package/dist/chunks/{worker.d.Bl1O4kuf.d.ts → worker.d.DvqK5Vmu.d.ts} +1 -1
- package/dist/chunks/{worker.d.BKbBp2ga.d.ts → worker.d.tQu2eJQy.d.ts} +3 -1
- package/dist/cli.js +4 -4
- package/dist/config.cjs +1 -1
- package/dist/config.d.ts +4 -4
- package/dist/config.js +2 -2
- package/dist/coverage.d.ts +2 -2
- package/dist/coverage.js +5 -5
- package/dist/environments.js +1 -1
- package/dist/execute.d.ts +1 -1
- package/dist/execute.js +1 -1
- package/dist/index.d.ts +12 -11
- package/dist/index.js +5 -5
- package/dist/node.d.ts +7 -7
- package/dist/node.js +12 -14
- package/dist/reporters.d.ts +2 -2
- package/dist/reporters.js +4 -4
- package/dist/runners.d.ts +5 -2
- package/dist/runners.js +51 -80
- package/dist/snapshot.js +2 -2
- package/dist/suite.js +2 -2
- package/dist/worker.js +36 -42
- package/dist/workers/forks.js +4 -4
- package/dist/workers/runVmTests.js +15 -21
- package/dist/workers/threads.js +4 -4
- package/dist/workers/vmForks.js +6 -6
- package/dist/workers/vmThreads.js +6 -6
- package/dist/workers.d.ts +2 -2
- package/dist/workers.js +10 -10
- package/package.json +16 -14
|
@@ -257,15 +257,10 @@ async function generateExampleFiles(framework, lang) {
|
|
|
257
257
|
let fileName = example.name;
|
|
258
258
|
const folder = resolve(process.cwd(), "vitest-example");
|
|
259
259
|
const fileContent = example[lang];
|
|
260
|
-
if (!existsSync(folder)) {
|
|
261
|
-
await mkdir(folder, { recursive: true });
|
|
262
|
-
}
|
|
260
|
+
if (!existsSync(folder)) await mkdir(folder, { recursive: true });
|
|
263
261
|
const isJSX = fileName.endsWith(".jsx");
|
|
264
|
-
if (isJSX && lang === "ts")
|
|
265
|
-
|
|
266
|
-
} else if (fileName.endsWith(".js") && lang === "ts") {
|
|
267
|
-
fileName = fileName.replace(".js", ".ts");
|
|
268
|
-
}
|
|
262
|
+
if (isJSX && lang === "ts") fileName = fileName.replace(".jsx", ".tsx");
|
|
263
|
+
else if (fileName.endsWith(".js") && lang === "ts") fileName = fileName.replace(".js", ".ts");
|
|
269
264
|
const filePath = resolve(folder, fileName);
|
|
270
265
|
const testPath = resolve(folder, `HelloWorld.test.${isJSX ? `${lang}x` : lang}`);
|
|
271
266
|
writeFileSync(filePath, fileContent.trimStart(), "utf-8");
|
|
@@ -395,9 +390,7 @@ function getFrameworkPluginPackage(framework) {
|
|
|
395
390
|
return null;
|
|
396
391
|
}
|
|
397
392
|
async function updateTsConfig(type) {
|
|
398
|
-
if (type == null)
|
|
399
|
-
return;
|
|
400
|
-
}
|
|
393
|
+
if (type == null) return;
|
|
401
394
|
const msg = `Add "${c.bold(type)}" to your tsconfig.json "${c.bold("compilerOptions.types")}" field to have better intellisense support.`;
|
|
402
395
|
log();
|
|
403
396
|
log(c.yellow("◼"), c.yellow(msg));
|
|
@@ -423,13 +416,11 @@ async function installPackages(pkgManager, packages) {
|
|
|
423
416
|
log();
|
|
424
417
|
await installPackage(packages, {
|
|
425
418
|
dev: true,
|
|
426
|
-
packageManager: pkgManager ??
|
|
419
|
+
packageManager: pkgManager ?? void 0
|
|
427
420
|
});
|
|
428
421
|
}
|
|
429
422
|
function readPkgJson(path) {
|
|
430
|
-
if (!existsSync(path))
|
|
431
|
-
return null;
|
|
432
|
-
}
|
|
423
|
+
if (!existsSync(path)) return null;
|
|
433
424
|
const content = readFileSync(path, "utf-8");
|
|
434
425
|
return JSON.parse(content);
|
|
435
426
|
}
|
|
@@ -443,33 +434,17 @@ function getPossibleDefaults(dependencies) {
|
|
|
443
434
|
};
|
|
444
435
|
}
|
|
445
436
|
function getPossibleFramework(dependencies) {
|
|
446
|
-
if (dependencies.vue || dependencies["vue-tsc"] || dependencies["@vue/reactivity"])
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
if (dependencies.
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
if (dependencies.
|
|
453
|
-
return "svelte";
|
|
454
|
-
}
|
|
455
|
-
if (dependencies.lit || dependencies["lit-html"]) {
|
|
456
|
-
return "lit";
|
|
457
|
-
}
|
|
458
|
-
if (dependencies.preact) {
|
|
459
|
-
return "preact";
|
|
460
|
-
}
|
|
461
|
-
if (dependencies["solid-js"] || dependencies["@solidjs/start"]) {
|
|
462
|
-
return "solid";
|
|
463
|
-
}
|
|
464
|
-
if (dependencies.marko) {
|
|
465
|
-
return "marko";
|
|
466
|
-
}
|
|
437
|
+
if (dependencies.vue || dependencies["vue-tsc"] || dependencies["@vue/reactivity"]) return "vue";
|
|
438
|
+
if (dependencies.react || dependencies["react-dom"]) return "react";
|
|
439
|
+
if (dependencies.svelte || dependencies["@sveltejs/kit"]) return "svelte";
|
|
440
|
+
if (dependencies.lit || dependencies["lit-html"]) return "lit";
|
|
441
|
+
if (dependencies.preact) return "preact";
|
|
442
|
+
if (dependencies["solid-js"] || dependencies["@solidjs/start"]) return "solid";
|
|
443
|
+
if (dependencies.marko) return "marko";
|
|
467
444
|
return "vanilla";
|
|
468
445
|
}
|
|
469
446
|
function getPossibleProvider(dependencies) {
|
|
470
|
-
if (dependencies.webdriverio || dependencies["@wdio/cli"] || dependencies["@wdio/config"])
|
|
471
|
-
return "webdriverio";
|
|
472
|
-
}
|
|
447
|
+
if (dependencies.webdriverio || dependencies["@wdio/cli"] || dependencies["@wdio/config"]) return "webdriverio";
|
|
473
448
|
// playwright is the default recommendation
|
|
474
449
|
return "playwright";
|
|
475
450
|
}
|
|
@@ -481,9 +456,7 @@ function getProviderDocsLink(provider) {
|
|
|
481
456
|
}
|
|
482
457
|
function sort(choices, value) {
|
|
483
458
|
const index = choices.findIndex((i) => i.value === value);
|
|
484
|
-
if (index === -1)
|
|
485
|
-
return choices;
|
|
486
|
-
}
|
|
459
|
+
if (index === -1) return choices;
|
|
487
460
|
const item = choices.splice(index, 1)[0];
|
|
488
461
|
return [item, ...choices];
|
|
489
462
|
}
|
|
@@ -560,18 +533,14 @@ async function create() {
|
|
|
560
533
|
message: "Choose a language for your tests",
|
|
561
534
|
choices: sort(getLanguageOptions(), defaults?.lang)
|
|
562
535
|
});
|
|
563
|
-
if (!lang)
|
|
564
|
-
return fail();
|
|
565
|
-
}
|
|
536
|
+
if (!lang) return fail();
|
|
566
537
|
const { provider } = await prompt({
|
|
567
538
|
type: "select",
|
|
568
539
|
name: "provider",
|
|
569
540
|
message: "Choose a browser provider. Vitest will use its API to control the testing environment",
|
|
570
541
|
choices: sort(getProviderOptions(), defaults?.provider)
|
|
571
542
|
});
|
|
572
|
-
if (!provider)
|
|
573
|
-
return fail();
|
|
574
|
-
}
|
|
543
|
+
if (!provider) return fail();
|
|
575
544
|
const { browsers } = await prompt({
|
|
576
545
|
type: "multiselect",
|
|
577
546
|
name: "browsers",
|
|
@@ -581,42 +550,28 @@ async function create() {
|
|
|
581
550
|
value: browser
|
|
582
551
|
}))
|
|
583
552
|
});
|
|
584
|
-
if (!provider)
|
|
585
|
-
return fail();
|
|
586
|
-
}
|
|
553
|
+
if (!provider) return fail();
|
|
587
554
|
const { framework } = await prompt({
|
|
588
555
|
type: "select",
|
|
589
556
|
name: "framework",
|
|
590
557
|
message: "Choose your framework",
|
|
591
558
|
choices: sort(getFramework(), defaults?.framework)
|
|
592
559
|
});
|
|
593
|
-
if (!framework)
|
|
594
|
-
return fail();
|
|
595
|
-
}
|
|
560
|
+
if (!framework) return fail();
|
|
596
561
|
let installPlaywright = false;
|
|
597
|
-
if (provider === "playwright") {
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
}
|
|
604
|
-
if (installPlaywright == null) {
|
|
605
|
-
return fail();
|
|
606
|
-
}
|
|
562
|
+
if (provider === "playwright") ({installPlaywright} = await prompt({
|
|
563
|
+
type: "confirm",
|
|
564
|
+
name: "installPlaywright",
|
|
565
|
+
message: `Install Playwright browsers (can be done manually via 'pnpm exec playwright install')?`
|
|
566
|
+
}));
|
|
567
|
+
if (installPlaywright == null) return fail();
|
|
607
568
|
const dependenciesToInstall = ["@vitest/browser"];
|
|
608
569
|
const frameworkPackage = getFrameworkTestPackage(framework);
|
|
609
|
-
if (frameworkPackage)
|
|
610
|
-
dependenciesToInstall.push(frameworkPackage);
|
|
611
|
-
}
|
|
570
|
+
if (frameworkPackage) dependenciesToInstall.push(frameworkPackage);
|
|
612
571
|
const providerPkg = getProviderPackageNames(provider);
|
|
613
|
-
if (providerPkg.pkg)
|
|
614
|
-
dependenciesToInstall.push(providerPkg.pkg);
|
|
615
|
-
}
|
|
572
|
+
if (providerPkg.pkg) dependenciesToInstall.push(providerPkg.pkg);
|
|
616
573
|
const frameworkPlugin = getFrameworkPluginPackage(framework);
|
|
617
|
-
if (frameworkPlugin)
|
|
618
|
-
dependenciesToInstall.push(frameworkPlugin);
|
|
619
|
-
}
|
|
574
|
+
if (frameworkPlugin) dependenciesToInstall.push(frameworkPlugin);
|
|
620
575
|
const pkgManager = await detectPackageManager();
|
|
621
576
|
log();
|
|
622
577
|
await installPackages(pkgManager, dependenciesToInstall.filter((pkg) => !dependencies[pkg]));
|
|
@@ -673,9 +628,7 @@ async function create() {
|
|
|
673
628
|
] } });
|
|
674
629
|
}
|
|
675
630
|
// TODO: can we do this ourselves?
|
|
676
|
-
if (lang === "ts")
|
|
677
|
-
await updateTsConfig(providerPkg?.types);
|
|
678
|
-
}
|
|
631
|
+
if (lang === "ts") await updateTsConfig(providerPkg?.types);
|
|
679
632
|
log();
|
|
680
633
|
const exampleTestFile = await generateExampleFiles(framework, lang);
|
|
681
634
|
log(c.green("✔"), "Created example test file in", c.bold(relative(process.cwd(), exampleTestFile)));
|
|
@@ -30,11 +30,8 @@ class MockDate extends RealDate {
|
|
|
30
30
|
let date;
|
|
31
31
|
switch (arguments.length) {
|
|
32
32
|
case 0:
|
|
33
|
-
if (now !== null)
|
|
34
|
-
|
|
35
|
-
} else {
|
|
36
|
-
date = new RealDate();
|
|
37
|
-
}
|
|
33
|
+
if (now !== null) date = new RealDate(now.valueOf());
|
|
34
|
+
else date = new RealDate();
|
|
38
35
|
break;
|
|
39
36
|
case 1:
|
|
40
37
|
date = new RealDate(y);
|
|
@@ -64,9 +61,7 @@ MockDate.toString = function() {
|
|
|
64
61
|
};
|
|
65
62
|
function mockDate(date) {
|
|
66
63
|
const dateObj = new RealDate(date.valueOf());
|
|
67
|
-
if (Number.isNaN(dateObj.getTime())) {
|
|
68
|
-
throw new TypeError(`mockdate: The time set is an invalid date: ${date}`);
|
|
69
|
-
}
|
|
64
|
+
if (Number.isNaN(dateObj.getTime())) throw new TypeError(`mockdate: The time set is an invalid date: ${date}`);
|
|
70
65
|
// @ts-expect-error global
|
|
71
66
|
globalThis.Date = MockDate;
|
|
72
67
|
now = dateObj.valueOf();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isCI } from 'std-env';
|
|
2
2
|
|
|
3
3
|
const isNode = typeof process < "u" && typeof process.stdout < "u" && !process.versions?.deno && !globalThis.window;
|
|
4
|
-
const isDeno = typeof process < "u" && typeof process.stdout < "u" && process.versions?.deno !==
|
|
4
|
+
const isDeno = typeof process < "u" && typeof process.stdout < "u" && process.versions?.deno !== void 0;
|
|
5
5
|
const isWindows = (isNode || isDeno) && process.platform === "win32";
|
|
6
6
|
const isTTY = (isNode || isDeno) && process.stdout?.isTTY && !isCI;
|
|
7
7
|
|