vitest 3.2.4 → 4.0.0-beta.10
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 +2 -2
- package/dist/browser.d.ts +13 -16
- package/dist/browser.js +6 -5
- package/dist/chunks/base.Cjha6usc.js +129 -0
- package/dist/chunks/{benchmark.CYdenmiT.js → benchmark.CJUa-Hsa.js} +6 -8
- package/dist/chunks/{benchmark.d.BwvBVTda.d.ts → benchmark.d.DAaHLpsq.d.ts} +4 -4
- package/dist/chunks/browser.d.yFAklsD1.d.ts +18 -0
- package/dist/chunks/{cac.Cb-PYCCB.js → cac.DCxo_nSu.js} +72 -163
- package/dist/chunks/{cli-api.BkDphVBG.js → cli-api.BJJXh9BV.js} +1331 -1678
- package/dist/chunks/{config.d.D2ROskhv.d.ts → config.d.B_LthbQq.d.ts} +59 -65
- package/dist/chunks/{console.CtFJOzRO.js → console.7h5kHUIf.js} +34 -70
- package/dist/chunks/{constants.DnKduX2e.js → constants.D_Q9UYh-.js} +1 -9
- package/dist/chunks/{coverage.DL5VHqXY.js → coverage.BCU-r2QL.js} +538 -765
- package/dist/chunks/{coverage.DVF1vEu8.js → coverage.D_JHT54q.js} +2 -2
- package/dist/chunks/{coverage.d.S9RMNXIe.d.ts → coverage.d.BZtK59WP.d.ts} +10 -8
- package/dist/chunks/{creator.GK6I-cL4.js → creator.08Gi-vCA.js} +93 -77
- package/dist/chunks/{date.Bq6ZW5rf.js → date.-jtEtIeV.js} +6 -17
- package/dist/chunks/{defaults.B7q_naMc.js → defaults.CXFFjsi8.js} +2 -42
- package/dist/chunks/environment.d.BsToaxti.d.ts +65 -0
- package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
- package/dist/chunks/{global.d.MAmajcmJ.d.ts → global.d.BK3X7FW1.d.ts} +7 -32
- package/dist/chunks/{globals.DEHgCU4V.js → globals.DG-S3xFe.js} +8 -8
- package/dist/chunks/{index.VByaPkjc.js → index.BIP7prJq.js} +472 -803
- package/dist/chunks/{index.B521nVV-.js → index.Bgo3tNWt.js} +23 -4
- package/dist/chunks/{index.BCWujgDG.js → index.BjKEiSn0.js} +14 -24
- package/dist/chunks/{index.CdQS2e2Q.js → index.CMfqw92x.js} +7 -8
- package/dist/chunks/{index.CmSc2RE5.js → index.DIWhzsUh.js} +72 -118
- package/dist/chunks/{inspector.C914Efll.js → inspector.CvQD-Nie.js} +10 -25
- package/dist/chunks/moduleRunner.d.D9nBoC4p.d.ts +201 -0
- package/dist/chunks/moduleTransport.I-bgQy0S.js +19 -0
- package/dist/chunks/{node.fjCdwEIl.js → node.CyipiPvJ.js} +1 -1
- package/dist/chunks/plugin.d.BMVSnsGV.d.ts +9 -0
- package/dist/chunks/{reporters.d.BFLkQcL6.d.ts → reporters.d.BUWjmRYq.d.ts} +2086 -2146
- package/dist/chunks/resolveSnapshotEnvironment.Bkht6Yor.js +81 -0
- package/dist/chunks/resolver.Bx6lE0iq.js +119 -0
- package/dist/chunks/rpc.BKr6mtxz.js +65 -0
- package/dist/chunks/{setup-common.Dd054P77.js → setup-common.uiMcU3cv.js} +17 -29
- package/dist/chunks/startModuleRunner.p67gbNo9.js +665 -0
- package/dist/chunks/{suite.d.FvehnV49.d.ts → suite.d.BJWk38HB.d.ts} +1 -1
- package/dist/chunks/test.BiqSKISg.js +214 -0
- package/dist/chunks/{typechecker.DRKU1-1g.js → typechecker.DB-fIMaH.js} +165 -234
- package/dist/chunks/{utils.CAioKnHs.js → utils.C2YI6McM.js} +5 -14
- package/dist/chunks/{utils.XdZDrNZV.js → utils.D2R2NiOH.js} +8 -27
- package/dist/chunks/{vi.bdSIJ99Y.js → vi.ZPgvtBao.js} +156 -305
- package/dist/chunks/{vm.BThCzidc.js → vm.Ca0Y0W5f.js} +116 -226
- package/dist/chunks/{worker.d.1GmBbd7G.d.ts → worker.d.BDsXGkwh.d.ts} +31 -32
- package/dist/chunks/{worker.d.CKwWzBSj.d.ts → worker.d.BNcX_2mH.d.ts} +1 -1
- package/dist/cli.js +10 -10
- package/dist/config.cjs +5 -58
- package/dist/config.d.ts +72 -71
- package/dist/config.js +3 -9
- package/dist/coverage.d.ts +31 -24
- package/dist/coverage.js +9 -9
- package/dist/environments.d.ts +9 -14
- package/dist/environments.js +1 -1
- package/dist/index.d.ts +52 -213
- package/dist/index.js +7 -9
- package/dist/module-evaluator.d.ts +13 -0
- package/dist/module-evaluator.js +276 -0
- package/dist/module-runner.js +15 -0
- package/dist/node.d.ts +62 -51
- package/dist/node.js +26 -42
- package/dist/reporters.d.ts +11 -12
- package/dist/reporters.js +12 -12
- package/dist/runners.d.ts +3 -4
- package/dist/runners.js +13 -231
- package/dist/snapshot.js +2 -2
- package/dist/suite.d.ts +2 -2
- package/dist/suite.js +2 -2
- package/dist/worker.js +90 -47
- package/dist/workers/forks.js +34 -10
- package/dist/workers/runVmTests.js +36 -56
- package/dist/workers/threads.js +34 -10
- package/dist/workers/vmForks.js +11 -10
- package/dist/workers/vmThreads.js +11 -10
- package/dist/workers.d.ts +5 -7
- package/dist/workers.js +35 -17
- package/globals.d.ts +17 -17
- package/package.json +32 -31
- package/dist/chunks/base.DfmxU-tU.js +0 -38
- package/dist/chunks/environment.d.cL3nLXbE.d.ts +0 -119
- package/dist/chunks/execute.B7h3T_Hc.js +0 -708
- package/dist/chunks/index.CwejwG0H.js +0 -105
- package/dist/chunks/rpc.-pEldfrD.js +0 -83
- package/dist/chunks/runBaseTests.9Ij9_de-.js +0 -129
- package/dist/chunks/vite.d.CMLlLIFP.d.ts +0 -25
- package/dist/execute.d.ts +0 -150
- 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
|
-
|
|
5
|
-
default: RuntimeCoverageProviderModule
|
|
2
|
+
import: (id: string) => Promise<{
|
|
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
|
/**
|
|
@@ -16,19 +16,21 @@ interface RuntimeCoverageProviderModule {
|
|
|
16
16
|
* Executed before tests are run in the worker thread.
|
|
17
17
|
*/
|
|
18
18
|
startCoverage?: (runtimeOptions: {
|
|
19
|
-
isolate: boolean
|
|
19
|
+
isolate: boolean;
|
|
20
20
|
}) => unknown | Promise<unknown>;
|
|
21
21
|
/**
|
|
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.
|
|
29
31
|
*/
|
|
30
32
|
stopCoverage?: (runtimeOptions: {
|
|
31
|
-
isolate: boolean
|
|
33
|
+
isolate: boolean;
|
|
32
34
|
}) => unknown | Promise<unknown>;
|
|
33
35
|
}
|
|
34
36
|
|
|
@@ -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,15 +42,14 @@ 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>
|
|
50
49
|
defineProps({
|
|
51
50
|
name: String
|
|
52
51
|
})
|
|
53
|
-
|
|
52
|
+
<\/script>
|
|
54
53
|
|
|
55
54
|
<template>
|
|
56
55
|
<div>
|
|
@@ -63,7 +62,7 @@ defineProps({
|
|
|
63
62
|
defineProps<{
|
|
64
63
|
name: string
|
|
65
64
|
}>()
|
|
66
|
-
|
|
65
|
+
<\/script>
|
|
67
66
|
|
|
68
67
|
<template>
|
|
69
68
|
<div>
|
|
@@ -83,20 +82,19 @@ 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>
|
|
91
89
|
export let name
|
|
92
|
-
|
|
90
|
+
<\/script>
|
|
93
91
|
|
|
94
92
|
<h1>Hello {name}!</h1>
|
|
95
93
|
`,
|
|
96
94
|
ts: `
|
|
97
95
|
<script lang="ts">
|
|
98
96
|
export let name: string
|
|
99
|
-
|
|
97
|
+
<\/script>
|
|
100
98
|
|
|
101
99
|
<h1>Hello {name}!</h1>
|
|
102
100
|
`,
|
|
@@ -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,41 @@ test('renders name', async () => {
|
|
|
195
191
|
await expect.element(element).toBeInTheDocument()
|
|
196
192
|
})
|
|
197
193
|
`
|
|
198
|
-
}
|
|
199
|
-
|
|
194
|
+
}, qwikExample = {
|
|
195
|
+
name: "HelloWorld.jsx",
|
|
196
|
+
js: `
|
|
197
|
+
import { component$ } from '@builder.io/qwik'
|
|
198
|
+
|
|
199
|
+
export default component$(({ name }) => {
|
|
200
|
+
return (
|
|
201
|
+
<div>
|
|
202
|
+
<h1>Hello {name}!</h1>
|
|
203
|
+
</div>
|
|
204
|
+
)
|
|
205
|
+
})
|
|
206
|
+
`,
|
|
207
|
+
ts: `
|
|
208
|
+
import { component$ } from '@builder.io/qwik'
|
|
209
|
+
|
|
210
|
+
export default component$(({ name }: { name: string }) => {
|
|
211
|
+
return (
|
|
212
|
+
<div>
|
|
213
|
+
<h1>Hello {name}!</h1>
|
|
214
|
+
</div>
|
|
215
|
+
)
|
|
216
|
+
})
|
|
217
|
+
`,
|
|
218
|
+
test: `
|
|
219
|
+
import { expect, test } from 'vitest'
|
|
220
|
+
import { render } from 'vitest-browser-qwik'
|
|
221
|
+
import HelloWorld from './HelloWorld.tsx'
|
|
222
|
+
|
|
223
|
+
test('renders name', async () => {
|
|
224
|
+
const { getByText } = render(<HelloWorld name="Vitest" />)
|
|
225
|
+
await expect.element(getByText('Hello Vitest!')).toBeInTheDocument()
|
|
226
|
+
})
|
|
227
|
+
`
|
|
228
|
+
}, vanillaExample = {
|
|
200
229
|
name: "HelloWorld.js",
|
|
201
230
|
js: `
|
|
202
231
|
export default function HelloWorld({ name }) {
|
|
@@ -249,23 +278,20 @@ function getExampleTest(framework) {
|
|
|
249
278
|
case "svelte": return svelteExample;
|
|
250
279
|
case "lit": return litExample;
|
|
251
280
|
case "marko": return markoExample;
|
|
281
|
+
case "qwik": return qwikExample;
|
|
252
282
|
default: return vanillaExample;
|
|
253
283
|
}
|
|
254
284
|
}
|
|
255
285
|
async function generateExampleFiles(framework, lang) {
|
|
256
286
|
const example = getExampleTest(framework);
|
|
257
287
|
let fileName = example.name;
|
|
258
|
-
const folder = resolve(process.cwd(), "vitest-example");
|
|
259
|
-
const fileContent = example[lang];
|
|
288
|
+
const folder = resolve(process.cwd(), "vitest-example"), fileContent = example[lang];
|
|
260
289
|
if (!existsSync(folder)) await mkdir(folder, { recursive: true });
|
|
261
290
|
const isJSX = fileName.endsWith(".jsx");
|
|
262
291
|
if (isJSX && lang === "ts") fileName = fileName.replace(".jsx", ".tsx");
|
|
263
292
|
else if (fileName.endsWith(".js") && lang === "ts") fileName = fileName.replace(".js", ".ts");
|
|
264
|
-
const filePath = resolve(folder, fileName);
|
|
265
|
-
|
|
266
|
-
writeFileSync(filePath, fileContent.trimStart(), "utf-8");
|
|
267
|
-
writeFileSync(testPath, example.test.trimStart(), "utf-8");
|
|
268
|
-
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;
|
|
269
295
|
}
|
|
270
296
|
|
|
271
297
|
// eslint-disable-next-line no-console
|
|
@@ -362,6 +388,11 @@ function getFramework() {
|
|
|
362
388
|
title: "marko",
|
|
363
389
|
value: "marko",
|
|
364
390
|
description: "\"A declarative, HTML-based language that makes building web apps fun\""
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
title: "qwik",
|
|
394
|
+
value: "qwik",
|
|
395
|
+
description: "\"Instantly interactive web apps at scale\""
|
|
365
396
|
}
|
|
366
397
|
];
|
|
367
398
|
}
|
|
@@ -375,6 +406,7 @@ function getFrameworkTestPackage(framework) {
|
|
|
375
406
|
case "preact": return "vitest-browser-preact";
|
|
376
407
|
case "solid": return "@solidjs/testing-library";
|
|
377
408
|
case "marko": return "@marko/testing-library";
|
|
409
|
+
case "qwik": return "vitest-browser-qwik";
|
|
378
410
|
}
|
|
379
411
|
throw new Error(`Unsupported framework: ${framework}`);
|
|
380
412
|
}
|
|
@@ -386,14 +418,14 @@ function getFrameworkPluginPackage(framework) {
|
|
|
386
418
|
case "preact": return "@preact/preset-vite";
|
|
387
419
|
case "solid": return "vite-plugin-solid";
|
|
388
420
|
case "marko": return "@marko/vite";
|
|
421
|
+
case "qwik": return "@builder.io/qwik/optimizer";
|
|
389
422
|
}
|
|
390
423
|
return null;
|
|
391
424
|
}
|
|
392
425
|
async function updateTsConfig(type) {
|
|
393
426
|
if (type == null) return;
|
|
394
427
|
const msg = `Add "${c.bold(type)}" to your tsconfig.json "${c.bold("compilerOptions.types")}" field to have better intellisense support.`;
|
|
395
|
-
log();
|
|
396
|
-
log(c.yellow("◼"), c.yellow(msg));
|
|
428
|
+
log(), log(c.yellow("◼"), c.yellow(msg));
|
|
397
429
|
}
|
|
398
430
|
function getLanguageOptions() {
|
|
399
431
|
return [{
|
|
@@ -411,10 +443,7 @@ async function installPackages(pkgManager, packages) {
|
|
|
411
443
|
log(c.green("✔"), c.bold("All packages are already installed."));
|
|
412
444
|
return;
|
|
413
445
|
}
|
|
414
|
-
log(c.cyan("◼"), c.bold("Installing packages..."))
|
|
415
|
-
log(c.cyan("◼"), packages.join(", "));
|
|
416
|
-
log();
|
|
417
|
-
await installPackage(packages, {
|
|
446
|
+
log(c.cyan("◼"), c.bold("Installing packages...")), log(c.cyan("◼"), packages.join(", ")), log(), await installPackage(packages, {
|
|
418
447
|
dev: true,
|
|
419
448
|
packageManager: pkgManager ?? void 0
|
|
420
449
|
});
|
|
@@ -425,8 +454,7 @@ function readPkgJson(path) {
|
|
|
425
454
|
return JSON.parse(content);
|
|
426
455
|
}
|
|
427
456
|
function getPossibleDefaults(dependencies) {
|
|
428
|
-
const provider = getPossibleProvider(dependencies);
|
|
429
|
-
const framework = getPossibleFramework(dependencies);
|
|
457
|
+
const provider = getPossibleProvider(dependencies), framework = getPossibleFramework(dependencies);
|
|
430
458
|
return {
|
|
431
459
|
lang: "ts",
|
|
432
460
|
provider,
|
|
@@ -434,19 +462,11 @@ function getPossibleDefaults(dependencies) {
|
|
|
434
462
|
};
|
|
435
463
|
}
|
|
436
464
|
function getPossibleFramework(dependencies) {
|
|
437
|
-
|
|
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";
|
|
444
|
-
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";
|
|
445
466
|
}
|
|
446
467
|
function getPossibleProvider(dependencies) {
|
|
447
|
-
if (dependencies.webdriverio || dependencies["@wdio/cli"] || dependencies["@wdio/config"]) return "webdriverio";
|
|
448
468
|
// playwright is the default recommendation
|
|
449
|
-
return "playwright";
|
|
469
|
+
return dependencies.webdriverio || dependencies["@wdio/cli"] || dependencies["@wdio/config"] ? "webdriverio" : "playwright";
|
|
450
470
|
}
|
|
451
471
|
function getProviderDocsLink(provider) {
|
|
452
472
|
switch (provider) {
|
|
@@ -463,18 +483,34 @@ function sort(choices, value) {
|
|
|
463
483
|
function fail() {
|
|
464
484
|
process.exitCode = 1;
|
|
465
485
|
}
|
|
486
|
+
function getFrameworkImportInfo(framework) {
|
|
487
|
+
switch (framework) {
|
|
488
|
+
case "svelte": return {
|
|
489
|
+
importName: "svelte",
|
|
490
|
+
isNamedExport: true
|
|
491
|
+
};
|
|
492
|
+
case "qwik": return {
|
|
493
|
+
importName: "qwikVite",
|
|
494
|
+
isNamedExport: true
|
|
495
|
+
};
|
|
496
|
+
default: return {
|
|
497
|
+
importName: framework,
|
|
498
|
+
isNamedExport: false
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
}
|
|
466
502
|
async function generateFrameworkConfigFile(options) {
|
|
467
|
-
const
|
|
468
|
-
const configContent = [
|
|
503
|
+
const { importName, isNamedExport } = getFrameworkImportInfo(options.framework), frameworkImport = isNamedExport ? `import { ${importName} } from '${options.frameworkPlugin}'` : `import ${importName} from '${options.frameworkPlugin}'`, configContent = [
|
|
469
504
|
`import { defineConfig } from 'vitest/config'`,
|
|
505
|
+
`import { ${options.provider} } from '@vitest/browser/providers/${options.provider}'`,
|
|
470
506
|
options.frameworkPlugin ? frameworkImport : null,
|
|
471
507
|
``,
|
|
472
508
|
"export default defineConfig({",
|
|
473
|
-
options.frameworkPlugin ? ` plugins: [${
|
|
509
|
+
options.frameworkPlugin ? ` plugins: [${importName}()],` : null,
|
|
474
510
|
` test: {`,
|
|
475
511
|
` browser: {`,
|
|
476
512
|
` enabled: true,`,
|
|
477
|
-
` provider:
|
|
513
|
+
` provider: ${options.provider}(),`,
|
|
478
514
|
options.provider !== "preview" && ` // ${getProviderDocsLink(options.provider)}`,
|
|
479
515
|
` instances: [`,
|
|
480
516
|
...options.browsers.map((browser) => ` { browser: '${browser}' },`),
|
|
@@ -492,9 +528,7 @@ async function updatePkgJsonScripts(pkgJsonPath, vitestScript) {
|
|
|
492
528
|
await writeFile(pkgJsonPath, `${JSON.stringify(pkg, null, 2)}\n`, "utf-8");
|
|
493
529
|
} else {
|
|
494
530
|
const pkg = JSON.parse(readFileSync(pkgJsonPath, "utf-8"));
|
|
495
|
-
pkg.scripts = pkg.scripts || {};
|
|
496
|
-
pkg.scripts["test:browser"] = vitestScript;
|
|
497
|
-
await writeFile(pkgJsonPath, `${JSON.stringify(pkg, null, 2)}\n`, "utf-8");
|
|
531
|
+
pkg.scripts = pkg.scripts || {}, pkg.scripts["test:browser"] = vitestScript, await writeFile(pkgJsonPath, `${JSON.stringify(pkg, null, 2)}\n`, "utf-8");
|
|
498
532
|
}
|
|
499
533
|
log(c.green("✔"), "Added \"test:browser\" script to your package.json.");
|
|
500
534
|
}
|
|
@@ -520,14 +554,10 @@ function getPlaywrightRunArgs(pkgManager) {
|
|
|
520
554
|
}
|
|
521
555
|
async function create() {
|
|
522
556
|
log(c.cyan("◼"), "This utility will help you set up a browser testing environment.\n");
|
|
523
|
-
const pkgJsonPath = resolve(process.cwd(), "package.json")
|
|
524
|
-
const pkg = readPkgJson(pkgJsonPath) || {};
|
|
525
|
-
const dependencies = {
|
|
557
|
+
const pkgJsonPath = resolve(process.cwd(), "package.json"), pkg = readPkgJson(pkgJsonPath) || {}, dependencies = {
|
|
526
558
|
...pkg.dependencies,
|
|
527
559
|
...pkg.devDependencies
|
|
528
|
-
}
|
|
529
|
-
const defaults = getPossibleDefaults(dependencies);
|
|
530
|
-
const { lang } = await prompt({
|
|
560
|
+
}, defaults = getPossibleDefaults(dependencies), { lang } = await prompt({
|
|
531
561
|
type: "select",
|
|
532
562
|
name: "lang",
|
|
533
563
|
message: "Choose a language for your tests",
|
|
@@ -565,30 +595,25 @@ async function create() {
|
|
|
565
595
|
message: `Install Playwright browsers (can be done manually via 'pnpm exec playwright install')?`
|
|
566
596
|
}));
|
|
567
597
|
if (installPlaywright == null) return fail();
|
|
568
|
-
const dependenciesToInstall = ["@vitest/browser"];
|
|
569
|
-
const frameworkPackage = getFrameworkTestPackage(framework);
|
|
598
|
+
const dependenciesToInstall = ["@vitest/browser"], frameworkPackage = getFrameworkTestPackage(framework);
|
|
570
599
|
if (frameworkPackage) dependenciesToInstall.push(frameworkPackage);
|
|
571
600
|
const providerPkg = getProviderPackageNames(provider);
|
|
572
601
|
if (providerPkg.pkg) dependenciesToInstall.push(providerPkg.pkg);
|
|
573
602
|
const frameworkPlugin = getFrameworkPluginPackage(framework);
|
|
574
603
|
if (frameworkPlugin) dependenciesToInstall.push(frameworkPlugin);
|
|
575
604
|
const pkgManager = await detectPackageManager();
|
|
576
|
-
log();
|
|
577
|
-
await installPackages(pkgManager, dependenciesToInstall.filter((pkg) => !dependencies[pkg]));
|
|
605
|
+
log(), await installPackages(pkgManager, dependenciesToInstall.filter((pkg) => !dependencies[pkg]));
|
|
578
606
|
const rootConfig = await findUp(configFiles, { cwd: process.cwd() });
|
|
579
607
|
let scriptCommand = "vitest";
|
|
580
|
-
log()
|
|
581
|
-
if (rootConfig) {
|
|
608
|
+
if (log(), rootConfig) {
|
|
582
609
|
const configPath = resolve(dirname(rootConfig), `vitest.browser.config.${lang}`);
|
|
583
|
-
scriptCommand = `vitest --config=${relative(process.cwd(), configPath)}
|
|
584
|
-
await generateFrameworkConfigFile({
|
|
610
|
+
scriptCommand = `vitest --config=${relative(process.cwd(), configPath)}`, await generateFrameworkConfigFile({
|
|
585
611
|
configPath,
|
|
586
612
|
framework,
|
|
587
613
|
frameworkPlugin,
|
|
588
614
|
provider,
|
|
589
615
|
browsers
|
|
590
|
-
})
|
|
591
|
-
log(
|
|
616
|
+
}), log(
|
|
592
617
|
c.green("✔"),
|
|
593
618
|
"Created a new config file for browser tests:",
|
|
594
619
|
c.bold(relative(process.cwd(), configPath)),
|
|
@@ -605,23 +630,17 @@ async function create() {
|
|
|
605
630
|
frameworkPlugin,
|
|
606
631
|
provider,
|
|
607
632
|
browsers
|
|
608
|
-
});
|
|
609
|
-
log(c.green("✔"), "Created a config file for browser tests:", c.bold(relative(process.cwd(), configPath)));
|
|
633
|
+
}), log(c.green("✔"), "Created a config file for browser tests:", c.bold(relative(process.cwd(), configPath)));
|
|
610
634
|
}
|
|
611
|
-
log()
|
|
612
|
-
await updatePkgJsonScripts(pkgJsonPath, scriptCommand);
|
|
613
|
-
if (installPlaywright) {
|
|
635
|
+
if (log(), await updatePkgJsonScripts(pkgJsonPath, scriptCommand), installPlaywright) {
|
|
614
636
|
log();
|
|
615
|
-
const [command, ...args] = getPlaywrightRunArgs(pkgManager)
|
|
616
|
-
const allArgs = [
|
|
637
|
+
const [command, ...args] = getPlaywrightRunArgs(pkgManager), allArgs = [
|
|
617
638
|
...args,
|
|
618
639
|
"playwright",
|
|
619
640
|
"install",
|
|
620
641
|
"--with-deps"
|
|
621
642
|
];
|
|
622
|
-
log(c.cyan("◼"), `Installing Playwright dependencies with \`${c.bold(command)} ${c.bold(allArgs.join(" "))}\`...`)
|
|
623
|
-
log();
|
|
624
|
-
await x(command, allArgs, { nodeOptions: { stdio: [
|
|
643
|
+
log(c.cyan("◼"), `Installing Playwright dependencies with \`${c.bold(command)} ${c.bold(allArgs.join(" "))}\`...`), log(), await x(command, allArgs, { nodeOptions: { stdio: [
|
|
625
644
|
"pipe",
|
|
626
645
|
"inherit",
|
|
627
646
|
"inherit"
|
|
@@ -631,10 +650,7 @@ async function create() {
|
|
|
631
650
|
if (lang === "ts") await updateTsConfig(providerPkg?.types);
|
|
632
651
|
log();
|
|
633
652
|
const exampleTestFile = await generateExampleFiles(framework, lang);
|
|
634
|
-
log(c.green("✔"), "Created example test file in", c.bold(relative(process.cwd(), exampleTestFile)));
|
|
635
|
-
log(c.dim(" You can safely delete this file once you have written your own tests."));
|
|
636
|
-
log();
|
|
637
|
-
log(c.cyan("◼"), "All done! Run your tests with", c.bold(getRunScript(pkgManager)));
|
|
653
|
+
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)));
|
|
638
654
|
}
|
|
639
655
|
|
|
640
656
|
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;
|
|
@@ -3,13 +3,7 @@ import './env.D4Lgay0q.js';
|
|
|
3
3
|
import { isCI } from 'std-env';
|
|
4
4
|
|
|
5
5
|
const defaultInclude = ["**/*.{test,spec}.?(c|m)[jt]s?(x)"];
|
|
6
|
-
const defaultExclude = [
|
|
7
|
-
"**/node_modules/**",
|
|
8
|
-
"**/dist/**",
|
|
9
|
-
"**/cypress/**",
|
|
10
|
-
"**/.{idea,git,cache,output,temp}/**",
|
|
11
|
-
"**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*"
|
|
12
|
-
];
|
|
6
|
+
const defaultExclude = ["**/node_modules/**", "**/.git/**"];
|
|
13
7
|
const benchmarkConfigDefaults = {
|
|
14
8
|
include: ["**/*.{bench,benchmark}.?(c|m)[jt]s?(x)"],
|
|
15
9
|
exclude: defaultExclude,
|
|
@@ -17,34 +11,14 @@ const benchmarkConfigDefaults = {
|
|
|
17
11
|
reporters: ["default"],
|
|
18
12
|
includeSamples: false
|
|
19
13
|
};
|
|
20
|
-
const defaultCoverageExcludes = [
|
|
21
|
-
"coverage/**",
|
|
22
|
-
"dist/**",
|
|
23
|
-
"**/node_modules/**",
|
|
24
|
-
"**/[.]**",
|
|
25
|
-
"packages/*/test?(s)/**",
|
|
26
|
-
"**/*.d.ts",
|
|
27
|
-
"**/virtual:*",
|
|
28
|
-
"**/__x00__*",
|
|
29
|
-
"**/\0*",
|
|
30
|
-
"cypress/**",
|
|
31
|
-
"test?(s)/**",
|
|
32
|
-
"test?(-*).?(c|m)[jt]s?(x)",
|
|
33
|
-
"**/*{.,-}{test,spec,bench,benchmark}?(-d).?(c|m)[jt]s?(x)",
|
|
34
|
-
"**/__tests__/**",
|
|
35
|
-
"**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*",
|
|
36
|
-
"**/vitest.{workspace,projects}.[jt]s?(on)",
|
|
37
|
-
"**/.{eslint,mocha,prettier}rc.{?(c|m)js,yml}"
|
|
38
|
-
];
|
|
39
14
|
// These are the generic defaults for coverage. Providers may also set some provider specific defaults.
|
|
40
15
|
const coverageConfigDefaults = {
|
|
41
16
|
provider: "v8",
|
|
42
17
|
enabled: false,
|
|
43
|
-
all: true,
|
|
44
18
|
clean: true,
|
|
45
19
|
cleanOnRerun: true,
|
|
46
20
|
reportsDirectory: "./coverage",
|
|
47
|
-
exclude:
|
|
21
|
+
exclude: [],
|
|
48
22
|
reportOnFailure: false,
|
|
49
23
|
reporter: [
|
|
50
24
|
["text", {}],
|
|
@@ -52,22 +26,8 @@ const coverageConfigDefaults = {
|
|
|
52
26
|
["clover", {}],
|
|
53
27
|
["json", {}]
|
|
54
28
|
],
|
|
55
|
-
extension: [
|
|
56
|
-
".js",
|
|
57
|
-
".cjs",
|
|
58
|
-
".mjs",
|
|
59
|
-
".ts",
|
|
60
|
-
".mts",
|
|
61
|
-
".tsx",
|
|
62
|
-
".jsx",
|
|
63
|
-
".vue",
|
|
64
|
-
".svelte",
|
|
65
|
-
".marko",
|
|
66
|
-
".astro"
|
|
67
|
-
],
|
|
68
29
|
allowExternal: false,
|
|
69
30
|
excludeAfterRemap: false,
|
|
70
|
-
ignoreEmptyLines: true,
|
|
71
31
|
processingConcurrency: Math.min(20, nodeos__default.availableParallelism?.() ?? nodeos__default.cpus().length)
|
|
72
32
|
};
|
|
73
33
|
const fakeTimersDefaults = {
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
type Awaitable<T> = T | PromiseLike<T>;
|
|
2
|
+
type Arrayable<T> = T | Array<T>;
|
|
3
|
+
interface AfterSuiteRunMeta {
|
|
4
|
+
coverage?: unknown;
|
|
5
|
+
testFiles: string[];
|
|
6
|
+
environment: string;
|
|
7
|
+
projectName?: string;
|
|
8
|
+
}
|
|
9
|
+
interface UserConsoleLog {
|
|
10
|
+
content: string;
|
|
11
|
+
origin?: string;
|
|
12
|
+
browser?: boolean;
|
|
13
|
+
type: "stdout" | "stderr";
|
|
14
|
+
taskId?: string;
|
|
15
|
+
time: number;
|
|
16
|
+
size: number;
|
|
17
|
+
}
|
|
18
|
+
interface ModuleGraphData {
|
|
19
|
+
graph: Record<string, string[]>;
|
|
20
|
+
externalized: string[];
|
|
21
|
+
inlined: string[];
|
|
22
|
+
}
|
|
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
|
+
}
|
|
37
|
+
type LabelColor = "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white";
|
|
38
|
+
|
|
39
|
+
interface EnvironmentReturn {
|
|
40
|
+
teardown: (global: any) => Awaitable<void>;
|
|
41
|
+
}
|
|
42
|
+
interface VmEnvironmentReturn {
|
|
43
|
+
getVmContext: () => {
|
|
44
|
+
[key: string]: any;
|
|
45
|
+
};
|
|
46
|
+
teardown: () => Awaitable<void>;
|
|
47
|
+
}
|
|
48
|
+
interface Environment {
|
|
49
|
+
name: string;
|
|
50
|
+
/**
|
|
51
|
+
* @deprecated use `viteEnvironment` instead. Uses `name` by default
|
|
52
|
+
*/
|
|
53
|
+
transformMode?: "web" | "ssr";
|
|
54
|
+
/**
|
|
55
|
+
* Environment initiated by the Vite server. It is usually available
|
|
56
|
+
* as `vite.server.environments.${name}`.
|
|
57
|
+
*
|
|
58
|
+
* By default, fallbacks to `name`.
|
|
59
|
+
*/
|
|
60
|
+
viteEnvironment?: "client" | "ssr" | ({} & string);
|
|
61
|
+
setupVM?: (options: Record<string, any>) => Awaitable<VmEnvironmentReturn>;
|
|
62
|
+
setup: (global: any, options: Record<string, any>) => Awaitable<EnvironmentReturn>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
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
|
}
|
|
@@ -1,41 +1,19 @@
|
|
|
1
1
|
import { PromisifyAssertion, Tester, ExpectStatic } from '@vitest/expect';
|
|
2
2
|
import { Plugin } from '@vitest/pretty-format';
|
|
3
3
|
import { SnapshotState } from '@vitest/snapshot';
|
|
4
|
-
import { B as BenchmarkResult } from './benchmark.d.
|
|
5
|
-
import { U as UserConsoleLog } from './environment.d.
|
|
6
|
-
|
|
7
|
-
type RawErrsMap = Map<string, TscErrorInfo[]>;
|
|
8
|
-
interface TscErrorInfo {
|
|
9
|
-
filePath: string;
|
|
10
|
-
errCode: number;
|
|
11
|
-
errMsg: string;
|
|
12
|
-
line: number;
|
|
13
|
-
column: number;
|
|
14
|
-
}
|
|
15
|
-
interface CollectLineNumbers {
|
|
16
|
-
target: number;
|
|
17
|
-
next: number;
|
|
18
|
-
prev?: number;
|
|
19
|
-
}
|
|
20
|
-
type CollectLines = { [key in keyof CollectLineNumbers] : string };
|
|
21
|
-
interface RootAndTarget {
|
|
22
|
-
root: string;
|
|
23
|
-
targetAbsPath: string;
|
|
24
|
-
}
|
|
25
|
-
type Context = RootAndTarget & {
|
|
26
|
-
rawErrsMap: RawErrsMap
|
|
27
|
-
openedDirs: Set<string>
|
|
28
|
-
lastActivePath?: string
|
|
29
|
-
};
|
|
4
|
+
import { B as BenchmarkResult } from './benchmark.d.DAaHLpsq.js';
|
|
5
|
+
import { U as UserConsoleLog } from './environment.d.BsToaxti.js';
|
|
30
6
|
|
|
31
7
|
declare global {
|
|
32
|
-
// eslint-disable-next-line ts/no-namespace
|
|
33
8
|
namespace Chai {
|
|
9
|
+
interface ContainSubset {
|
|
10
|
+
(expected: any): Assertion;
|
|
11
|
+
}
|
|
34
12
|
interface Assertion {
|
|
35
|
-
containSubset:
|
|
13
|
+
containSubset: ContainSubset;
|
|
36
14
|
}
|
|
37
15
|
interface Assert {
|
|
38
|
-
containSubset
|
|
16
|
+
containSubset(val: any, exp: any, msg?: string): void;
|
|
39
17
|
}
|
|
40
18
|
}
|
|
41
19
|
}
|
|
@@ -67,7 +45,6 @@ declare module "@vitest/expect" {
|
|
|
67
45
|
addSnapshotSerializer: (plugin: Plugin) => void;
|
|
68
46
|
}
|
|
69
47
|
interface Assertion<T> {
|
|
70
|
-
// Snapshots are extended in @vitest/snapshot and are not part of @vitest/expect
|
|
71
48
|
matchSnapshot: SnapshotMatcher<T>;
|
|
72
49
|
toMatchSnapshot: SnapshotMatcher<T>;
|
|
73
50
|
toMatchInlineSnapshot: InlineSnapshotMatcher<T>;
|
|
@@ -132,5 +109,3 @@ declare module "@vitest/runner" {
|
|
|
132
109
|
benchmark?: BenchmarkResult;
|
|
133
110
|
}
|
|
134
111
|
}
|
|
135
|
-
|
|
136
|
-
export type { CollectLineNumbers as C, RawErrsMap as R, TscErrorInfo as T, CollectLines as a, RootAndTarget as b, Context as c };
|