vitest 4.0.0-beta.4 → 4.0.0-beta.6
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 +1 -1
- package/dist/browser.d.ts +8 -9
- package/dist/browser.js +3 -2
- package/dist/chunks/base.BXI97p6t.js +39 -0
- package/dist/chunks/{benchmark.CYdenmiT.js → benchmark.UW6Ezvxy.js} +6 -8
- package/dist/chunks/{browser.d.BRP8scJf.d.ts → browser.d.Cawq_X_N.d.ts} +1 -1
- package/dist/chunks/{cac.CY0IAxC4.js → cac.WE-urWw5.js} +38 -115
- package/dist/chunks/{cli-api.B8xRY9Zt.js → cli-api.CZz3evYC.js} +931 -1439
- package/dist/chunks/{config.d.DZo8c7fw.d.ts → config.d.CKNVOKm0.d.ts} +3 -8
- package/dist/chunks/{console.DoJHFxmj.js → console.B0quX7yH.js} +32 -68
- package/dist/chunks/{constants.CXzqaLmq.js → constants.D_Q9UYh-.js} +1 -6
- package/dist/chunks/{coverage.C84l9G-M.js → coverage.BPRS6xgn.js} +395 -665
- package/dist/chunks/{coverage.DVF1vEu8.js → coverage.D_JHT54q.js} +2 -2
- package/dist/chunks/{coverage.d.CNYjU4GF.d.ts → coverage.d.BZtK59WP.d.ts} +7 -5
- package/dist/chunks/{creator.yfA2ExGt.js → creator.KEg6n5IC.js} +29 -75
- package/dist/chunks/{date.Bq6ZW5rf.js → date.-jtEtIeV.js} +6 -17
- package/dist/chunks/{environment.d.Bhm9oc0v.d.ts → environment.d.2fYMoz3o.d.ts} +26 -4
- package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
- package/dist/chunks/{global.d.DAhT2emn.d.ts → global.d.K6uBQHzY.d.ts} +1 -1
- package/dist/chunks/{globals.Dgo-vS5G.js → globals.lgsmH00r.js} +7 -6
- package/dist/chunks/{index.D3SKT3tv.js → index.7w0eqmYM.js} +14 -24
- package/dist/chunks/{index.D1_MsKEt.js → index.AR8aAkCC.js} +4 -2
- package/dist/chunks/{index.CmSc2RE5.js → index.BG0gqZH-.js} +43 -106
- package/dist/chunks/{index.CtUvr1c8.js → index.CsFXYRkW.js} +27 -46
- package/dist/chunks/{index.Bz6b0Ib7.js → index.VNI-1z5c.js} +276 -604
- package/dist/chunks/{inspector.C914Efll.js → inspector.CvQD-Nie.js} +10 -25
- package/dist/chunks/moduleRunner.d.8kKUsuDg.d.ts +202 -0
- package/dist/chunks/moduleTransport.I-bgQy0S.js +19 -0
- package/dist/chunks/{node.fjCdwEIl.js → node.BOqcT2jW.js} +1 -1
- package/dist/chunks/{plugin.d.CLhMcYdD.d.ts → plugin.d.DuiQJfUL.d.ts} +1 -1
- package/dist/chunks/{reporters.d.DWg40D2B.d.ts → reporters.d.CqR9-CDJ.d.ts} +52 -101
- package/dist/chunks/resolver.Bx6lE0iq.js +119 -0
- package/dist/chunks/{rpc.jnQO9F8a.js → rpc.RpPylpp0.js} +7 -21
- package/dist/chunks/runBaseTests.D6sfuWBM.js +99 -0
- package/dist/chunks/{setup-common.Ebx5x0eP.js → setup-common.hLGRxhC8.js} +15 -27
- package/dist/chunks/startModuleRunner.C8TW8zTN.js +655 -0
- package/dist/chunks/{typechecker.CMNPqJOo.js → typechecker.Cd1wvxUM.js} +97 -209
- package/dist/chunks/{utils.CcGm2cd1.js → utils.C2YI6McM.js} +4 -13
- package/dist/chunks/{utils.XdZDrNZV.js → utils.C7__0Iv5.js} +7 -17
- package/dist/chunks/{vi.CA0EPI9Y.js → vi.BfdOiD4j.js} +116 -269
- package/dist/chunks/{vm.BUnLJt_P.js → vm.BHBje7cC.js} +101 -225
- package/dist/chunks/{worker.d.zjyR34Pb.d.ts → worker.d.D9QWnzAe.d.ts} +16 -13
- package/dist/chunks/{worker.d.C-1AbnVe.d.ts → worker.d.Db-UVmXc.d.ts} +1 -1
- package/dist/cli.js +4 -4
- package/dist/config.cjs +3 -9
- package/dist/config.d.ts +10 -12
- package/dist/config.js +1 -1
- package/dist/coverage.d.ts +10 -11
- package/dist/coverage.js +5 -6
- package/dist/environments.d.ts +2 -2
- package/dist/environments.js +1 -1
- package/dist/index.d.ts +10 -9
- package/dist/index.js +6 -5
- package/dist/module-evaluator.d.ts +12 -0
- package/dist/module-evaluator.js +276 -0
- package/dist/module-runner.js +15 -0
- package/dist/node.d.ts +12 -13
- package/dist/node.js +19 -24
- package/dist/reporters.d.ts +7 -8
- package/dist/reporters.js +3 -3
- package/dist/runners.d.ts +3 -3
- package/dist/runners.js +35 -57
- package/dist/snapshot.js +2 -2
- package/dist/suite.js +2 -2
- package/dist/worker.js +82 -45
- package/dist/workers/forks.js +11 -10
- package/dist/workers/runVmTests.js +27 -46
- package/dist/workers/threads.js +11 -10
- package/dist/workers/vmForks.js +11 -10
- package/dist/workers/vmThreads.js +11 -10
- package/dist/workers.d.ts +5 -4
- package/dist/workers.js +17 -16
- package/package.json +22 -17
- package/dist/chunks/base.BaCDDRPG.js +0 -38
- package/dist/chunks/execute.Dt-pCVcL.js +0 -708
- package/dist/chunks/runBaseTests.DBVVLMSb.js +0 -129
- package/dist/execute.d.ts +0 -148
- package/dist/execute.js +0 -13
|
@@ -8,13 +8,13 @@ async function resolveCoverageProviderModule(options, loader) {
|
|
|
8
8
|
if (provider === "v8" || provider === "istanbul") {
|
|
9
9
|
let builtInModule = CoverageProviderMap[provider];
|
|
10
10
|
if (provider === "v8" && loader.isBrowser) builtInModule += "/browser";
|
|
11
|
-
const { default: coverageModule } = await loader.
|
|
11
|
+
const { default: coverageModule } = await loader.import(builtInModule);
|
|
12
12
|
if (!coverageModule) throw new Error(`Failed to load ${CoverageProviderMap[provider]}. Default export is missing.`);
|
|
13
13
|
return coverageModule;
|
|
14
14
|
}
|
|
15
15
|
let customProviderModule;
|
|
16
16
|
try {
|
|
17
|
-
customProviderModule = await loader.
|
|
17
|
+
customProviderModule = await loader.import(options.customProviderModule);
|
|
18
18
|
} catch (error) {
|
|
19
19
|
throw new Error(`Failed to load custom CoverageProviderModule from ${options.customProviderModule}`, { cause: error });
|
|
20
20
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ModuleExecutionInfo } from 'vite-node/client';
|
|
2
|
-
|
|
3
1
|
interface RuntimeCoverageModuleLoader {
|
|
4
|
-
|
|
2
|
+
import: (id: string) => Promise<{
|
|
5
3
|
default: RuntimeCoverageProviderModule;
|
|
6
4
|
}>;
|
|
7
5
|
isBrowser?: boolean;
|
|
8
|
-
moduleExecutionInfo?:
|
|
6
|
+
moduleExecutionInfo?: Map<string, {
|
|
7
|
+
startOffset: number;
|
|
8
|
+
}>;
|
|
9
9
|
}
|
|
10
10
|
interface RuntimeCoverageProviderModule {
|
|
11
11
|
/**
|
|
@@ -22,7 +22,9 @@ interface RuntimeCoverageProviderModule {
|
|
|
22
22
|
* Executed on after each run in the worker thread. Possible to return a payload passed to the provider
|
|
23
23
|
*/
|
|
24
24
|
takeCoverage?: (runtimeOptions?: {
|
|
25
|
-
moduleExecutionInfo?:
|
|
25
|
+
moduleExecutionInfo?: Map<string, {
|
|
26
|
+
startOffset: number;
|
|
27
|
+
}>;
|
|
26
28
|
}) => unknown | Promise<unknown>;
|
|
27
29
|
/**
|
|
28
30
|
* Executed after all tests have been run in the worker thread.
|
|
@@ -5,7 +5,7 @@ import { detectPackageManager, installPackage } from './index.D3XRDfWc.js';
|
|
|
5
5
|
import { p as prompt, f as findUp } from './index.X0nbfr6-.js';
|
|
6
6
|
import { x } from 'tinyexec';
|
|
7
7
|
import c from 'tinyrainbow';
|
|
8
|
-
import { c as configFiles } from './constants.
|
|
8
|
+
import { c as configFiles } from './constants.D_Q9UYh-.js';
|
|
9
9
|
import 'node:process';
|
|
10
10
|
import 'node:url';
|
|
11
11
|
import './_commonjsHelpers.BFTU3MAI.js';
|
|
@@ -42,8 +42,7 @@ test('renders name', async () => {
|
|
|
42
42
|
await expect.element(getByText('Hello Vitest!')).toBeInTheDocument()
|
|
43
43
|
})
|
|
44
44
|
`
|
|
45
|
-
}
|
|
46
|
-
const vueExample = {
|
|
45
|
+
}, vueExample = {
|
|
47
46
|
name: "HelloWorld.vue",
|
|
48
47
|
js: `
|
|
49
48
|
<script setup>
|
|
@@ -83,8 +82,7 @@ test('renders name', async () => {
|
|
|
83
82
|
await expect.element(getByText('Hello Vitest!')).toBeInTheDocument()
|
|
84
83
|
})
|
|
85
84
|
`
|
|
86
|
-
}
|
|
87
|
-
const svelteExample = {
|
|
85
|
+
}, svelteExample = {
|
|
88
86
|
name: "HelloWorld.svelte",
|
|
89
87
|
js: `
|
|
90
88
|
<script>
|
|
@@ -110,8 +108,7 @@ test('renders name', async () => {
|
|
|
110
108
|
await expect.element(getByText('Hello Vitest!')).toBeInTheDocument()
|
|
111
109
|
})
|
|
112
110
|
`
|
|
113
|
-
}
|
|
114
|
-
const markoExample = {
|
|
111
|
+
}, markoExample = {
|
|
115
112
|
name: "HelloWorld.marko",
|
|
116
113
|
js: `
|
|
117
114
|
class {
|
|
@@ -140,8 +137,7 @@ test('renders name', async () => {
|
|
|
140
137
|
expect(element).toBeInTheDocument()
|
|
141
138
|
})
|
|
142
139
|
`
|
|
143
|
-
}
|
|
144
|
-
const litExample = {
|
|
140
|
+
}, litExample = {
|
|
145
141
|
name: "HelloWorld.js",
|
|
146
142
|
js: `
|
|
147
143
|
import { html, LitElement } from 'lit'
|
|
@@ -195,8 +191,7 @@ test('renders name', async () => {
|
|
|
195
191
|
await expect.element(element).toBeInTheDocument()
|
|
196
192
|
})
|
|
197
193
|
`
|
|
198
|
-
}
|
|
199
|
-
const qwikExample = {
|
|
194
|
+
}, qwikExample = {
|
|
200
195
|
name: "HelloWorld.jsx",
|
|
201
196
|
js: `
|
|
202
197
|
import { component$ } from '@builder.io/qwik'
|
|
@@ -230,8 +225,7 @@ test('renders name', async () => {
|
|
|
230
225
|
await expect.element(getByText('Hello Vitest!')).toBeInTheDocument()
|
|
231
226
|
})
|
|
232
227
|
`
|
|
233
|
-
}
|
|
234
|
-
const vanillaExample = {
|
|
228
|
+
}, vanillaExample = {
|
|
235
229
|
name: "HelloWorld.js",
|
|
236
230
|
js: `
|
|
237
231
|
export default function HelloWorld({ name }) {
|
|
@@ -291,17 +285,13 @@ function getExampleTest(framework) {
|
|
|
291
285
|
async function generateExampleFiles(framework, lang) {
|
|
292
286
|
const example = getExampleTest(framework);
|
|
293
287
|
let fileName = example.name;
|
|
294
|
-
const folder = resolve(process.cwd(), "vitest-example");
|
|
295
|
-
const fileContent = example[lang];
|
|
288
|
+
const folder = resolve(process.cwd(), "vitest-example"), fileContent = example[lang];
|
|
296
289
|
if (!existsSync(folder)) await mkdir(folder, { recursive: true });
|
|
297
290
|
const isJSX = fileName.endsWith(".jsx");
|
|
298
291
|
if (isJSX && lang === "ts") fileName = fileName.replace(".jsx", ".tsx");
|
|
299
292
|
else if (fileName.endsWith(".js") && lang === "ts") fileName = fileName.replace(".js", ".ts");
|
|
300
|
-
const filePath = resolve(folder, fileName);
|
|
301
|
-
|
|
302
|
-
writeFileSync(filePath, fileContent.trimStart(), "utf-8");
|
|
303
|
-
writeFileSync(testPath, example.test.trimStart(), "utf-8");
|
|
304
|
-
return testPath;
|
|
293
|
+
const filePath = resolve(folder, fileName), testPath = resolve(folder, `HelloWorld.test.${isJSX ? `${lang}x` : lang}`);
|
|
294
|
+
return writeFileSync(filePath, fileContent.trimStart(), "utf-8"), writeFileSync(testPath, example.test.trimStart(), "utf-8"), testPath;
|
|
305
295
|
}
|
|
306
296
|
|
|
307
297
|
// eslint-disable-next-line no-console
|
|
@@ -435,8 +425,7 @@ function getFrameworkPluginPackage(framework) {
|
|
|
435
425
|
async function updateTsConfig(type) {
|
|
436
426
|
if (type == null) return;
|
|
437
427
|
const msg = `Add "${c.bold(type)}" to your tsconfig.json "${c.bold("compilerOptions.types")}" field to have better intellisense support.`;
|
|
438
|
-
log();
|
|
439
|
-
log(c.yellow("◼"), c.yellow(msg));
|
|
428
|
+
log(), log(c.yellow("◼"), c.yellow(msg));
|
|
440
429
|
}
|
|
441
430
|
function getLanguageOptions() {
|
|
442
431
|
return [{
|
|
@@ -454,10 +443,7 @@ async function installPackages(pkgManager, packages) {
|
|
|
454
443
|
log(c.green("✔"), c.bold("All packages are already installed."));
|
|
455
444
|
return;
|
|
456
445
|
}
|
|
457
|
-
log(c.cyan("◼"), c.bold("Installing packages..."))
|
|
458
|
-
log(c.cyan("◼"), packages.join(", "));
|
|
459
|
-
log();
|
|
460
|
-
await installPackage(packages, {
|
|
446
|
+
log(c.cyan("◼"), c.bold("Installing packages...")), log(c.cyan("◼"), packages.join(", ")), log(), await installPackage(packages, {
|
|
461
447
|
dev: true,
|
|
462
448
|
packageManager: pkgManager ?? void 0
|
|
463
449
|
});
|
|
@@ -468,8 +454,7 @@ function readPkgJson(path) {
|
|
|
468
454
|
return JSON.parse(content);
|
|
469
455
|
}
|
|
470
456
|
function getPossibleDefaults(dependencies) {
|
|
471
|
-
const provider = getPossibleProvider(dependencies);
|
|
472
|
-
const framework = getPossibleFramework(dependencies);
|
|
457
|
+
const provider = getPossibleProvider(dependencies), framework = getPossibleFramework(dependencies);
|
|
473
458
|
return {
|
|
474
459
|
lang: "ts",
|
|
475
460
|
provider,
|
|
@@ -477,20 +462,11 @@ function getPossibleDefaults(dependencies) {
|
|
|
477
462
|
};
|
|
478
463
|
}
|
|
479
464
|
function getPossibleFramework(dependencies) {
|
|
480
|
-
|
|
481
|
-
if (dependencies.react || dependencies["react-dom"]) return "react";
|
|
482
|
-
if (dependencies.svelte || dependencies["@sveltejs/kit"]) return "svelte";
|
|
483
|
-
if (dependencies.lit || dependencies["lit-html"]) return "lit";
|
|
484
|
-
if (dependencies.preact) return "preact";
|
|
485
|
-
if (dependencies["solid-js"] || dependencies["@solidjs/start"]) return "solid";
|
|
486
|
-
if (dependencies.marko) return "marko";
|
|
487
|
-
if (dependencies["@builder.io/qwik"] || dependencies["@qwik.dev/core"]) return "qwik";
|
|
488
|
-
return "vanilla";
|
|
465
|
+
return dependencies.vue || dependencies["vue-tsc"] || dependencies["@vue/reactivity"] ? "vue" : dependencies.react || dependencies["react-dom"] ? "react" : dependencies.svelte || dependencies["@sveltejs/kit"] ? "svelte" : dependencies.lit || dependencies["lit-html"] ? "lit" : dependencies.preact ? "preact" : dependencies["solid-js"] || dependencies["@solidjs/start"] ? "solid" : dependencies.marko ? "marko" : dependencies["@builder.io/qwik"] || dependencies["@qwik.dev/core"] ? "qwik" : "vanilla";
|
|
489
466
|
}
|
|
490
467
|
function getPossibleProvider(dependencies) {
|
|
491
|
-
if (dependencies.webdriverio || dependencies["@wdio/cli"] || dependencies["@wdio/config"]) return "webdriverio";
|
|
492
468
|
// playwright is the default recommendation
|
|
493
|
-
return "playwright";
|
|
469
|
+
return dependencies.webdriverio || dependencies["@wdio/cli"] || dependencies["@wdio/config"] ? "webdriverio" : "playwright";
|
|
494
470
|
}
|
|
495
471
|
function getProviderDocsLink(provider) {
|
|
496
472
|
switch (provider) {
|
|
@@ -524,9 +500,7 @@ function getFrameworkImportInfo(framework) {
|
|
|
524
500
|
}
|
|
525
501
|
}
|
|
526
502
|
async function generateFrameworkConfigFile(options) {
|
|
527
|
-
const { importName, isNamedExport } = getFrameworkImportInfo(options.framework)
|
|
528
|
-
const frameworkImport = isNamedExport ? `import { ${importName} } from '${options.frameworkPlugin}'` : `import ${importName} from '${options.frameworkPlugin}'`;
|
|
529
|
-
const configContent = [
|
|
503
|
+
const { importName, isNamedExport } = getFrameworkImportInfo(options.framework), frameworkImport = isNamedExport ? `import { ${importName} } from '${options.frameworkPlugin}'` : `import ${importName} from '${options.frameworkPlugin}'`, configContent = [
|
|
530
504
|
`import { defineConfig } from 'vitest/config'`,
|
|
531
505
|
options.frameworkPlugin ? frameworkImport : null,
|
|
532
506
|
``,
|
|
@@ -553,9 +527,7 @@ async function updatePkgJsonScripts(pkgJsonPath, vitestScript) {
|
|
|
553
527
|
await writeFile(pkgJsonPath, `${JSON.stringify(pkg, null, 2)}\n`, "utf-8");
|
|
554
528
|
} else {
|
|
555
529
|
const pkg = JSON.parse(readFileSync(pkgJsonPath, "utf-8"));
|
|
556
|
-
pkg.scripts = pkg.scripts || {};
|
|
557
|
-
pkg.scripts["test:browser"] = vitestScript;
|
|
558
|
-
await writeFile(pkgJsonPath, `${JSON.stringify(pkg, null, 2)}\n`, "utf-8");
|
|
530
|
+
pkg.scripts = pkg.scripts || {}, pkg.scripts["test:browser"] = vitestScript, await writeFile(pkgJsonPath, `${JSON.stringify(pkg, null, 2)}\n`, "utf-8");
|
|
559
531
|
}
|
|
560
532
|
log(c.green("✔"), "Added \"test:browser\" script to your package.json.");
|
|
561
533
|
}
|
|
@@ -581,14 +553,10 @@ function getPlaywrightRunArgs(pkgManager) {
|
|
|
581
553
|
}
|
|
582
554
|
async function create() {
|
|
583
555
|
log(c.cyan("◼"), "This utility will help you set up a browser testing environment.\n");
|
|
584
|
-
const pkgJsonPath = resolve(process.cwd(), "package.json")
|
|
585
|
-
const pkg = readPkgJson(pkgJsonPath) || {};
|
|
586
|
-
const dependencies = {
|
|
556
|
+
const pkgJsonPath = resolve(process.cwd(), "package.json"), pkg = readPkgJson(pkgJsonPath) || {}, dependencies = {
|
|
587
557
|
...pkg.dependencies,
|
|
588
558
|
...pkg.devDependencies
|
|
589
|
-
}
|
|
590
|
-
const defaults = getPossibleDefaults(dependencies);
|
|
591
|
-
const { lang } = await prompt({
|
|
559
|
+
}, defaults = getPossibleDefaults(dependencies), { lang } = await prompt({
|
|
592
560
|
type: "select",
|
|
593
561
|
name: "lang",
|
|
594
562
|
message: "Choose a language for your tests",
|
|
@@ -626,30 +594,25 @@ async function create() {
|
|
|
626
594
|
message: `Install Playwright browsers (can be done manually via 'pnpm exec playwright install')?`
|
|
627
595
|
}));
|
|
628
596
|
if (installPlaywright == null) return fail();
|
|
629
|
-
const dependenciesToInstall = ["@vitest/browser"];
|
|
630
|
-
const frameworkPackage = getFrameworkTestPackage(framework);
|
|
597
|
+
const dependenciesToInstall = ["@vitest/browser"], frameworkPackage = getFrameworkTestPackage(framework);
|
|
631
598
|
if (frameworkPackage) dependenciesToInstall.push(frameworkPackage);
|
|
632
599
|
const providerPkg = getProviderPackageNames(provider);
|
|
633
600
|
if (providerPkg.pkg) dependenciesToInstall.push(providerPkg.pkg);
|
|
634
601
|
const frameworkPlugin = getFrameworkPluginPackage(framework);
|
|
635
602
|
if (frameworkPlugin) dependenciesToInstall.push(frameworkPlugin);
|
|
636
603
|
const pkgManager = await detectPackageManager();
|
|
637
|
-
log();
|
|
638
|
-
await installPackages(pkgManager, dependenciesToInstall.filter((pkg) => !dependencies[pkg]));
|
|
604
|
+
log(), await installPackages(pkgManager, dependenciesToInstall.filter((pkg) => !dependencies[pkg]));
|
|
639
605
|
const rootConfig = await findUp(configFiles, { cwd: process.cwd() });
|
|
640
606
|
let scriptCommand = "vitest";
|
|
641
|
-
log()
|
|
642
|
-
if (rootConfig) {
|
|
607
|
+
if (log(), rootConfig) {
|
|
643
608
|
const configPath = resolve(dirname(rootConfig), `vitest.browser.config.${lang}`);
|
|
644
|
-
scriptCommand = `vitest --config=${relative(process.cwd(), configPath)}
|
|
645
|
-
await generateFrameworkConfigFile({
|
|
609
|
+
scriptCommand = `vitest --config=${relative(process.cwd(), configPath)}`, await generateFrameworkConfigFile({
|
|
646
610
|
configPath,
|
|
647
611
|
framework,
|
|
648
612
|
frameworkPlugin,
|
|
649
613
|
provider,
|
|
650
614
|
browsers
|
|
651
|
-
})
|
|
652
|
-
log(
|
|
615
|
+
}), log(
|
|
653
616
|
c.green("✔"),
|
|
654
617
|
"Created a new config file for browser tests:",
|
|
655
618
|
c.bold(relative(process.cwd(), configPath)),
|
|
@@ -666,23 +629,17 @@ async function create() {
|
|
|
666
629
|
frameworkPlugin,
|
|
667
630
|
provider,
|
|
668
631
|
browsers
|
|
669
|
-
});
|
|
670
|
-
log(c.green("✔"), "Created a config file for browser tests:", c.bold(relative(process.cwd(), configPath)));
|
|
632
|
+
}), log(c.green("✔"), "Created a config file for browser tests:", c.bold(relative(process.cwd(), configPath)));
|
|
671
633
|
}
|
|
672
|
-
log()
|
|
673
|
-
await updatePkgJsonScripts(pkgJsonPath, scriptCommand);
|
|
674
|
-
if (installPlaywright) {
|
|
634
|
+
if (log(), await updatePkgJsonScripts(pkgJsonPath, scriptCommand), installPlaywright) {
|
|
675
635
|
log();
|
|
676
|
-
const [command, ...args] = getPlaywrightRunArgs(pkgManager)
|
|
677
|
-
const allArgs = [
|
|
636
|
+
const [command, ...args] = getPlaywrightRunArgs(pkgManager), allArgs = [
|
|
678
637
|
...args,
|
|
679
638
|
"playwright",
|
|
680
639
|
"install",
|
|
681
640
|
"--with-deps"
|
|
682
641
|
];
|
|
683
|
-
log(c.cyan("◼"), `Installing Playwright dependencies with \`${c.bold(command)} ${c.bold(allArgs.join(" "))}\`...`)
|
|
684
|
-
log();
|
|
685
|
-
await x(command, allArgs, { nodeOptions: { stdio: [
|
|
642
|
+
log(c.cyan("◼"), `Installing Playwright dependencies with \`${c.bold(command)} ${c.bold(allArgs.join(" "))}\`...`), log(), await x(command, allArgs, { nodeOptions: { stdio: [
|
|
686
643
|
"pipe",
|
|
687
644
|
"inherit",
|
|
688
645
|
"inherit"
|
|
@@ -692,10 +649,7 @@ async function create() {
|
|
|
692
649
|
if (lang === "ts") await updateTsConfig(providerPkg?.types);
|
|
693
650
|
log();
|
|
694
651
|
const exampleTestFile = await generateExampleFiles(framework, lang);
|
|
695
|
-
log(c.green("✔"), "Created example test file in", c.bold(relative(process.cwd(), exampleTestFile)));
|
|
696
|
-
log(c.dim(" You can safely delete this file once you have written your own tests."));
|
|
697
|
-
log();
|
|
698
|
-
log(c.cyan("◼"), "All done! Run your tests with", c.bold(getRunScript(pkgManager)));
|
|
652
|
+
log(c.green("✔"), "Created example test file in", c.bold(relative(process.cwd(), exampleTestFile))), log(c.dim(" You can safely delete this file once you have written your own tests.")), log(), log(c.cyan("◼"), "All done! Run your tests with", c.bold(getRunScript(pkgManager)));
|
|
699
653
|
}
|
|
700
654
|
|
|
701
655
|
export { create };
|
|
@@ -37,34 +37,23 @@ class MockDate extends RealDate {
|
|
|
37
37
|
date = new RealDate(y);
|
|
38
38
|
break;
|
|
39
39
|
default:
|
|
40
|
-
d = typeof d === "undefined" ? 1 : d;
|
|
41
|
-
h = h || 0;
|
|
42
|
-
M = M || 0;
|
|
43
|
-
s = s || 0;
|
|
44
|
-
ms = ms || 0;
|
|
45
|
-
date = new RealDate(y, m, d, h, M, s, ms);
|
|
40
|
+
d = typeof d === "undefined" ? 1 : d, h = h || 0, M = M || 0, s = s || 0, ms = ms || 0, date = new RealDate(y, m, d, h, M, s, ms);
|
|
46
41
|
break;
|
|
47
42
|
}
|
|
48
|
-
Object.setPrototypeOf(date, MockDate.prototype);
|
|
49
|
-
return date;
|
|
43
|
+
return Object.setPrototypeOf(date, MockDate.prototype), date;
|
|
50
44
|
}
|
|
51
45
|
}
|
|
52
|
-
MockDate.UTC = RealDate.UTC
|
|
53
|
-
MockDate.now = function() {
|
|
46
|
+
MockDate.UTC = RealDate.UTC, MockDate.now = function() {
|
|
54
47
|
return new MockDate().valueOf();
|
|
55
|
-
}
|
|
56
|
-
MockDate.parse = function(dateString) {
|
|
48
|
+
}, MockDate.parse = function(dateString) {
|
|
57
49
|
return RealDate.parse(dateString);
|
|
58
|
-
}
|
|
59
|
-
MockDate.toString = function() {
|
|
50
|
+
}, MockDate.toString = function() {
|
|
60
51
|
return RealDate.toString();
|
|
61
52
|
};
|
|
62
53
|
function mockDate(date) {
|
|
63
54
|
const dateObj = new RealDate(date.valueOf());
|
|
64
55
|
if (Number.isNaN(dateObj.getTime())) throw new TypeError(`mockdate: The time set is an invalid date: ${date}`);
|
|
65
|
-
|
|
66
|
-
globalThis.Date = MockDate;
|
|
67
|
-
now = dateObj.valueOf();
|
|
56
|
+
globalThis.Date = MockDate, now = dateObj.valueOf();
|
|
68
57
|
}
|
|
69
58
|
function resetDate() {
|
|
70
59
|
globalThis.Date = RealDate;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
type Awaitable<T> = T | PromiseLike<T>;
|
|
2
2
|
type Arrayable<T> = T | Array<T>;
|
|
3
|
-
type TransformMode = "web" | "ssr";
|
|
4
3
|
interface AfterSuiteRunMeta {
|
|
5
4
|
coverage?: unknown;
|
|
6
5
|
testFiles: string[];
|
|
7
|
-
|
|
6
|
+
environment: string;
|
|
8
7
|
projectName?: string;
|
|
9
8
|
}
|
|
10
9
|
interface UserConsoleLog {
|
|
@@ -22,6 +21,19 @@ interface ModuleGraphData {
|
|
|
22
21
|
inlined: string[];
|
|
23
22
|
}
|
|
24
23
|
interface ProvidedContext {}
|
|
24
|
+
interface ResolveFunctionResult {
|
|
25
|
+
id: string;
|
|
26
|
+
file: string;
|
|
27
|
+
url: string;
|
|
28
|
+
}
|
|
29
|
+
interface FetchCachedFileSystemResult {
|
|
30
|
+
cached: true;
|
|
31
|
+
tmp: string;
|
|
32
|
+
id: string;
|
|
33
|
+
file: string | null;
|
|
34
|
+
url: string;
|
|
35
|
+
invalidate: boolean;
|
|
36
|
+
}
|
|
25
37
|
// These need to be compatible with Tinyrainbow's bg-colors, and CSS's background-color
|
|
26
38
|
type LabelColor = "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white";
|
|
27
39
|
|
|
@@ -36,9 +48,19 @@ interface VmEnvironmentReturn {
|
|
|
36
48
|
}
|
|
37
49
|
interface Environment {
|
|
38
50
|
name: string;
|
|
39
|
-
|
|
51
|
+
/**
|
|
52
|
+
* @deprecated use `viteEnvironment` instead. Uses `name` by default
|
|
53
|
+
*/
|
|
54
|
+
transformMode?: "web" | "ssr";
|
|
55
|
+
/**
|
|
56
|
+
* Environment initiated by the Vite server. It is usually available
|
|
57
|
+
* as `vite.server.environments.${name}`.
|
|
58
|
+
*
|
|
59
|
+
* By default, fallbacks to `name`.
|
|
60
|
+
*/
|
|
61
|
+
viteEnvironment?: "client" | "ssr" | ({} & string);
|
|
40
62
|
setupVM?: (options: Record<string, any>) => Awaitable<VmEnvironmentReturn>;
|
|
41
63
|
setup: (global: any, options: Record<string, any>) => Awaitable<EnvironmentReturn>;
|
|
42
64
|
}
|
|
43
65
|
|
|
44
|
-
export type { AfterSuiteRunMeta as A, Environment as E, LabelColor as L, ModuleGraphData as M, ProvidedContext as P,
|
|
66
|
+
export type { AfterSuiteRunMeta as A, Environment as E, FetchCachedFileSystemResult as F, LabelColor as L, ModuleGraphData as M, ProvidedContext as P, ResolveFunctionResult as R, UserConsoleLog as U, VmEnvironmentReturn as V, EnvironmentReturn as a, Awaitable as b, Arrayable as c };
|
|
@@ -11,8 +11,7 @@ class VitestGit {
|
|
|
11
11
|
try {
|
|
12
12
|
result = await x("git", args, { nodeOptions: { cwd: this.root } });
|
|
13
13
|
} catch (e) {
|
|
14
|
-
e.message = e.stderr;
|
|
15
|
-
throw e;
|
|
14
|
+
throw e.message = e.stderr, e;
|
|
16
15
|
}
|
|
17
16
|
return result.stdout.split("\n").filter((s) => s !== "").map((changedPath) => resolve(this.root, changedPath));
|
|
18
17
|
}
|
|
@@ -2,7 +2,7 @@ import { PromisifyAssertion, Tester, ExpectStatic } from '@vitest/expect';
|
|
|
2
2
|
import { Plugin } from '@vitest/pretty-format';
|
|
3
3
|
import { SnapshotState } from '@vitest/snapshot';
|
|
4
4
|
import { B as BenchmarkResult } from './benchmark.d.DAaHLpsq.js';
|
|
5
|
-
import { U as UserConsoleLog } from './environment.d.
|
|
5
|
+
import { U as UserConsoleLog } from './environment.d.2fYMoz3o.js';
|
|
6
6
|
|
|
7
7
|
declare global {
|
|
8
8
|
// eslint-disable-next-line ts/no-namespace
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import { g as globalApis } from './constants.
|
|
2
|
-
import { V as VitestIndex } from './index.
|
|
3
|
-
import './vi.
|
|
1
|
+
import { g as globalApis } from './constants.D_Q9UYh-.js';
|
|
2
|
+
import { V as VitestIndex } from './index.AR8aAkCC.js';
|
|
3
|
+
import './vi.BfdOiD4j.js';
|
|
4
4
|
import '@vitest/expect';
|
|
5
5
|
import '@vitest/runner';
|
|
6
6
|
import '@vitest/runner/utils';
|
|
7
7
|
import 'chai';
|
|
8
|
-
import './utils.
|
|
8
|
+
import './utils.C7__0Iv5.js';
|
|
9
9
|
import '@vitest/utils';
|
|
10
10
|
import './_commonjsHelpers.BFTU3MAI.js';
|
|
11
11
|
import '@vitest/snapshot';
|
|
12
12
|
import '@vitest/utils/error';
|
|
13
13
|
import '@vitest/spy';
|
|
14
14
|
import '@vitest/utils/source-map';
|
|
15
|
-
import './date.
|
|
16
|
-
import './benchmark.
|
|
15
|
+
import './date.-jtEtIeV.js';
|
|
16
|
+
import './benchmark.UW6Ezvxy.js';
|
|
17
17
|
import 'expect-type';
|
|
18
|
+
import 'vite/module-runner';
|
|
18
19
|
|
|
19
20
|
function registerApiGlobally() {
|
|
20
21
|
globalApis.forEach((api) => {
|
|
@@ -2,7 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import { getTasks, getFullName, getTests } from '@vitest/runner/utils';
|
|
3
3
|
import * as pathe from 'pathe';
|
|
4
4
|
import c from 'tinyrainbow';
|
|
5
|
-
import { g as getStateSymbol, t as truncateString, F as F_RIGHT, D as DefaultReporter, f as formatProjectName } from './index.
|
|
5
|
+
import { g as getStateSymbol, t as truncateString, F as F_RIGHT, D as DefaultReporter, f as formatProjectName } from './index.VNI-1z5c.js';
|
|
6
6
|
import { stripVTControlCharacters } from 'node:util';
|
|
7
7
|
import { notNullish } from '@vitest/utils';
|
|
8
8
|
|
|
@@ -98,19 +98,16 @@ function renderBenchmark(result, widths) {
|
|
|
98
98
|
].join(" ");
|
|
99
99
|
}
|
|
100
100
|
function renderTable(options) {
|
|
101
|
-
const output = [];
|
|
102
|
-
const benchMap = {};
|
|
101
|
+
const output = [], benchMap = {};
|
|
103
102
|
for (const task of options.tasks) if (task.meta.benchmark && task.result?.benchmark) benchMap[task.id] = {
|
|
104
103
|
current: task.result.benchmark,
|
|
105
104
|
baseline: options.compare?.[task.id]
|
|
106
105
|
};
|
|
107
|
-
const benchCount = Object.entries(benchMap).length;
|
|
108
|
-
const columnWidths = computeColumnWidths(Object.values(benchMap).flatMap((v) => [v.current, v.baseline]).filter(notNullish));
|
|
106
|
+
const benchCount = Object.entries(benchMap).length, columnWidths = computeColumnWidths(Object.values(benchMap).flatMap((v) => [v.current, v.baseline]).filter(notNullish));
|
|
109
107
|
let idx = 0;
|
|
110
108
|
const padding = " ".repeat(1 );
|
|
111
109
|
for (const task of options.tasks) {
|
|
112
|
-
const duration = task.result?.duration;
|
|
113
|
-
const bench = benchMap[task.id];
|
|
110
|
+
const duration = task.result?.duration, bench = benchMap[task.id];
|
|
114
111
|
let prefix = "";
|
|
115
112
|
if (idx === 0 && task.meta?.benchmark) prefix += `${renderTableHead(columnWidths)}\n${padding}`;
|
|
116
113
|
prefix += ` ${getStateSymbol(task)} `;
|
|
@@ -126,8 +123,7 @@ function renderTable(options) {
|
|
|
126
123
|
let body = renderBenchmark(bench.current, columnWidths);
|
|
127
124
|
if (options.compare && bench.baseline) {
|
|
128
125
|
if (bench.current.hz) {
|
|
129
|
-
const diff = bench.current.hz / bench.baseline.hz;
|
|
130
|
-
const diffFixed = diff.toFixed(2);
|
|
126
|
+
const diff = bench.current.hz / bench.baseline.hz, diffFixed = diff.toFixed(2);
|
|
131
127
|
if (diffFixed === "1.0.0") body += c.gray(` [${diffFixed}x]`);
|
|
132
128
|
if (diff > 1) body += c.blue(` [${diffFixed}x] ⇑`);
|
|
133
129
|
else body += c.red(` [${diffFixed}x] ⇓`);
|
|
@@ -144,8 +140,7 @@ function renderTable(options) {
|
|
|
144
140
|
if (task.result?.state !== "pass" && outputMap.get(task) != null) {
|
|
145
141
|
let data = outputMap.get(task);
|
|
146
142
|
if (typeof data === "string") {
|
|
147
|
-
data = stripVTControlCharacters(data.trim().split("\n").filter(Boolean).pop());
|
|
148
|
-
if (data === "") data = void 0;
|
|
143
|
+
if (data = stripVTControlCharacters(data.trim().split("\n").filter(Boolean).pop()), data === "") data = void 0;
|
|
149
144
|
}
|
|
150
145
|
if (data != null) {
|
|
151
146
|
const out = ` ${" ".repeat(options.level)}${F_RIGHT} ${data}`;
|
|
@@ -160,8 +155,7 @@ function renderTable(options) {
|
|
|
160
155
|
class BenchmarkReporter extends DefaultReporter {
|
|
161
156
|
compare;
|
|
162
157
|
async onInit(ctx) {
|
|
163
|
-
super.onInit(ctx)
|
|
164
|
-
if (this.ctx.config.benchmark?.compare) {
|
|
158
|
+
if (super.onInit(ctx), this.ctx.config.benchmark?.compare) {
|
|
165
159
|
const compareFile = pathe.resolve(this.ctx.config.root, this.ctx.config.benchmark?.compare);
|
|
166
160
|
try {
|
|
167
161
|
this.compare = flattenFormattedBenchmarkReport(JSON.parse(await fs.promises.readFile(compareFile, "utf-8")));
|
|
@@ -179,8 +173,7 @@ class BenchmarkReporter extends DefaultReporter {
|
|
|
179
173
|
}
|
|
180
174
|
}
|
|
181
175
|
onTestSuiteResult(testSuite) {
|
|
182
|
-
super.onTestSuiteResult(testSuite);
|
|
183
|
-
this.printSuiteTable(testSuite);
|
|
176
|
+
super.onTestSuiteResult(testSuite), this.printSuiteTable(testSuite);
|
|
184
177
|
}
|
|
185
178
|
printTestModule(testModule) {
|
|
186
179
|
this.printSuiteTable(testModule);
|
|
@@ -188,13 +181,11 @@ class BenchmarkReporter extends DefaultReporter {
|
|
|
188
181
|
printSuiteTable(testTask) {
|
|
189
182
|
const state = testTask.state();
|
|
190
183
|
if (state === "pending" || state === "queued") return;
|
|
191
|
-
const benches = testTask.task.tasks.filter((t) => t.meta.benchmark);
|
|
192
|
-
const duration = testTask.task.result?.duration || 0;
|
|
184
|
+
const benches = testTask.task.tasks.filter((t) => t.meta.benchmark), duration = testTask.task.result?.duration || 0;
|
|
193
185
|
if (benches.length > 0 && benches.every((t) => t.result?.state !== "run" && t.result?.state !== "queued")) {
|
|
194
186
|
let title = `\n ${getStateSymbol(testTask.task)} ${formatProjectName(testTask.project)}${getFullName(testTask.task, c.dim(" > "))}`;
|
|
195
187
|
if (duration != null && duration > this.ctx.config.slowTestThreshold) title += c.yellow(` ${Math.round(duration)}${c.dim("ms")}`);
|
|
196
|
-
this.log(title)
|
|
197
|
-
this.log(renderTable({
|
|
188
|
+
this.log(title), this.log(renderTable({
|
|
198
189
|
tasks: benches,
|
|
199
190
|
level: 1,
|
|
200
191
|
columns: this.ctx.logger.getColumns(),
|
|
@@ -204,17 +195,16 @@ class BenchmarkReporter extends DefaultReporter {
|
|
|
204
195
|
}));
|
|
205
196
|
}
|
|
206
197
|
}
|
|
207
|
-
async
|
|
208
|
-
super.
|
|
198
|
+
async onTestRunEnd(testModules, unhandledErrors, reason) {
|
|
199
|
+
super.onTestRunEnd(testModules, unhandledErrors, reason);
|
|
209
200
|
// write output for future comparison
|
|
210
201
|
let outputFile = this.ctx.config.benchmark?.outputJson;
|
|
211
202
|
if (outputFile) {
|
|
212
203
|
outputFile = pathe.resolve(this.ctx.config.root, outputFile);
|
|
213
204
|
const outputDirectory = pathe.dirname(outputFile);
|
|
214
205
|
if (!fs.existsSync(outputDirectory)) await fs.promises.mkdir(outputDirectory, { recursive: true });
|
|
215
|
-
const output = createBenchmarkJsonReport(files);
|
|
216
|
-
await fs.promises.writeFile(outputFile, JSON.stringify(output, null, 2));
|
|
217
|
-
this.log(`Benchmark report written to ${outputFile}`);
|
|
206
|
+
const files = testModules.map((t) => t.task.file), output = createBenchmarkJsonReport(files);
|
|
207
|
+
await fs.promises.writeFile(outputFile, JSON.stringify(output, null, 2)), this.log(`Benchmark report written to ${outputFile}`);
|
|
218
208
|
}
|
|
219
209
|
}
|
|
220
210
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { c as createExpect, a as globalExpect, i as inject, v as vi, b as vitest } from './vi.
|
|
2
|
-
import { b as bench } from './benchmark.
|
|
1
|
+
import { c as createExpect, a as globalExpect, i as inject, v as vi, b as vitest } from './vi.BfdOiD4j.js';
|
|
2
|
+
import { b as bench } from './benchmark.UW6Ezvxy.js';
|
|
3
3
|
import { expectTypeOf } from 'expect-type';
|
|
4
4
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, suite, test } from '@vitest/runner';
|
|
5
|
+
import { EvaluatedModules } from 'vite/module-runner';
|
|
5
6
|
import * as chai from 'chai';
|
|
6
7
|
import { assert, should } from 'chai';
|
|
7
8
|
|
|
@@ -9,6 +10,7 @@ const assertType = function assertType() {};
|
|
|
9
10
|
|
|
10
11
|
var VitestIndex = /*#__PURE__*/Object.freeze({
|
|
11
12
|
__proto__: null,
|
|
13
|
+
EvaluatedModules: EvaluatedModules,
|
|
12
14
|
afterAll: afterAll,
|
|
13
15
|
afterEach: afterEach,
|
|
14
16
|
assert: assert,
|