vitest 3.1.3 → 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 (57) hide show
  1. package/LICENSE.md +0 -232
  2. package/dist/browser.d.ts +4 -2
  3. package/dist/browser.js +3 -4
  4. package/dist/chunks/{base.DslwPSCy.js → base.DwtwORaC.js} +2 -2
  5. package/dist/chunks/{cac.BN2e7cE1.js → cac.I9MLYfT-.js} +14 -10
  6. package/dist/chunks/{cli-api.Bti1vevt.js → cli-api.d6IK1pnk.js} +945 -852
  7. package/dist/chunks/{coverage.87S59-Sl.js → coverage.OGU09Jbh.js} +129 -4216
  8. package/dist/chunks/{creator.CuL7xDWI.js → creator.DGAdZ4Hj.js} +18 -39
  9. package/dist/chunks/{environment.d.Dmw5ulng.d.ts → environment.d.D8YDy2v5.d.ts} +2 -1
  10. package/dist/chunks/{execute.BpmIjFTD.js → execute.JlGHLJZT.js} +3 -5
  11. package/dist/chunks/{global.d.CXRAxnWc.d.ts → global.d.BPa1eL3O.d.ts} +17 -12
  12. package/dist/chunks/{globals.CZAEe_Gf.js → globals.CpxW8ccg.js} +2 -3
  13. package/dist/chunks/{index.Bw6JxgX8.js → index.CK1YOQaa.js} +7 -7
  14. package/dist/chunks/{index.De2FqGmR.js → index.CV36oG_L.js} +896 -957
  15. package/dist/chunks/{index.B0uVAVvx.js → index.CfXMNXHg.js} +2 -14
  16. package/dist/chunks/index.CmC5OK9L.js +275 -0
  17. package/dist/chunks/{index.Cu2UlluP.js → index.DswW_LEs.js} +2 -2
  18. package/dist/chunks/{index.DBIGubLC.js → index.X0nbfr6-.js} +7 -7
  19. package/dist/chunks/{reporters.d.DG9VKi4m.d.ts → reporters.d.CLC9rhKy.d.ts} +68 -11
  20. package/dist/chunks/{runBaseTests.BV8m0B-u.js → runBaseTests.Dn2vyej_.js} +5 -6
  21. package/dist/chunks/{setup-common.AQcDs321.js → setup-common.CYo3Y0dD.js} +1 -3
  22. package/dist/chunks/typechecker.DnTrplSJ.js +897 -0
  23. package/dist/chunks/{vi.ClIskdbk.js → vi.BFR5YIgu.js} +3 -0
  24. package/dist/chunks/{vite.d.D3ndlJcw.d.ts → vite.d.CBZ3M_ru.d.ts} +1 -1
  25. package/dist/chunks/{vm.CuLHT1BG.js → vm.C1HHjtNS.js} +1 -1
  26. package/dist/chunks/{worker.d.CHGSOG0s.d.ts → worker.d.CoCI7hzP.d.ts} +1 -1
  27. package/dist/chunks/{worker.d.C-KN07Ls.d.ts → worker.d.D5Xdi-Zr.d.ts} +1 -1
  28. package/dist/cli.js +20 -1
  29. package/dist/config.cjs +3 -0
  30. package/dist/config.d.ts +8 -5
  31. package/dist/config.js +3 -0
  32. package/dist/coverage.d.ts +3 -3
  33. package/dist/coverage.js +4 -7
  34. package/dist/environments.d.ts +2 -2
  35. package/dist/execute.d.ts +2 -2
  36. package/dist/execute.js +1 -1
  37. package/dist/index.d.ts +45 -32
  38. package/dist/index.js +2 -3
  39. package/dist/node.d.ts +8 -8
  40. package/dist/node.js +16 -18
  41. package/dist/reporters.d.ts +3 -3
  42. package/dist/reporters.js +14 -14
  43. package/dist/runners.d.ts +1 -1
  44. package/dist/runners.js +2 -2
  45. package/dist/workers/forks.js +2 -2
  46. package/dist/workers/runVmTests.js +5 -6
  47. package/dist/workers/threads.js +2 -2
  48. package/dist/workers/vmForks.js +2 -2
  49. package/dist/workers/vmThreads.js +2 -2
  50. package/dist/workers.d.ts +3 -3
  51. package/dist/workers.js +3 -3
  52. package/package.json +15 -19
  53. package/dist/chunks/run-once.Dimr7O9f.js +0 -47
  54. package/dist/chunks/typechecker.DYQbn8uK.js +0 -956
  55. package/dist/chunks/utils.Cc45eY3L.js +0 -200
  56. package/dist/utils.d.ts +0 -3
  57. 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);
