vitest 3.2.0-beta.1 → 3.2.0-beta.2

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 (46) hide show
  1. package/LICENSE.md +0 -232
  2. package/dist/browser.d.ts +2 -0
  3. package/dist/browser.js +3 -4
  4. package/dist/chunks/{base.SfTiRNZf.js → base.DwtwORaC.js} +2 -2
  5. package/dist/chunks/{cac.TfX2-DVH.js → cac.I9MLYfT-.js} +10 -8
  6. package/dist/chunks/{cli-api.2970Nj9J.js → cli-api.d6IK1pnk.js} +48 -16
  7. package/dist/chunks/{coverage.z0LVMxgb.js → coverage.OGU09Jbh.js} +126 -4215
  8. package/dist/chunks/{creator.CuL7xDWI.js → creator.DGAdZ4Hj.js} +18 -39
  9. package/dist/chunks/{execute.BpmIjFTD.js → execute.JlGHLJZT.js} +3 -5
  10. package/dist/chunks/{global.d.BCOHQEpR.d.ts → global.d.BPa1eL3O.d.ts} +10 -10
  11. package/dist/chunks/{globals.Cg4NtV4P.js → globals.CpxW8ccg.js} +1 -2
  12. package/dist/chunks/{index.Bw6JxgX8.js → index.CK1YOQaa.js} +7 -7
  13. package/dist/chunks/{index.CUacZlWG.js → index.CV36oG_L.js} +881 -948
  14. package/dist/chunks/{index.BPc7M5ni.js → index.CfXMNXHg.js} +1 -13
  15. package/dist/chunks/index.CmC5OK9L.js +275 -0
  16. package/dist/chunks/{index.DbWBPwtH.js → index.DswW_LEs.js} +1 -1
  17. package/dist/chunks/{index.DBIGubLC.js → index.X0nbfr6-.js} +7 -7
  18. package/dist/chunks/{reporters.d.DGm4k1Wx.d.ts → reporters.d.CLC9rhKy.d.ts} +17 -0
  19. package/dist/chunks/{runBaseTests.CguliJB5.js → runBaseTests.Dn2vyej_.js} +3 -4
  20. package/dist/chunks/{setup-common.BP6KrF_Z.js → setup-common.CYo3Y0dD.js} +1 -3
  21. package/dist/chunks/typechecker.DnTrplSJ.js +897 -0
  22. package/dist/chunks/{vite.d.DjP_ALCZ.d.ts → vite.d.CBZ3M_ru.d.ts} +1 -1
  23. package/dist/chunks/{vm.CuLHT1BG.js → vm.C1HHjtNS.js} +1 -1
  24. package/dist/cli.js +20 -1
  25. package/dist/config.d.ts +3 -3
  26. package/dist/coverage.d.ts +1 -1
  27. package/dist/coverage.js +4 -7
  28. package/dist/execute.js +1 -1
  29. package/dist/index.d.ts +5 -27
  30. package/dist/index.js +1 -2
  31. package/dist/node.d.ts +4 -4
  32. package/dist/node.js +16 -18
  33. package/dist/reporters.d.ts +1 -1
  34. package/dist/reporters.js +14 -14
  35. package/dist/workers/forks.js +2 -2
  36. package/dist/workers/runVmTests.js +3 -4
  37. package/dist/workers/threads.js +2 -2
  38. package/dist/workers/vmForks.js +2 -2
  39. package/dist/workers/vmThreads.js +2 -2
  40. package/dist/workers.js +3 -3
  41. package/package.json +15 -19
  42. package/dist/chunks/run-once.Dimr7O9f.js +0 -47
  43. package/dist/chunks/typechecker.DYQbn8uK.js +0 -956
  44. package/dist/chunks/utils.8gfOgtry.js +0 -207
  45. package/dist/utils.d.ts +0 -3
  46. package/dist/utils.js +0 -2
@@ -1,8 +1,8 @@
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.Bw6JxgX8.js';
5
- import { p as prompt, f as findUp } from './index.DBIGubLC.js';
4
+ import { detectPackageManager, installPackage } from './index.CK1YOQaa.js';
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
8
  import { c as configFiles } from './constants.BZZyIeIE.js';
