vitest 4.0.0-beta.5 → 4.0.0-beta.7

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 (64) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/browser.d.ts +3 -3
  3. package/dist/browser.js +2 -2
  4. package/dist/chunks/{base.DMfOuRWD.js → base.BXI97p6t.js} +7 -16
  5. package/dist/chunks/{benchmark.CtuRzf-i.js → benchmark.UW6Ezvxy.js} +4 -9
  6. package/dist/chunks/{browser.d.Cawq_X_N.d.ts → browser.d.DOMmqJQx.d.ts} +1 -1
  7. package/dist/chunks/{cac.CKnbxhn2.js → cac.Dsn7ixFt.js} +38 -113
  8. package/dist/chunks/{cli-api.COn58yrl.js → cli-api.DfGJyldU.js} +829 -1232
  9. package/dist/chunks/{config.d.CKNVOKm0.d.ts → config.d._GBBbReY.d.ts} +1 -0
  10. package/dist/chunks/{console.Duv2dVIC.js → console.B0quX7yH.js} +32 -68
  11. package/dist/chunks/{coverage.B6cReEn1.js → coverage.Dvxug1RM.js} +210 -579
  12. package/dist/chunks/{creator.DUVZ6rfm.js → creator.KEg6n5IC.js} +28 -74
  13. package/dist/chunks/{date.Bq6ZW5rf.js → date.-jtEtIeV.js} +6 -17
  14. package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
  15. package/dist/chunks/{globals.CJQ63oO0.js → globals.lgsmH00r.js} +5 -5
  16. package/dist/chunks/{index.QZr3S3vQ.js → index.AR8aAkCC.js} +2 -2
  17. package/dist/chunks/{index.DQhAfQQU.js → index.C3EbxYwt.js} +276 -607
  18. package/dist/chunks/{index.oWRWx-nj.js → index.CsFXYRkW.js} +17 -36
  19. package/dist/chunks/{index.DgN0Zk9a.js → index.D2B6d2vv.js} +14 -24
  20. package/dist/chunks/{index.BRtIe7r8.js → index.DfviD7lX.js} +55 -110
  21. package/dist/chunks/{inspector.C914Efll.js → inspector.CvQD-Nie.js} +10 -25
  22. package/dist/chunks/{moduleRunner.d.mmOmOGrW.d.ts → moduleRunner.d.CX4DuqOx.d.ts} +2 -2
  23. package/dist/chunks/{node.4JV5OXkt.js → node.BOqcT2jW.js} +1 -1
  24. package/dist/chunks/{plugin.d.CvOlgjxK.d.ts → plugin.d.vcD4xbMS.d.ts} +1 -1
  25. package/dist/chunks/{reporters.d.CYE9sT5z.d.ts → reporters.d.BC86JJdB.d.ts} +799 -758
  26. package/dist/chunks/{resolver.D5bG4zy5.js → resolver.Bx6lE0iq.js} +21 -64
  27. package/dist/chunks/{rpc.DGoW_Vl-.js → rpc.RpPylpp0.js} +7 -21
  28. package/dist/chunks/{runBaseTests.B3KcKqlF.js → runBaseTests.D6sfuWBM.js} +25 -54
  29. package/dist/chunks/{setup-common.lgPs-bYv.js → setup-common.hLGRxhC8.js} +9 -22
  30. package/dist/chunks/{startModuleRunner.C8FtT_BY.js → startModuleRunner.C8TW8zTN.js} +83 -205
  31. package/dist/chunks/{typechecker.BgoW4nTA.js → typechecker.DSo_maXz.js} +97 -209
  32. package/dist/chunks/{utils.CcGm2cd1.js → utils.C2YI6McM.js} +4 -13
  33. package/dist/chunks/{utils.B9FY3b73.js → utils.C7__0Iv5.js} +5 -14
  34. package/dist/chunks/{vi.DGAfBY4R.js → vi.BfdOiD4j.js} +110 -267
  35. package/dist/chunks/{vm.BKfKvaKl.js → vm.BHBje7cC.js} +73 -177
  36. package/dist/chunks/{worker.d.Db-UVmXc.d.ts → worker.d.BKu8cnnX.d.ts} +1 -1
  37. package/dist/chunks/{worker.d.D9QWnzAe.d.ts → worker.d.DYlqbejz.d.ts} +1 -1
  38. package/dist/cli.js +3 -3
  39. package/dist/config.d.ts +7 -7
  40. package/dist/coverage.d.ts +4 -4
  41. package/dist/coverage.js +2 -2
  42. package/dist/environments.js +1 -1
  43. package/dist/index.d.ts +6 -6
  44. package/dist/index.js +5 -5
  45. package/dist/module-evaluator.d.ts +3 -3
  46. package/dist/module-evaluator.js +33 -84
  47. package/dist/module-runner.js +2 -2
  48. package/dist/node.d.ts +11 -9
  49. package/dist/node.js +16 -27
  50. package/dist/reporters.d.ts +5 -5
  51. package/dist/reporters.js +3 -3
  52. package/dist/runners.d.ts +1 -1
  53. package/dist/runners.js +23 -51
  54. package/dist/snapshot.js +2 -2
  55. package/dist/suite.js +2 -2
  56. package/dist/worker.js +18 -34
  57. package/dist/workers/forks.js +4 -4
  58. package/dist/workers/runVmTests.js +19 -37
  59. package/dist/workers/threads.js +4 -4
  60. package/dist/workers/vmForks.js +7 -7
  61. package/dist/workers/vmThreads.js +7 -7
  62. package/dist/workers.d.ts +3 -3
  63. package/dist/workers.js +11 -11
  64. package/package.json +11 -11
@@ -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
- const testPath = resolve(folder, `HelloWorld.test.${isJSX ? `${lang}x` : lang}`);
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
- if (dependencies.vue || dependencies["vue-tsc"] || dependencies["@vue/reactivity"]) return "vue";
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
- // @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;
@@ -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,19 +1,19 @@
1
1
  import { g as globalApis } from './constants.D_Q9UYh-.js';
2
- import { V as VitestIndex } from './index.QZr3S3vQ.js';
3
- import './vi.DGAfBY4R.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.B9FY3b73.js';
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.Bq6ZW5rf.js';
16
- import './benchmark.CtuRzf-i.js';
15
+ import './date.-jtEtIeV.js';
16
+ import './benchmark.UW6Ezvxy.js';
17
17
  import 'expect-type';
18
18
  import 'vite/module-runner';
19
19
 
@@ -1,5 +1,5 @@
1
- import { c as createExpect, a as globalExpect, i as inject, v as vi, b as vitest } from './vi.DGAfBY4R.js';
2
- import { b as bench } from './benchmark.CtuRzf-i.js';
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
5
  import { EvaluatedModules } from 'vite/module-runner';