@@ -36,6 +36,7 @@ interface ModuleGraphData {
36
36
  inlined: string[];
37
37
  }
38
38
  interface ProvidedContext {}
39
+ type LabelColor = "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white";
39
40
 
40
41
  type HappyDOMOptions = Omit<NonNullable<ConstructorParameters<typeof happyDomTypes.Window>[0]>, "console">;
41
42
 
@@ -114,4 +115,4 @@ interface ResolvedTestEnvironment {
114
115
  options: Record<string, any> | null;
115
116
  }
116
117
 
117
- export type { AfterSuiteRunMeta as A, Constructable as C, Environment as E, HappyDOMOptions as H, JSDOMOptions as J, ModuleGraphData as M, Nullable as N, ProvidedContext as P, ResolvedTestEnvironment as R, TransformMode as T, UserConsoleLog as U, VmEnvironmentReturn as V, EnvironmentReturn as a, Awaitable as b, Arrayable as c, ArgumentsType as d, MutableArray as e, EnvironmentOptions as f, ModuleCache as g };
118
+ export type { AfterSuiteRunMeta as A, Constructable as C, Environment as E, HappyDOMOptions as H, JSDOMOptions as J, LabelColor as L, ModuleGraphData as M, Nullable as N, ProvidedContext as P, ResolvedTestEnvironment as R, TransformMode as T, UserConsoleLog as U, VmEnvironmentReturn as V, EnvironmentReturn as a, Awaitable as b, Arrayable as c, ArgumentsType as d, MutableArray as e, EnvironmentOptions as f, ModuleCache as g };
@@ -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)) {
@@ -2,7 +2,7 @@ import { PromisifyAssertion, Tester, ExpectStatic } from '@vitest/expect';
2
2
  import { Plugin } from '@vitest/pretty-format';
3
3
  import { SnapshotState } from '@vitest/snapshot';
4
4
  import { B as BenchmarkResult } from './benchmark.d.BwvBVTda.js';
5
- import { U as UserConsoleLog } from './environment.d.Dmw5ulng.js';
5
+ import { U as UserConsoleLog } from './environment.d.D8YDy2v5.js';
6
6
 
7
7
  type RawErrsMap = Map<string, TscErrorInfo[]>;
8
8
  interface TscErrorInfo {
@@ -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,40 +72,45 @@ 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" {
107
107
  interface TestContext {
108
- expect: ExpectStatic;
108
+ /**
109
+ * `expect` instance bound to the current test.
110
+ *
111
+ * This API is useful for running snapshot tests concurrently because global expect cannot track them.
112
+ */
113
+ readonly expect: ExpectStatic;
109
114
  }
110
115
  interface TaskMeta {
111
116
  typecheck?: boolean;
@@ -1,6 +1,6 @@
1
1
  import { g as globalApis } from './constants.BZZyIeIE.js';
2
- import { V as VitestIndex } from './index.B0uVAVvx.js';
3
- import './vi.ClIskdbk.js';
2
+ import { V as VitestIndex } from './index.CfXMNXHg.js';
3
+ import './vi.BFR5YIgu.js';
4
4
  import '@vitest/expect';
5
5
  import '@vitest/runner';
6
6
  import '@vitest/runner/utils';
@@ -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) {