vitest 3.0.0-beta.3 → 3.0.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 (54) hide show
  1. package/LICENSE.md +1 -315
  2. package/config.d.ts +2 -0
  3. package/dist/browser.d.ts +3 -3
  4. package/dist/browser.js +1 -1
  5. package/dist/chunks/{base.CQ2VEtuH.js → base.CUDzyU2J.js} +2 -2
  6. package/dist/chunks/{cac.e7qW4xLT.js → cac.DZC9WjGM.js} +8 -8
  7. package/dist/chunks/{cli-api.CWDlED-m.js → cli-api.CmJw5Cd_.js} +920 -84
  8. package/dist/chunks/{config.BTPBhmK5.d.ts → config.BRtC-JeT.d.ts} +6 -0
  9. package/dist/chunks/{console.BYGVloWk.js → console.CN7AiMGV.js} +16 -7
  10. package/dist/chunks/{creator.Ot9GlSGw.js → creator.DztqrnyH.js} +1 -1
  11. package/dist/chunks/{execute.2pr0rHgK.js → execute.BMOaRArH.js} +27 -16
  12. package/dist/chunks/global.CnI8_G5V.d.ts +133 -0
  13. package/dist/chunks/{globals.BFncSRNA.js → globals.C5RQxaV3.js} +2 -2
  14. package/dist/chunks/{index.CkWmZCXU.js → index.BQbxGbG9.js} +1 -1
  15. package/dist/chunks/{index.BBoOXW-l.js → index.CUcwvygK.js} +5 -5
  16. package/dist/chunks/{index.DQboAxJm.js → index.D9C26wCk.js} +1 -0
  17. package/dist/chunks/index.TKSL1HjN.js +2460 -0
  18. package/dist/chunks/{reporters.DCiyjXOg.d.ts → reporters.Y8BYiXBN.d.ts} +412 -386
  19. package/dist/chunks/{resolveConfig.C1d7TK-U.js → resolveConfig.CSLLD33d.js} +140 -55
  20. package/dist/chunks/{rpc.C3q9uwRX.js → rpc.TVf73xOu.js} +0 -1
  21. package/dist/chunks/{runBaseTests.qNWRkgHj.js → runBaseTests.C0T_TQwH.js} +9 -7
  22. package/dist/chunks/{setup-common.Cp_bu5q3.js → setup-common.D0zLenuv.js} +1 -1
  23. package/dist/chunks/{RandomSequencer.C6x84bNN.js → typechecker.BJMkWMXo.js} +84 -108
  24. package/dist/chunks/{utils.Coei4Wlj.js → utils.DJWL04yX.js} +9 -20
  25. package/dist/chunks/{vi.S4Fq8wSo.js → vi.Da_PT3Vw.js} +554 -272
  26. package/dist/chunks/{vite.CRSMFy31.d.ts → vite.CQ0dHgkN.d.ts} +1 -1
  27. package/dist/chunks/{vm.DGhTouO3.js → vm.DrFVeTXo.js} +4 -4
  28. package/dist/chunks/{worker.R-PA7DpW.d.ts → worker.B1y96qmv.d.ts} +1 -1
  29. package/dist/chunks/{worker.XbtCXEXv.d.ts → worker.CIpff8Eg.d.ts} +3 -5
  30. package/dist/cli.js +1 -1
  31. package/dist/config.d.ts +4 -4
  32. package/dist/coverage.d.ts +2 -2
  33. package/dist/coverage.js +5 -4
  34. package/dist/execute.d.ts +3 -3
  35. package/dist/execute.js +1 -1
  36. package/dist/index.d.ts +18 -119
  37. package/dist/index.js +2 -2
  38. package/dist/node.d.ts +12 -9
  39. package/dist/node.js +25 -24
  40. package/dist/reporters.d.ts +2 -2
  41. package/dist/reporters.js +4 -10
  42. package/dist/runners.d.ts +2 -1
  43. package/dist/runners.js +9 -16
  44. package/dist/worker.js +1 -1
  45. package/dist/workers/forks.js +2 -2
  46. package/dist/workers/runVmTests.js +8 -6
  47. package/dist/workers/threads.js +2 -2
  48. package/dist/workers/vmForks.js +3 -3
  49. package/dist/workers/vmThreads.js +3 -3
  50. package/dist/workers.d.ts +3 -3
  51. package/dist/workers.js +5 -5
  52. package/package.json +17 -19
  53. package/dist/chunks/index.CzkCSFCy.js +0 -5455
  54. package/dist/chunks/types.BOjykUpq.d.ts +0 -27
