vitest 3.2.0-beta.2 → 3.2.0

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 (72) hide show
  1. package/LICENSE.md +29 -0
  2. package/dist/browser.d.ts +3 -3
  3. package/dist/browser.js +2 -2
  4. package/dist/chunks/{base.DwtwORaC.js → base.Cg0miDlQ.js} +11 -14
  5. package/dist/chunks/{benchmark.BoF7jW0Q.js → benchmark.CYdenmiT.js} +4 -6
  6. package/dist/chunks/{cac.I9MLYfT-.js → cac.6rXCxFY1.js} +76 -143
  7. package/dist/chunks/{cli-api.d6IK1pnk.js → cli-api.Cej3MBjA.js} +1460 -1344
  8. package/dist/chunks/{config.d.UqE-KR0o.d.ts → config.d.D2ROskhv.d.ts} +2 -0
  9. package/dist/chunks/{console.K1NMVOSc.js → console.CtFJOzRO.js} +25 -45
  10. package/dist/chunks/{constants.BZZyIeIE.js → constants.DnKduX2e.js} +1 -0
  11. package/dist/chunks/{coverage.0iPg4Wrz.js → coverage.DVF1vEu8.js} +4 -12
  12. package/dist/chunks/{coverage.OGU09Jbh.js → coverage.EIiagJJP.js} +578 -993
  13. package/dist/chunks/{creator.DGAdZ4Hj.js → creator.GK6I-cL4.js} +39 -83
  14. package/dist/chunks/date.Bq6ZW5rf.js +73 -0
  15. package/dist/chunks/{defaults.DSxsTG0h.js → defaults.B7q_naMc.js} +2 -1
  16. package/dist/chunks/{env.Dq0hM4Xv.js → env.D4Lgay0q.js} +1 -1
  17. package/dist/chunks/{environment.d.D8YDy2v5.d.ts → environment.d.cL3nLXbE.d.ts} +1 -0
  18. package/dist/chunks/{execute.JlGHLJZT.js → execute.B7h3T_Hc.js} +126 -217
  19. package/dist/chunks/{git.DXfdBEfR.js → git.BVQ8w_Sw.js} +1 -3
  20. package/dist/chunks/{global.d.BPa1eL3O.d.ts → global.d.MAmajcmJ.d.ts} +5 -1
  21. package/dist/chunks/{globals.CpxW8ccg.js → globals.DEHgCU4V.js} +7 -6
  22. package/dist/chunks/{index.CV36oG_L.js → index.BZ0g1JD2.js} +430 -625
  23. package/dist/chunks/{index.DswW_LEs.js → index.BbB8_kAK.js} +25 -24
  24. package/dist/chunks/{index.CmC5OK9L.js → index.CIyJn3t1.js} +38 -82
  25. package/dist/chunks/{index.CfXMNXHg.js → index.CdQS2e2Q.js} +4 -2
  26. package/dist/chunks/{index.DFXFpH3w.js → index.CmSc2RE5.js} +85 -105
  27. package/dist/chunks/index.D3XRDfWc.js +213 -0
  28. package/dist/chunks/{inspector.DbDkSkFn.js → inspector.C914Efll.js} +4 -1
  29. package/dist/chunks/{node.3xsWotC9.js → node.fjCdwEIl.js} +1 -1
  30. package/dist/chunks/{reporters.d.CLC9rhKy.d.ts → reporters.d.C1ogPriE.d.ts} +47 -9
  31. package/dist/chunks/{rpc.D9_013TY.js → rpc.Iovn4oWe.js} +10 -19
  32. package/dist/chunks/{runBaseTests.Dn2vyej_.js → runBaseTests.Dd85QTll.js} +27 -31
  33. package/dist/chunks/{setup-common.CYo3Y0dD.js → setup-common.Dd054P77.js} +16 -42
  34. package/dist/chunks/{typechecker.DnTrplSJ.js → typechecker.DRKU1-1g.js} +163 -186
  35. package/dist/chunks/{utils.BfxieIyZ.js → utils.CAioKnHs.js} +9 -14
  36. package/dist/chunks/{utils.CgTj3MsC.js → utils.XdZDrNZV.js} +6 -13
  37. package/dist/chunks/{vi.BFR5YIgu.js → vi.bdSIJ99Y.js} +137 -263
  38. package/dist/chunks/{vite.d.CBZ3M_ru.d.ts → vite.d.DqE4-hhK.d.ts} +3 -1
  39. package/dist/chunks/{vm.C1HHjtNS.js → vm.BThCzidc.js} +164 -212
  40. package/dist/chunks/{worker.d.D5Xdi-Zr.d.ts → worker.d.DvqK5Vmu.d.ts} +1 -1
  41. package/dist/chunks/{worker.d.CoCI7hzP.d.ts → worker.d.tQu2eJQy.d.ts} +5 -3
  42. package/dist/cli.js +5 -5
  43. package/dist/config.cjs +3 -1
  44. package/dist/config.d.ts +7 -6
  45. package/dist/config.js +3 -3
  46. package/dist/coverage.d.ts +4 -4
  47. package/dist/coverage.js +7 -7
  48. package/dist/environments.d.ts +6 -2
  49. package/dist/environments.js +1 -1
  50. package/dist/execute.d.ts +9 -3
  51. package/dist/execute.js +1 -1
  52. package/dist/index.d.ts +28 -15
  53. package/dist/index.js +5 -5
  54. package/dist/node.d.ts +18 -10
  55. package/dist/node.js +17 -17
  56. package/dist/reporters.d.ts +4 -4
  57. package/dist/reporters.js +4 -4
  58. package/dist/runners.d.ts +6 -3
  59. package/dist/runners.js +59 -80
  60. package/dist/snapshot.js +2 -2
  61. package/dist/suite.js +2 -2
  62. package/dist/worker.js +39 -41
  63. package/dist/workers/forks.js +6 -4
  64. package/dist/workers/runVmTests.js +20 -21
  65. package/dist/workers/threads.js +4 -4
  66. package/dist/workers/vmForks.js +6 -6
  67. package/dist/workers/vmThreads.js +6 -6
  68. package/dist/workers.d.ts +4 -4
  69. package/dist/workers.js +10 -10
  70. package/package.json +21 -19
  71. package/dist/chunks/date.CDOsz-HY.js +0 -53
  72. package/dist/chunks/index.CK1YOQaa.js +0 -143