@@ -488,32 +488,6 @@ function sort(choices, value) {
488
488
  function fail() {
489
489
  process.exitCode = 1;
490
490
  }
491
- async function generateWorkspaceFile(options) {
492
- const relativeRoot = relative(dirname(options.configPath), options.rootConfig);
493
- const workspaceContent = [
494
- `import { defineWorkspace } from 'vitest/config'`,
495
- "",
496
- "export default defineWorkspace([",
497
- " // If you want to keep running your existing tests in Node.js, uncomment the next line.",
498
- ` // '${relativeRoot}',`,
499
- ` {`,
500
- ` extends: '${relativeRoot}',`,
501
- ` test: {`,
502
- ` browser: {`,
503
- ` enabled: true,`,
504
- ` provider: '${options.provider}',`,
505
- options.provider !== "preview" && ` // ${getProviderDocsLink(options.provider)}`,
506
- ` instances: [`,
507
- ...options.browsers.map((browser) => ` { browser: '${browser}' },`),
508
- ` ],`,
509
- ` },`,
510
- ` },`,
511
- ` },`,
512
- `])`,
513
- ""
514
- ].filter((c) => typeof c === "string").join("\n");
515
- await writeFile(options.configPath, workspaceContent);
516
- }
517
491
  async function generateFrameworkConfigFile(options) {
518
492
  const frameworkImport = options.framework === "svelte" ? `import { svelte } from '${options.frameworkPlugin}'` : `import ${options.framework} from '${options.frameworkPlugin}'`;
519
493
  const configContent = [
@@ -648,19 +622,24 @@ async function create() {
648
622
  let scriptCommand = "vitest";
649
623
  log();
650
624
  if (rootConfig) {
651
- let browserWorkspaceFile = resolve(dirname(rootConfig), `vitest.workspace.${lang}`);
652
- if (existsSync(browserWorkspaceFile)) {
653
- log(c.yellow("⚠"), c.yellow("A workspace file already exists. Creating a new one for the browser tests - you can merge them manually if needed."));
654
- browserWorkspaceFile = resolve(process.cwd(), `vitest.workspace.browser.${lang}`);
655
- }
656
- scriptCommand = `vitest --workspace=${relative(process.cwd(), browserWorkspaceFile)}`;
657
- await generateWorkspaceFile({
658
- configPath: browserWorkspaceFile,
659
- rootConfig,
625
+ const configPath = resolve(dirname(rootConfig), `vitest.browser.config.${lang}`);
626
+ scriptCommand = `vitest --config=${relative(process.cwd(), configPath)}`;
627
+ await generateFrameworkConfigFile({
628
+ configPath,
629
+ framework,
630
+ frameworkPlugin,
660
631
  provider,
661
632
  browsers
662
633
  });
663
- log(c.green("✔"), "Created a workspace file for browser tests:", c.bold(relative(process.cwd(), browserWorkspaceFile)));
634
+ log(
635
+ c.green("✔"),
636
+ "Created a new config file for browser tests:",
637
+ c.bold(relative(process.cwd(), configPath)),
638
+ // TODO: Can we modify the config ourselves?
639
+ "\nSince you already have a Vitest config file, it is recommended to copy the contents of the new file ",
640
+ "into your existing config located at ",
641
+ c.bold(relative(process.cwd(), rootConfig))
642
+ );
664
643
  } else {
665
644
  const configPath = resolve(process.cwd(), `vitest.config.${lang}`);
666
645
  await generateFrameworkConfigFile({
@@ -670,7 +649,7 @@ async function create() {
670
649
  provider,
671
650
  browsers
672
651
  });
673
- log(c.green("✔"), "Created a config file for browser tests", c.bold(relative(process.cwd(), configPath)));
652
+ log(c.green("✔"), "Created a config file for browser tests:", c.bold(relative(process.cwd(), configPath)));
674
653
  }
675
654
  log();
676
655
  await updatePkgJsonScripts(pkgJsonPath, scriptCommand);
@@ -548,11 +548,9 @@ function listenForErrors(state) {
548
548
  dispose.length = 0;
549
549
  function catchError(err, type, event) {
550
550
  const worker = state();
551
- if (worker.current?.type === "test") {
552
- const listeners = process.listeners(event);
553
- if (listeners.length > 1) {
554
- return;
555
- }
551
+ const listeners = process.listeners(event);
552
+ if (listeners.length > 1) {
553
+ return;
556
554
  }
557
555
  const error = processError(err);
558
556
  if (!isPrimitive(error)) {
@@ -39,12 +39,12 @@ declare global {
39
39
  }
40
40
  }
41
41
  interface SnapshotMatcher<T> {
42
- <U extends { [P in keyof T] : any }>(snapshot: Partial<U>, message?: string): void;
43
- (message?: string): void;
42
+ <U extends { [P in keyof T] : any }>(snapshot: Partial<U>, hint?: string): void;
43
+ (hint?: string): void;
44
44
  }
45
45
  interface InlineSnapshotMatcher<T> {
46
- <U extends { [P in keyof T] : any }>(properties: Partial<U>, snapshot?: string, message?: string): void;
47
- (message?: string): void;
46
+ <U extends { [P in keyof T] : any }>(properties: Partial<U>, snapshot?: string, hint?: string): void;
47
+ (hint?: string): void;
48
48
  }
49
49
  declare module "@vitest/expect" {
50
50
  interface MatcherState {
@@ -72,35 +72,35 @@ declare module "@vitest/expect" {
72
72
  /**
73
73
  * Checks that an error thrown by a function matches a previously recorded snapshot.
74
74
  *
75
- * @param message - Optional custom error message.
75
+ * @param hint - Optional custom error message.
76
76
  *
77
77
  * @example
78
78
  * expect(functionWithError).toThrowErrorMatchingSnapshot();
79
79
  */
80
- toThrowErrorMatchingSnapshot: (message?: string) => void;
80
+ toThrowErrorMatchingSnapshot: (hint?: string) => void;
81
81
  /**
82
82
  * Checks that an error thrown by a function matches an inline snapshot within the test file.
83
83
  * Useful for keeping snapshots close to the test code.
84
84
  *
85
85
  * @param snapshot - Optional inline snapshot string to match.
86
- * @param message - Optional custom error message.
86
+ * @param hint - Optional custom error message.
87
87
  *
88
88
  * @example
89
89
  * const throwError = () => { throw new Error('Error occurred') };
90
90
  * expect(throwError).toThrowErrorMatchingInlineSnapshot(`"Error occurred"`);
91
91
  */
92
- toThrowErrorMatchingInlineSnapshot: (snapshot?: string, message?: string) => void;
92
+ toThrowErrorMatchingInlineSnapshot: (snapshot?: string, hint?: string) => void;
93
93
  /**
94
94
  * Compares the received value to a snapshot saved in a specified file.
95
95
  * Useful for cases where snapshot content is large or needs to be shared across tests.
96
96
  *
97
97
  * @param filepath - Path to the snapshot file.
98
- * @param message - Optional custom error message.
98
+ * @param hint - Optional custom error message.
99
99
  *
100
100
  * @example
101
101
  * await expect(largeData).toMatchFileSnapshot('path/to/snapshot.json');
102
102
  */
103
- toMatchFileSnapshot: (filepath: string, message?: string) => Promise<void>;
103
+ toMatchFileSnapshot: (filepath: string, hint?: string) => Promise<void>;
104
104
  }
105
105
  }
106
106
  declare module "@vitest/runner" {
@@ -1,5 +1,5 @@
1
1
  import { g as globalApis } from './constants.BZZyIeIE.js';
2
- import { V as VitestIndex } from './index.BPc7M5ni.js';
2
+ import { V as VitestIndex } from './index.CfXMNXHg.js';
3
3
  import './vi.BFR5YIgu.js';
4
4
  import '@vitest/expect';
5
5
  import '@vitest/runner';
@@ -13,7 +13,6 @@ import '@vitest/utils/error';
13
13
  import '@vitest/spy';
14
14
  import '@vitest/utils/source-map';
15
15
  import './date.CDOsz-HY.js';
16
- import './run-once.Dimr7O9f.js';
17
16
  import './benchmark.BoF7jW0Q.js';
18
17
  import 'expect-type';
19
18
 
@@ -1,7 +1,7 @@
1
1
  import process from 'node:process';
2
2
  import fs, { existsSync } from 'node:fs';
3
3
  import fsPromises from 'node:fs/promises';
4
- import p, { resolve } from 'node:path';
4
+ import path, { resolve } from 'node:path';
5
5
  import { x } from 'tinyexec';
6
6
 
7
7
  const AGENTS = [
@@ -27,27 +27,27 @@ async function detect(options = {}) {
27
27
  const { cwd, onUnknown } = options;
28
28
  for (const directory of lookup(cwd)) {
29
29
  for (const lock of Object.keys(LOCKS)) {
30
- if (await fileExists(p.join(directory, lock))) {
30
+ if (await fileExists(path.join(directory, lock))) {
31
31
  const name = LOCKS[lock];
32
- const result2 = await parsePackageJson(p.join(directory, "package.json"), onUnknown);
32
+ const result2 = await parsePackageJson(path.join(directory, "package.json"), onUnknown);
33
33
  if (result2)
34
34
  return result2;
35
35
  else
36
36
  return { name, agent: name };
37
37
  }
38
38
  }
39
- const result = await parsePackageJson(p.join(directory, "package.json"), onUnknown);
39
+ const result = await parsePackageJson(path.join(directory, "package.json"), onUnknown);
40
40
  if (result)
41
41
  return result;
42
42
  }
43
43
  return null;
44
44
  }
45
45
  function* lookup(cwd = process.cwd()) {
46
- let directory = p.resolve(cwd);
47
- const { root } = p.parse(directory);
46
+ let directory = path.resolve(cwd);
47
+ const { root } = path.parse(directory);
48
48
  while (directory && directory !== root) {
49
49
  yield directory;
50
- directory = p.dirname(directory);
50
+ directory = path.dirname(directory);
51
51
  }
52
52
  }
53
53
  async function parsePackageJson(filepath, onUnknown) {