@@ -60,6 +60,12 @@ interface FakeTimerInstallOpts {
60
60
  * @default true
61
61
  */
62
62
  shouldClearNativeTimers?: boolean | undefined;
63
+
64
+ /**
65
+ * Don't throw error when asked to fake timers that are not present.
66
+ * @default false
67
+ */
68
+ ignoreMissingTimers?: boolean | undefined;
63
69
  }
64
70
 
65
71
  /**
@@ -27,13 +27,24 @@ function createCustomConsole(defaultState) {
27
27
  const stdoutBuffer = /* @__PURE__ */ new Map();
28
28
  const stderrBuffer = /* @__PURE__ */ new Map();
29
29
  const timers = /* @__PURE__ */ new Map();
30
- const { setTimeout, clearTimeout } = getSafeTimers();
30
+ const { queueMicrotask } = getSafeTimers();
31
+ function queueCancelableMicrotask(callback) {
32
+ let canceled = false;
33
+ queueMicrotask(() => {
34
+ if (!canceled) {
35
+ callback();
36
+ }
37
+ });
38
+ return () => {
39
+ canceled = true;
40
+ };
41
+ }
31
42
  const state = () => defaultState || getWorkerState();
32
43
  function schedule(taskId) {
33
44
  const timer = timers.get(taskId);
34
45
  const { stdoutTime, stderrTime } = timer;
35
- clearTimeout(timer.timer);
36
- timer.timer = setTimeout(() => {
46
+ timer.cancel?.();
47
+ timer.cancel = queueCancelableMicrotask(() => {
37
48
  if (stderrTime < stdoutTime) {
38
49
  sendStderr(taskId);
39
50
  sendStdout(taskId);
@@ -93,8 +104,7 @@ function createCustomConsole(defaultState) {
93
104
  } else {
94
105
  timer = {
95
106
  stdoutTime: RealDate.now(),
96
- stderrTime: RealDate.now(),
97
- timer: 0
107
+ stderrTime: RealDate.now()
98
108
  };
99
109
  timers.set(id, timer);
100
110
  }
@@ -127,8 +137,7 @@ function createCustomConsole(defaultState) {
127
137
  } else {
128
138
  timer = {
129
139
  stderrTime: RealDate.now(),
130
- stdoutTime: RealDate.now(),
131
- timer: 0
140
+ stdoutTime: RealDate.now()
132
141
  };
133
142
  timers.set(id, timer);
134
143
  }
@@ -1,7 +1,7 @@
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.DQboAxJm.js';
4
+ import { detectPackageManager, installPackage } from './index.D9C26wCk.js';
5
5
  import { p as prompt, f as findUp } from './index.BJDntFik.js';
6
6
  import { x } from 'tinyexec';
7
7
  import c from 'tinyrainbow';
@@ -21,6 +21,8 @@ function normalizeWindowsPath(input = "") {
21
21
  const _UNC_REGEX = /^[/\\]{2}/;
22
22
  const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
23
23
  const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
24
+ const _EXTNAME_RE = /.(\.[^./]+)$/;
25
+ globalThis.process?.platform === "win32" ? ";" : ":";
24
26
  const normalize = function(path) {
25
27
  if (path.length === 0) {
26
28
  return ".";
@@ -50,24 +52,26 @@ const normalize = function(path) {
50
52
  }
51
53
  return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
52
54
  };
53
- const join = function(...arguments_) {
54
- if (arguments_.length === 0) {
55
- return ".";
56
- }
57
- let joined;
58
- for (const argument of arguments_) {
59
- if (argument && argument.length > 0) {
60
- if (joined === void 0) {
61
- joined = argument;
55
+ const join = function(...segments) {
56
+ let path = "";
57
+ for (const seg of segments) {
58
+ if (!seg) {
59
+ continue;
60
+ }
61
+ if (path.length > 0) {
62
+ const pathTrailing = path[path.length - 1] === "/";
63
+ const segLeading = seg[0] === "/";
64
+ const both = pathTrailing && segLeading;
65
+ if (both) {
66
+ path += seg.slice(1);
62
67
  } else {
63
- joined += `/${argument}`;
68
+ path += pathTrailing || segLeading ? seg : `/${seg}`;
64
69
  }
70
+ } else {
71
+ path += seg;
65
72
  }
66
73
  }
67
- if (joined === void 0) {
68
- return ".";
69
- }
70
- return normalize(joined.replace(/\/\/+/g, "/"));
74
+ return normalize(path);
71
75
  };
72
76
  function cwd() {
73
77
  if (typeof process !== "undefined" && typeof process.cwd === "function") {
@@ -156,7 +160,6 @@ function normalizeString(path, allowAboveRoot) {
156
160
  const isAbsolute = function(p) {
157
161
  return _IS_ABSOLUTE_RE.test(p);
158
162
  };
159
- const _EXTNAME_RE = /.(\.[^./]+)$/;
160
163
  const extname = function(p) {
161
164
  const match = _EXTNAME_RE.exec(normalizeWindowsPath(p));
162
165
  return match && match[1] || "";
@@ -169,7 +172,15 @@ const dirname = function(p) {
169
172
  return segments.join("/") || (isAbsolute(p) ? "/" : ".");
170
173
  };
171
174
  const basename = function(p, extension) {
172
- const lastSegment = normalizeWindowsPath(p).split("/").pop();
175
+ const segments = normalizeWindowsPath(p).split("/");
176
+ let lastSegment = "";
177
+ for (let i = segments.length - 1; i >= 0; i--) {
178
+ const val = segments[i];
179
+ if (val) {
180
+ lastSegment = val;
181
+ break;
182
+ }
183
+ }
173
184
  return extension && lastSegment.endsWith(extension) ? lastSegment.slice(0, -extension.length) : lastSegment;
174
185
  };
175
186
 
@@ -0,0 +1,133 @@
1
+ import { PromisifyAssertion, Tester, ExpectStatic } from '@vitest/expect';
2
+ import { Plugin } from '@vitest/pretty-format';
3
+ import { SnapshotState } from '@vitest/snapshot';
4
+ import { B as BenchmarkResult } from './benchmark.CFFwLv-O.js';
5
+ import { U as UserConsoleLog } from './environment.d8YfPkTm.js';
6
+
7
+ type RawErrsMap = Map<string, TscErrorInfo[]>;
8
+ interface TscErrorInfo {
9
+ filePath: string;
10
+ errCode: number;
11
+ errMsg: string;
12
+ line: number;
13
+ column: number;
14
+ }
15
+ interface CollectLineNumbers {
16
+ target: number;
17
+ next: number;
18
+ prev?: number;
19
+ }
20
+ type CollectLines = {
21
+ [key in keyof CollectLineNumbers]: string;
22
+ };
23
+ interface RootAndTarget {
24
+ root: string;
25
+ targetAbsPath: string;
26
+ }
27
+ type Context = RootAndTarget & {
28
+ rawErrsMap: RawErrsMap;
29
+ openedDirs: Set<string>;
30
+ lastActivePath?: string;
31
+ };
32
+
33
+ declare global {
34
+ namespace Chai {
35
+ interface Assertion {
36
+ containSubset: (expected: any) => Assertion;
37
+ }
38
+ interface Assert {
39
+ containSubset: (val: any, exp: any, msg?: string) => void;
40
+ }
41
+ }
42
+ }
43
+ interface SnapshotMatcher<T> {
44
+ <U extends {
45
+ [P in keyof T]: any;
46
+ }>(snapshot: Partial<U>, message?: string): void;
47
+ (message?: string): void;
48
+ }
49
+ interface InlineSnapshotMatcher<T> {
50
+ <U extends {
51
+ [P in keyof T]: any;
52
+ }>(properties: Partial<U>, snapshot?: string, message?: string): void;
53
+ (message?: string): void;
54
+ }
55
+ declare module '@vitest/expect' {
56
+ interface MatcherState {
57
+ environment: string;
58
+ snapshotState: SnapshotState;
59
+ }
60
+ interface ExpectPollOptions {
61
+ interval?: number;
62
+ timeout?: number;
63
+ message?: string;
64
+ }
65
+ interface ExpectStatic {
66
+ unreachable: (message?: string) => never;
67
+ soft: <T>(actual: T, message?: string) => Assertion<T>;
68
+ poll: <T>(actual: () => T, options?: ExpectPollOptions) => PromisifyAssertion<Awaited<T>>;
69
+ addEqualityTesters: (testers: Array<Tester>) => void;
70
+ assertions: (expected: number) => void;
71
+ hasAssertions: () => void;
72
+ addSnapshotSerializer: (plugin: Plugin) => void;
73
+ }
74
+ interface Assertion<T> {
75
+ matchSnapshot: SnapshotMatcher<T>;
76
+ toMatchSnapshot: SnapshotMatcher<T>;
77
+ toMatchInlineSnapshot: InlineSnapshotMatcher<T>;
78
+ /**
79
+ * Checks that an error thrown by a function matches a previously recorded snapshot.
80
+ *
81
+ * @param message - Optional custom error message.
82
+ *
83
+ * @example
84
+ * expect(functionWithError).toThrowErrorMatchingSnapshot();
85
+ */
86
+ toThrowErrorMatchingSnapshot: (message?: string) => void;
87
+ /**
88
+ * Checks that an error thrown by a function matches an inline snapshot within the test file.
89
+ * Useful for keeping snapshots close to the test code.
90
+ *
91
+ * @param snapshot - Optional inline snapshot string to match.
92
+ * @param message - Optional custom error message.
93
+ *
94
+ * @example
95
+ * const throwError = () => { throw new Error('Error occurred') };
96
+ * expect(throwError).toThrowErrorMatchingInlineSnapshot(`"Error occurred"`);
97
+ */
98
+ toThrowErrorMatchingInlineSnapshot: (snapshot?: string, message?: string) => void;
99
+ /**
100
+ * Compares the received value to a snapshot saved in a specified file.
101
+ * Useful for cases where snapshot content is large or needs to be shared across tests.
102
+ *
103
+ * @param filepath - Path to the snapshot file.
104
+ * @param message - Optional custom error message.
105
+ *
106
+ * @example
107
+ * await expect(largeData).toMatchFileSnapshot('path/to/snapshot.json');
108
+ */
109
+ toMatchFileSnapshot: (filepath: string, message?: string) => Promise<void>;
110
+ }
111
+ }
112
+ declare module '@vitest/runner' {
113
+ interface TestContext {
114
+ expect: ExpectStatic;
115
+ }
116
+ interface TaskMeta {
117
+ typecheck?: boolean;
118
+ benchmark?: boolean;
119
+ failScreenshotPath?: string;
120
+ }
121
+ interface File {
122
+ prepareDuration?: number;
123
+ environmentLoad?: number;
124
+ }
125
+ interface TaskBase {
126
+ logs?: UserConsoleLog[];
127
+ }
128
+ interface TaskResult {
129
+ benchmark?: BenchmarkResult;
130
+ }
131
+ }
132
+
133
+ export type { CollectLineNumbers as C, RawErrsMap as R, TscErrorInfo as T, CollectLines as a, RootAndTarget as b, Context as c };
@@ -1,6 +1,6 @@
1
1
  import { g as globalApis } from './constants.fzPh7AOq.js';
2
- import { V as VitestIndex } from './index.CkWmZCXU.js';
3
- import './vi.S4Fq8wSo.js';
2
+ import { V as VitestIndex } from './index.BQbxGbG9.js';
3
+ import './vi.Da_PT3Vw.js';
4
4
  import '@vitest/expect';
5
5
  import '@vitest/runner';
6
6
  import '@vitest/runner/utils';
@@ -1,4 +1,4 @@
1
- import { c as createExpect, a as globalExpect, i as inject, v as vi, b as vitest } from './vi.S4Fq8wSo.js';
1
+ import { c as createExpect, a as globalExpect, i as inject, v as vi, b as vitest } from './vi.Da_PT3Vw.js';
2
2
  import { i as isFirstRun, a as runOnce } from './run-once.2ogXb3JV.js';
3
3
  import { b as bench } from './benchmark.Cdu9hjj4.js';
4
4
  import { expectTypeOf } from 'expect-type';
@@ -2,8 +2,8 @@ import * as chai from 'chai';
2
2
  import { resolve } from 'node:path';
3
3
  import { t as takeCoverageInsideWorker } from './coverage.BWeNbfBa.js';
4
4
  import { distDir } from '../path.js';
5
- import { r as rpc } from './rpc.C3q9uwRX.js';
6
- import { l as loadDiffConfig, a as loadSnapshotSerializers } from './setup-common.Cp_bu5q3.js';
5
+ import { r as rpc } from './rpc.TVf73xOu.js';
6
+ import { l as loadDiffConfig, a as loadSnapshotSerializers } from './setup-common.D0zLenuv.js';
7
7
  import { g as getWorkerState } from './utils.C8RiOc4B.js';
8
8
 
9
9
  function setupChaiConfig(config) {
@@ -58,9 +58,9 @@ async function resolveTestRunner(config, executor) {
58
58
  ]);
59
59
  testRunner.config.diffOptions = diffOptions;
60
60
  const originalOnTaskUpdate = testRunner.onTaskUpdate;
61
- testRunner.onTaskUpdate = async (task) => {
62
- const p = rpc().onTaskUpdate(task);
63
- await originalOnTaskUpdate?.call(testRunner, task);
61
+ testRunner.onTaskUpdate = async (task, events) => {
62
+ const p = rpc().onTaskUpdate(task, events);
63
+ await originalOnTaskUpdate?.call(testRunner, task, events);
64
64
  return p;
65
65
  };
66
66
  const originalOnCollectStart = testRunner.onCollectStart;
@@ -14,6 +14,7 @@ const AGENTS = [
14
14
  "deno"
15
15
  ];
16
16
  const LOCKS = {
17
+ "bun.lock": "bun",
17
18
  "bun.lockb": "bun",
18
19
  "deno.lock": "deno",
19
20
  "pnpm-lock.yaml": "pnpm",