@@ -1,11 +1,11 @@
1
1
  import { existsSync, writeFileSync, readFileSync } from 'node:fs';
2
2
  import { mkdir, writeFile } from 'node:fs/promises';
3
3
  import { resolve, dirname, relative } from 'node:path';
4
- import { detectPackageManager, installPackage } from './index.CK1YOQaa.js';
4
+ 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.BZZyIeIE.js';
8
+ import { c as configFiles } from './constants.DnKduX2e.js';
9
9
  import 'node:process';
10
10
  import 'node:url';
11
11
  import './_commonjsHelpers.BFTU3MAI.js';
@@ -236,14 +236,14 @@ test('renders name', () => {
236
236
  };
237
237
  function getExampleTest(framework) {
238
238
  switch (framework) {
239
- case "solid":
240
- case "preact": return {
239
+ case "solid": return {
241
240
  ...jsxExample,
242
241
  test: jsxExample.test.replace("@testing-library/jsx", `@testing-library/${framework}`)
243
242
  };
243
+ case "preact":
244
244
  case "react": return {
245
245
  ...jsxExample,
246
- test: jsxExample.test.replace("@testing-library/jsx", "vitest-browser-react")
246
+ test: jsxExample.test.replace("@testing-library/jsx", `vitest-browser-${framework}`)
247
247
  };
248
248
  case "vue": return vueExample;
249
249
  case "svelte": return svelteExample;
@@ -257,15 +257,10 @@ async function generateExampleFiles(framework, lang) {
257
257
  let fileName = example.name;
258
258
  const folder = resolve(process.cwd(), "vitest-example");
259
259
  const fileContent = example[lang];
260
- if (!existsSync(folder)) {
261
- await mkdir(folder, { recursive: true });
262
- }
260
+ if (!existsSync(folder)) await mkdir(folder, { recursive: true });
263
261
  const isJSX = fileName.endsWith(".jsx");
264
- if (isJSX && lang === "ts") {
265
- fileName = fileName.replace(".jsx", ".tsx");
266
- } else if (fileName.endsWith(".js") && lang === "ts") {
267
- fileName = fileName.replace(".js", ".ts");
268
- }
262
+ if (isJSX && lang === "ts") fileName = fileName.replace(".jsx", ".tsx");
263
+ else if (fileName.endsWith(".js") && lang === "ts") fileName = fileName.replace(".js", ".ts");
269
264
  const filePath = resolve(folder, fileName);
270
265
  const testPath = resolve(folder, `HelloWorld.test.${isJSX ? `${lang}x` : lang}`);
271
266
  writeFileSync(filePath, fileContent.trimStart(), "utf-8");
@@ -273,6 +268,7 @@ async function generateExampleFiles(framework, lang) {
273
268
  return testPath;
274
269
  }
275
270
 
271
+ // eslint-disable-next-line no-console
276
272
  const log = console.log;
277
273
  function getProviderOptions() {
278
274
  const providers = {
@@ -376,7 +372,7 @@ function getFrameworkTestPackage(framework) {
376
372
  case "svelte": return "vitest-browser-svelte";
377
373
  case "react": return "vitest-browser-react";
378
374
  case "lit": return "vitest-browser-lit";
379
- case "preact": return "@testing-library/preact";
375
+ case "preact": return "vitest-browser-preact";
380
376
  case "solid": return "@solidjs/testing-library";
381
377
  case "marko": return "@marko/testing-library";
382
378
  }
@@ -394,9 +390,7 @@ function getFrameworkPluginPackage(framework) {
394
390
  return null;
395
391
  }
396
392
  async function updateTsConfig(type) {
397
- if (type == null) {
398
- return;
399
- }
393
+ if (type == null) return;
400
394
  const msg = `Add "${c.bold(type)}" to your tsconfig.json "${c.bold("compilerOptions.types")}" field to have better intellisense support.`;
401
395
  log();
402
396
  log(c.yellow("◼"), c.yellow(msg));
@@ -422,13 +416,11 @@ async function installPackages(pkgManager, packages) {
422
416
  log();
423
417
  await installPackage(packages, {
424
418
  dev: true,
425
- packageManager: pkgManager ?? undefined
419
+ packageManager: pkgManager ?? void 0
426
420
  });
427
421
  }
428
422
  function readPkgJson(path) {
429
- if (!existsSync(path)) {
430
- return null;
431
- }
423
+ if (!existsSync(path)) return null;
432
424
  const content = readFileSync(path, "utf-8");
433
425
  return JSON.parse(content);
434
426
  }
@@ -442,33 +434,18 @@ function getPossibleDefaults(dependencies) {
442
434
  };
443
435
  }
444
436
  function getPossibleFramework(dependencies) {
445
- if (dependencies.vue || dependencies["vue-tsc"] || dependencies["@vue/reactivity"]) {
446
- return "vue";
447
- }
448
- if (dependencies.react || dependencies["react-dom"]) {
449
- return "react";
450
- }
451
- if (dependencies.svelte || dependencies["@sveltejs/kit"]) {
452
- return "svelte";
453
- }
454
- if (dependencies.lit || dependencies["lit-html"]) {
455
- return "lit";
456
- }
457
- if (dependencies.preact) {
458
- return "preact";
459
- }
460
- if (dependencies["solid-js"] || dependencies["@solidjs/start"]) {
461
- return "solid";
462
- }
463
- if (dependencies.marko) {
464
- return "marko";
465
- }
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";
466
444
  return "vanilla";
467
445
  }
468
446
  function getPossibleProvider(dependencies) {
469
- if (dependencies.webdriverio || dependencies["@wdio/cli"] || dependencies["@wdio/config"]) {
470
- return "webdriverio";
471
- }
447
+ if (dependencies.webdriverio || dependencies["@wdio/cli"] || dependencies["@wdio/config"]) return "webdriverio";
448
+ // playwright is the default recommendation
472
449
  return "playwright";
473
450
  }
474
451
  function getProviderDocsLink(provider) {
@@ -479,9 +456,7 @@ function getProviderDocsLink(provider) {
479
456
  }
480
457
  function sort(choices, value) {
481
458
  const index = choices.findIndex((i) => i.value === value);
482
- if (index === -1) {
483
- return choices;
484
- }
459
+ if (index === -1) return choices;
485
460
  const item = choices.splice(index, 1)[0];
486
461
  return [item, ...choices];
487
462
  }
@@ -558,18 +533,14 @@ async function create() {
558
533
  message: "Choose a language for your tests",
559
534
  choices: sort(getLanguageOptions(), defaults?.lang)
560
535
  });
561
- if (!lang) {
562
- return fail();
563
- }
536
+ if (!lang) return fail();
564
537
  const { provider } = await prompt({
565
538
  type: "select",
566
539
  name: "provider",
567
540
  message: "Choose a browser provider. Vitest will use its API to control the testing environment",
568
541
  choices: sort(getProviderOptions(), defaults?.provider)
569
542
  });
570
- if (!provider) {
571
- return fail();
572
- }
543
+ if (!provider) return fail();
573
544
  const { browsers } = await prompt({
574
545
  type: "multiselect",
575
546
  name: "browsers",
@@ -579,42 +550,28 @@ async function create() {
579
550
  value: browser
580
551
  }))
581
552
  });
582
- if (!provider) {
583
- return fail();
584
- }
553
+ if (!provider) return fail();
585
554
  const { framework } = await prompt({
586
555
  type: "select",
587
556
  name: "framework",
588
557
  message: "Choose your framework",
589
558
  choices: sort(getFramework(), defaults?.framework)
590
559
  });
591
- if (!framework) {
592
- return fail();
593
- }
560
+ if (!framework) return fail();
594
561
  let installPlaywright = false;
595
- if (provider === "playwright") {
596
- ({installPlaywright} = await prompt({
597
- type: "confirm",
598
- name: "installPlaywright",
599
- message: `Install Playwright browsers (can be done manually via 'pnpm exec playwright install')?`
600
- }));
601
- }
602
- if (installPlaywright == null) {
603
- return fail();
604
- }
562
+ if (provider === "playwright") ({installPlaywright} = await prompt({
563
+ type: "confirm",
564
+ name: "installPlaywright",
565
+ message: `Install Playwright browsers (can be done manually via 'pnpm exec playwright install')?`
566
+ }));
567
+ if (installPlaywright == null) return fail();
605
568
  const dependenciesToInstall = ["@vitest/browser"];
606
569
  const frameworkPackage = getFrameworkTestPackage(framework);
607
- if (frameworkPackage) {
608
- dependenciesToInstall.push(frameworkPackage);
609
- }
570
+ if (frameworkPackage) dependenciesToInstall.push(frameworkPackage);
610
571
  const providerPkg = getProviderPackageNames(provider);
611
- if (providerPkg.pkg) {
612
- dependenciesToInstall.push(providerPkg.pkg);
613
- }
572
+ if (providerPkg.pkg) dependenciesToInstall.push(providerPkg.pkg);
614
573
  const frameworkPlugin = getFrameworkPluginPackage(framework);
615
- if (frameworkPlugin) {
616
- dependenciesToInstall.push(frameworkPlugin);
617
- }
574
+ if (frameworkPlugin) dependenciesToInstall.push(frameworkPlugin);
618
575
  const pkgManager = await detectPackageManager();
619
576
  log();
620
577
  await installPackages(pkgManager, dependenciesToInstall.filter((pkg) => !dependencies[pkg]));
@@ -639,7 +596,7 @@ async function create() {
639
596
  "\nSince you already have a Vitest config file, it is recommended to copy the contents of the new file ",
640
597
  "into your existing config located at ",
641
598
  c.bold(relative(process.cwd(), rootConfig))
642
- );
599
+ );
643
600
  } else {
644
601
  const configPath = resolve(process.cwd(), `vitest.config.${lang}`);
645
602
  await generateFrameworkConfigFile({
@@ -670,9 +627,8 @@ async function create() {
670
627
  "inherit"
671
628
  ] } });
672
629
  }
673
- if (lang === "ts") {
674
- await updateTsConfig(providerPkg?.types);
675
- }
630
+ // TODO: can we do this ourselves?
631
+ if (lang === "ts") await updateTsConfig(providerPkg?.types);
676
632
  log();
677
633
  const exampleTestFile = await generateExampleFiles(framework, lang);
678
634
  log(c.green("✔"), "Created example test file in", c.bold(relative(process.cwd(), exampleTestFile)));
@@ -0,0 +1,73 @@
1
+ /* Ported from https://github.com/boblauer/MockDate/blob/master/src/mockdate.ts */
2
+ /*
3
+ The MIT License (MIT)
4
+
5
+ Copyright (c) 2014 Bob Lauer
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
24
+ */
25
+ const RealDate = Date;
26
+ let now = null;
27
+ class MockDate extends RealDate {
28
+ constructor(y, m, d, h, M, s, ms) {
29
+ super();
30
+ let date;
31
+ switch (arguments.length) {
32
+ case 0:
33
+ if (now !== null) date = new RealDate(now.valueOf());
34
+ else date = new RealDate();
35
+ break;
36
+ case 1:
37
+ date = new RealDate(y);
38
+ break;
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);
46
+ break;
47
+ }
48
+ Object.setPrototypeOf(date, MockDate.prototype);
49
+ return date;
50
+ }
51
+ }
52
+ MockDate.UTC = RealDate.UTC;
53
+ MockDate.now = function() {
54
+ return new MockDate().valueOf();
55
+ };
56
+ MockDate.parse = function(dateString) {
57
+ return RealDate.parse(dateString);
58
+ };
59
+ MockDate.toString = function() {
60
+ return RealDate.toString();
61
+ };
62
+ function mockDate(date) {
63
+ const dateObj = new RealDate(date.valueOf());
64
+ 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();
68
+ }
69
+ function resetDate() {
70
+ globalThis.Date = RealDate;
71
+ }
72
+
73
+ export { RealDate as R, mockDate as m, resetDate as r };
@@ -1,5 +1,5 @@
1
1
  import nodeos__default from 'node:os';
2
- import './env.Dq0hM4Xv.js';
2
+ import './env.D4Lgay0q.js';
3
3
  import { isCI } from 'std-env';
4
4
 
5
5
  const defaultInclude = ["**/*.{test,spec}.?(c|m)[jt]s?(x)"];
@@ -36,6 +36,7 @@ const defaultCoverageExcludes = [
36
36
  "**/vitest.{workspace,projects}.[jt]s?(on)",
37
37
  "**/.{eslint,mocha,prettier}rc.{?(c|m)js,yml}"
38
38
  ];
39
+ // These are the generic defaults for coverage. Providers may also set some provider specific defaults.
39
40
  const coverageConfigDefaults = {
40
41
  provider: "v8",
41
42
  enabled: false,
@@ -1,7 +1,7 @@
1
1
  import { isCI } from 'std-env';
2
2
 
3
3
  const isNode = typeof process < "u" && typeof process.stdout < "u" && !process.versions?.deno && !globalThis.window;
4
- const isDeno = typeof process < "u" && typeof process.stdout < "u" && process.versions?.deno !== undefined;
4
+ const isDeno = typeof process < "u" && typeof process.stdout < "u" && process.versions?.deno !== void 0;
5
5
  const isWindows = (isNode || isDeno) && process.platform === "win32";
6
6
  const isTTY = (isNode || isDeno) && process.stdout?.isTTY && !isCI;
7
7
 
@@ -36,6 +36,7 @@ interface ModuleGraphData {
36
36
  inlined: string[];
37
37
  }
38
38
  interface ProvidedContext {}
39
+ // These need to be compatible with Tinyrainbow's bg-colors, and CSS's background-color
39
40
  type LabelColor = "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white";
40
41
 
41
42
  type HappyDOMOptions = Omit<NonNullable<ConstructorParameters<typeof happyDomTypes.Window>[0]>, "console">;