vitest 4.0.0-beta.1 → 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.
Files changed (85) hide show
  1. package/LICENSE.md +2 -2
  2. package/dist/browser.d.ts +13 -14
  3. package/dist/browser.js +6 -5
  4. package/dist/chunks/base.Cjha6usc.js +129 -0
  5. package/dist/chunks/{benchmark.CYdenmiT.js → benchmark.CJUa-Hsa.js} +6 -8
  6. package/dist/chunks/{benchmark.d.BwvBVTda.d.ts → benchmark.d.DAaHLpsq.d.ts} +4 -4
  7. package/dist/chunks/{browser.d.q8Z0P0q1.d.ts → browser.d.yFAklsD1.d.ts} +5 -5
  8. package/dist/chunks/{cac.D3EzDDZd.js → cac.DCxo_nSu.js} +70 -152
  9. package/dist/chunks/{cli-api.Dn5gKePv.js → cli-api.BJJXh9BV.js} +1330 -1677
  10. package/dist/chunks/{config.d.HJdfX-8k.d.ts → config.d.B_LthbQq.d.ts} +58 -63
  11. package/dist/chunks/{console.CtFJOzRO.js → console.7h5kHUIf.js} +34 -70
  12. package/dist/chunks/{constants.DnKduX2e.js → constants.D_Q9UYh-.js} +1 -9
  13. package/dist/chunks/{coverage.Cwa-XhJt.js → coverage.BCU-r2QL.js} +515 -781
  14. package/dist/chunks/{coverage.DVF1vEu8.js → coverage.D_JHT54q.js} +2 -2
  15. package/dist/chunks/{coverage.d.S9RMNXIe.d.ts → coverage.d.BZtK59WP.d.ts} +10 -8
  16. package/dist/chunks/{creator.GK6I-cL4.js → creator.08Gi-vCA.js} +93 -77
  17. package/dist/chunks/{date.Bq6ZW5rf.js → date.-jtEtIeV.js} +6 -17
  18. package/dist/chunks/{environment.d.CUq4cUgQ.d.ts → environment.d.BsToaxti.d.ts} +27 -6
  19. package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
  20. package/dist/chunks/{global.d.CVbXEflG.d.ts → global.d.BK3X7FW1.d.ts} +2 -5
  21. package/dist/chunks/{globals.Cxal6MLI.js → globals.DG-S3xFe.js} +8 -8
  22. package/dist/chunks/{index.CZI_8rVt.js → index.BIP7prJq.js} +289 -608
  23. package/dist/chunks/{index.B521nVV-.js → index.Bgo3tNWt.js} +23 -4
  24. package/dist/chunks/{index.TfbsX-3I.js → index.BjKEiSn0.js} +14 -24
  25. package/dist/chunks/{index.BWf_gE5n.js → index.CMfqw92x.js} +7 -6
  26. package/dist/chunks/{index.CmSc2RE5.js → index.DIWhzsUh.js} +72 -118
  27. package/dist/chunks/{inspector.C914Efll.js → inspector.CvQD-Nie.js} +10 -25
  28. package/dist/chunks/moduleRunner.d.D9nBoC4p.d.ts +201 -0
  29. package/dist/chunks/moduleTransport.I-bgQy0S.js +19 -0
  30. package/dist/chunks/{node.fjCdwEIl.js → node.CyipiPvJ.js} +1 -1
  31. package/dist/chunks/{plugin.d.C2EcJUjo.d.ts → plugin.d.BMVSnsGV.d.ts} +1 -1
  32. package/dist/chunks/{reporters.d.DxZg19fy.d.ts → reporters.d.BUWjmRYq.d.ts} +1226 -1291
  33. package/dist/chunks/resolveSnapshotEnvironment.Bkht6Yor.js +81 -0
  34. package/dist/chunks/resolver.Bx6lE0iq.js +119 -0
  35. package/dist/chunks/rpc.BKr6mtxz.js +65 -0
  36. package/dist/chunks/{setup-common.D7ZqXFx-.js → setup-common.uiMcU3cv.js} +17 -29
  37. package/dist/chunks/startModuleRunner.p67gbNo9.js +665 -0
  38. package/dist/chunks/{suite.d.FvehnV49.d.ts → suite.d.BJWk38HB.d.ts} +1 -1
  39. package/dist/chunks/test.BiqSKISg.js +214 -0
  40. package/dist/chunks/{typechecker.CVytUJuF.js → typechecker.DB-fIMaH.js} +144 -213
  41. package/dist/chunks/{utils.CAioKnHs.js → utils.C2YI6McM.js} +5 -14
  42. package/dist/chunks/{utils.XdZDrNZV.js → utils.D2R2NiOH.js} +8 -27
  43. package/dist/chunks/{vi.bdSIJ99Y.js → vi.ZPgvtBao.js} +156 -305
  44. package/dist/chunks/{vm.BThCzidc.js → vm.Ca0Y0W5f.js} +116 -226
  45. package/dist/chunks/{worker.d.DoNjFAiv.d.ts → worker.d.BDsXGkwh.d.ts} +28 -22
  46. package/dist/chunks/{worker.d.CmvJfRGs.d.ts → worker.d.BNcX_2mH.d.ts} +1 -1
  47. package/dist/cli.js +4 -4
  48. package/dist/config.cjs +3 -9
  49. package/dist/config.d.ts +49 -54
  50. package/dist/config.js +1 -1
  51. package/dist/coverage.d.ts +27 -26
  52. package/dist/coverage.js +6 -7
  53. package/dist/environments.d.ts +9 -13
  54. package/dist/environments.js +1 -1
  55. package/dist/index.d.ts +38 -45
  56. package/dist/index.js +7 -9
  57. package/dist/module-evaluator.d.ts +13 -0
  58. package/dist/module-evaluator.js +276 -0
  59. package/dist/module-runner.js +15 -0
  60. package/dist/node.d.ts +40 -41
  61. package/dist/node.js +23 -33
  62. package/dist/reporters.d.ts +12 -13
  63. package/dist/reporters.js +3 -3
  64. package/dist/runners.d.ts +3 -3
  65. package/dist/runners.js +13 -232
  66. package/dist/snapshot.js +2 -2
  67. package/dist/suite.d.ts +2 -2
  68. package/dist/suite.js +2 -2
  69. package/dist/worker.js +90 -47
  70. package/dist/workers/forks.js +34 -10
  71. package/dist/workers/runVmTests.js +36 -56
  72. package/dist/workers/threads.js +34 -10
  73. package/dist/workers/vmForks.js +11 -10
  74. package/dist/workers/vmThreads.js +11 -10
  75. package/dist/workers.d.ts +5 -4
  76. package/dist/workers.js +35 -17
  77. package/globals.d.ts +17 -17
  78. package/package.json +32 -31
  79. package/dist/chunks/base.Bj3pWTr1.js +0 -38
  80. package/dist/chunks/execute.B7h3T_Hc.js +0 -708
  81. package/dist/chunks/index.D-VkfKhf.js +0 -105
  82. package/dist/chunks/rpc.CsFtxqeq.js +0 -83
  83. package/dist/chunks/runBaseTests.BC7ZIH5L.js +0 -129
  84. package/dist/execute.d.ts +0 -148
  85. 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.executeId(builtInModule);
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.executeId(options.customProviderModule);
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
- executeId: (id: string) => Promise<{
5
- default: RuntimeCoverageProviderModule
2
+ import: (id: string) => Promise<{
3
+ default: RuntimeCoverageProviderModule;
6
4
  }>;
7
5
  isBrowser?: boolean;
8
- moduleExecutionInfo?: 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?: 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.DnKduX2e.js';
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
- </script>
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
- </script>
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
- </script>
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
- </script>
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
- const vanillaExample = {
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
- const testPath = resolve(folder, `HelloWorld.test.${isJSX ? `${lang}x` : lang}`);
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
- 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";
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 frameworkImport = options.framework === "svelte" ? `import { svelte } from '${options.frameworkPlugin}'` : `import ${options.framework} from '${options.frameworkPlugin}'`;
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: [${options.framework}()],` : null,
509
+ options.frameworkPlugin ? ` plugins: [${importName}()],` : null,
474
510
  ` test: {`,
475
511
  ` browser: {`,
476
512
  ` enabled: true,`,
477
- ` provider: '${options.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
- // @ts-expect-error global
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
- transformMode: TransformMode | "browser";
6
+ environment: string;
8
7
  projectName?: string;
9
8
  }
10
9
  interface UserConsoleLog {
@@ -22,7 +21,19 @@ interface ModuleGraphData {
22
21
  inlined: string[];
23
22
  }
24
23
  interface ProvidedContext {}
25
- // These need to be compatible with Tinyrainbow's bg-colors, and CSS's background-color
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
+ }
26
37
  type LabelColor = "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white";
27
38
 
28
39
  interface EnvironmentReturn {
@@ -30,15 +41,25 @@ interface EnvironmentReturn {
30
41
  }
31
42
  interface VmEnvironmentReturn {
32
43
  getVmContext: () => {
33
- [key: string]: any
44
+ [key: string]: any;
34
45
  };
35
46
  teardown: () => Awaitable<void>;
36
47
  }
37
48
  interface Environment {
38
49
  name: string;
39
- transformMode: "web" | "ssr";
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);
40
61
  setupVM?: (options: Record<string, any>) => Awaitable<VmEnvironmentReturn>;
41
62
  setup: (global: any, options: Record<string, any>) => Awaitable<EnvironmentReturn>;
42
63
  }
43
64
 
44
- export type { AfterSuiteRunMeta as A, Environment as E, LabelColor as L, ModuleGraphData as M, ProvidedContext as P, TransformMode as T, UserConsoleLog as U, VmEnvironmentReturn as V, EnvironmentReturn as a, Awaitable as b, Arrayable as c };
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,11 +1,10 @@
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.BwvBVTda.js';
5
- import { U as UserConsoleLog } from './environment.d.CUq4cUgQ.js';
4
+ import { B as BenchmarkResult } from './benchmark.d.DAaHLpsq.js';
5
+ import { U as UserConsoleLog } from './environment.d.BsToaxti.js';
6
6
 
7
7
  declare global {
8
- // eslint-disable-next-line ts/no-namespace
9
8
  namespace Chai {
10
9
  interface ContainSubset {
11
10
  (expected: any): Assertion;
@@ -14,7 +13,6 @@ declare global {
14
13
  containSubset: ContainSubset;
15
14
  }
16
15
  interface Assert {
17
- // eslint-disable-next-line ts/method-signature-style
18
16
  containSubset(val: any, exp: any, msg?: string): void;
19
17
  }
20
18
  }
@@ -47,7 +45,6 @@ declare module "@vitest/expect" {
47
45
  addSnapshotSerializer: (plugin: Plugin) => void;
48
46
  }
49
47
  interface Assertion<T> {
50
- // Snapshots are extended in @vitest/snapshot and are not part of @vitest/expect
51
48
  matchSnapshot: SnapshotMatcher<T>;
52
49
  toMatchSnapshot: SnapshotMatcher<T>;
53
50
  toMatchInlineSnapshot: InlineSnapshotMatcher<T>;
@@ -1,25 +1,25 @@
1
- import { g as globalApis } from './constants.DnKduX2e.js';
2
- import { V as VitestIndex } from './index.BWf_gE5n.js';
3
- import './vi.bdSIJ99Y.js';
1
+ import { g as globalApis } from './constants.D_Q9UYh-.js';
2
+ import { i as index } from './index.CMfqw92x.js';
3
+ import './vi.ZPgvtBao.js';
4
4
  import '@vitest/expect';
5
5
  import '@vitest/runner';
6
6
  import '@vitest/runner/utils';
7
- import 'chai';
8
- import './utils.XdZDrNZV.js';
7
+ import './utils.D2R2NiOH.js';
9
8
  import '@vitest/utils';
10
9
  import './_commonjsHelpers.BFTU3MAI.js';
11
10
  import '@vitest/snapshot';
12
11
  import '@vitest/utils/error';
13
12
  import '@vitest/spy';
14
13
  import '@vitest/utils/source-map';
15
- import './date.Bq6ZW5rf.js';
16
- import './benchmark.CYdenmiT.js';
14
+ import './date.-jtEtIeV.js';
15
+ import './benchmark.CJUa-Hsa.js';
17
16
  import 'expect-type';
17
+ import 'vite/module-runner';
18
18
 
19
19
  function registerApiGlobally() {
20
20
  globalApis.forEach((api) => {
21
21
  // @ts-expect-error I know what I am doing :P
22
- globalThis[api] = VitestIndex[api];
22
+ globalThis[api] = index[api];
23
23
  });
24
24
  }
25
25