vitest 4.0.0-beta.5 → 4.0.0-beta.6

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 +1 -1
  2. package/dist/browser.d.ts +1 -1
  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/{cac.CKnbxhn2.js → cac.WE-urWw5.js} +37 -113
  7. package/dist/chunks/{cli-api.COn58yrl.js → cli-api.CZz3evYC.js} +505 -1211
  8. package/dist/chunks/{console.Duv2dVIC.js → console.B0quX7yH.js} +32 -68
  9. package/dist/chunks/{coverage.B6cReEn1.js → coverage.BPRS6xgn.js} +210 -579
  10. package/dist/chunks/{creator.DUVZ6rfm.js → creator.KEg6n5IC.js} +28 -74
  11. package/dist/chunks/{date.Bq6ZW5rf.js → date.-jtEtIeV.js} +6 -17
  12. package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
  13. package/dist/chunks/{globals.CJQ63oO0.js → globals.lgsmH00r.js} +5 -5
  14. package/dist/chunks/{index.DgN0Zk9a.js → index.7w0eqmYM.js} +14 -24
  15. package/dist/chunks/{index.QZr3S3vQ.js → index.AR8aAkCC.js} +2 -2
  16. package/dist/chunks/{index.BRtIe7r8.js → index.BG0gqZH-.js} +39 -102
  17. package/dist/chunks/{index.oWRWx-nj.js → index.CsFXYRkW.js} +17 -36
  18. package/dist/chunks/{index.DQhAfQQU.js → index.VNI-1z5c.js} +270 -606
  19. package/dist/chunks/{inspector.C914Efll.js → inspector.CvQD-Nie.js} +10 -25
  20. package/dist/chunks/{moduleRunner.d.mmOmOGrW.d.ts → moduleRunner.d.8kKUsuDg.d.ts} +1 -1
  21. package/dist/chunks/{node.4JV5OXkt.js → node.BOqcT2jW.js} +1 -1
  22. package/dist/chunks/{plugin.d.CvOlgjxK.d.ts → plugin.d.DuiQJfUL.d.ts} +1 -1
  23. package/dist/chunks/{reporters.d.CYE9sT5z.d.ts → reporters.d.CqR9-CDJ.d.ts} +16 -33
  24. package/dist/chunks/{resolver.D5bG4zy5.js → resolver.Bx6lE0iq.js} +21 -64
  25. package/dist/chunks/{rpc.DGoW_Vl-.js → rpc.RpPylpp0.js} +7 -21
  26. package/dist/chunks/{runBaseTests.B3KcKqlF.js → runBaseTests.D6sfuWBM.js} +25 -54
  27. package/dist/chunks/{setup-common.lgPs-bYv.js → setup-common.hLGRxhC8.js} +9 -22
  28. package/dist/chunks/{startModuleRunner.C8FtT_BY.js → startModuleRunner.C8TW8zTN.js} +83 -205
  29. package/dist/chunks/{typechecker.BgoW4nTA.js → typechecker.Cd1wvxUM.js} +96 -208
  30. package/dist/chunks/{utils.CcGm2cd1.js → utils.C2YI6McM.js} +4 -13
  31. package/dist/chunks/{utils.B9FY3b73.js → utils.C7__0Iv5.js} +5 -14
  32. package/dist/chunks/{vi.DGAfBY4R.js → vi.BfdOiD4j.js} +110 -267
  33. package/dist/chunks/{vm.BKfKvaKl.js → vm.BHBje7cC.js} +73 -177
  34. package/dist/cli.js +3 -3
  35. package/dist/config.d.ts +4 -4
  36. package/dist/coverage.d.ts +1 -1
  37. package/dist/coverage.js +2 -2
  38. package/dist/environments.js +1 -1
  39. package/dist/index.js +5 -5
  40. package/dist/module-evaluator.d.ts +1 -1
  41. package/dist/module-evaluator.js +33 -84
  42. package/dist/module-runner.js +2 -2
  43. package/dist/node.d.ts +3 -3
  44. package/dist/node.js +13 -19
  45. package/dist/reporters.d.ts +2 -2
  46. package/dist/reporters.js +3 -3
  47. package/dist/runners.js +23 -51
  48. package/dist/snapshot.js +2 -2
  49. package/dist/suite.js +2 -2
  50. package/dist/worker.js +18 -34
  51. package/dist/workers/forks.js +4 -4
  52. package/dist/workers/runVmTests.js +19 -37
  53. package/dist/workers/threads.js +4 -4
  54. package/dist/workers/vmForks.js +7 -7
  55. package/dist/workers/vmThreads.js +7 -7
  56. package/dist/workers.js +11 -11
  57. package/package.json +11 -11
@@ -2,55 +2,40 @@ import { createRequire } from 'node:module';
2
2
  import { pathToFileURL } from 'node:url';
3
3
 
4
4
  const __require = createRequire(import.meta.url);
5
- let inspector;
6
- let session;
5
+ let inspector, session;
7
6
  /**
8
7
  * Enables debugging inside `worker_threads` and `child_process`.
9
8
  * Should be called as early as possible when worker/process has been set up.
10
9
  */
11
10
  function setupInspect(ctx) {
12
- const config = ctx.config;
13
- const isEnabled = config.inspector.enabled;
11
+ const config = ctx.config, isEnabled = config.inspector.enabled;
14
12
  if (isEnabled) {
15
13
  inspector = __require("node:inspector");
16
14
  // Inspector may be open already if "isolate: false" is used
17
15
  const isOpen = inspector.url() !== void 0;
18
16
  if (!isOpen) {
19
- inspector.open(config.inspector.port, config.inspector.host, config.inspector.waitForDebugger);
20
- if (config.inspectBrk) {
17
+ if (inspector.open(config.inspector.port, config.inspector.host, config.inspector.waitForDebugger), config.inspectBrk) {
21
18
  const firstTestFile = typeof ctx.files[0] === "string" ? ctx.files[0] : ctx.files[0].filepath;
22
19
  // Stop at first test file
23
- if (firstTestFile) {
24
- session = new inspector.Session();
25
- session.connect();
26
- session.post("Debugger.enable");
27
- session.post("Debugger.setBreakpointByUrl", {
28
- lineNumber: 0,
29
- url: pathToFileURL(firstTestFile)
30
- });
31
- }
20
+ if (firstTestFile) session = new inspector.Session(), session.connect(), session.post("Debugger.enable"), session.post("Debugger.setBreakpointByUrl", {
21
+ lineNumber: 0,
22
+ url: pathToFileURL(firstTestFile)
23
+ });
32
24
  }
33
25
  }
34
26
  }
35
27
  const keepOpen = shouldKeepOpen(config);
36
28
  return function cleanup() {
37
- if (isEnabled && !keepOpen && inspector) {
38
- inspector.close();
39
- session?.disconnect();
40
- }
29
+ if (isEnabled && !keepOpen && inspector) inspector.close(), session?.disconnect();
41
30
  };
42
31
  }
43
32
  function closeInspector(config) {
44
33
  const keepOpen = shouldKeepOpen(config);
45
- if (inspector && !keepOpen) {
46
- inspector.close();
47
- session?.disconnect();
48
- }
34
+ if (inspector && !keepOpen) inspector.close(), session?.disconnect();
49
35
  }
50
36
  function shouldKeepOpen(config) {
51
37
  // In watch mode the inspector can persist re-runs if isolation is disabled and a single worker is used
52
- const isIsolatedSingleThread = config.pool === "threads" && config.poolOptions?.threads?.isolate === false && config.poolOptions?.threads?.singleThread;
53
- const isIsolatedSingleFork = config.pool === "forks" && config.poolOptions?.forks?.isolate === false && config.poolOptions?.forks?.singleFork;
38
+ const isIsolatedSingleThread = config.pool === "threads" && config.poolOptions?.threads?.isolate === false && config.poolOptions?.threads?.singleThread, isIsolatedSingleFork = config.pool === "forks" && config.poolOptions?.forks?.isolate === false && config.poolOptions?.forks?.singleFork;
54
39
  return config.watch && (isIsolatedSingleFork || isIsolatedSingleThread);
55
40
  }
56
41
 
@@ -159,7 +159,7 @@ declare class VitestMocker {
159
159
  getMockPath(dep: string): string;
160
160
  getDependencyMock(id: string): MockedModule | undefined;
161
161
  findMockRedirect(mockPath: string, external: string | null): string | null;
162
- mockObject(object: Record<string | symbol, any>, mockExports?: Record<string | symbol, any>, behavior?: MockedModuleType): Record<string | symbol, any>;
162
+ mockObject(object: Record<string | symbol, any>, mockExports?: Record<string | symbol, any>, behavior?: "automock" | "autospy"): Record<string | symbol, any>;
163
163
  unmockPath(id: string): void;
164
164
  mockPath(originalId: string, id: string, url: string, external: string | null, mockType: MockedModuleType | undefined, factory: MockFactory | undefined): void;
165
165
  importActual<T>(rawId: string, importer: string, callstack?: string[] | null): Promise<T>;
@@ -1,5 +1,5 @@
1
1
  import { NodeSnapshotEnvironment } from '@vitest/snapshot/environment';
2
- import { g as getWorkerState } from './utils.B9FY3b73.js';
2
+ import { g as getWorkerState } from './utils.C7__0Iv5.js';
3
3
  import '@vitest/utils';
4
4
 
5
5
  class VitestNodeSnapshotEnvironment extends NodeSnapshotEnvironment {
@@ -1,4 +1,4 @@
1
- import { V as Vitest, T as TestProject, a as TestProjectConfiguration } from './reporters.d.CYE9sT5z.js';
1
+ import { V as Vitest, T as TestProject, a as TestProjectConfiguration } from './reporters.d.CqR9-CDJ.js';
2
2
 
3
3
  interface VitestPluginContext {
4
4
  vitest: Vitest;
@@ -1,6 +1,6 @@
1
- import { Task, CancelReason, TaskMeta, Suite, File, TestAnnotation, ImportDuration, TaskResultPack, TaskEventPack, SequenceSetupFiles, SequenceHooks } from '@vitest/runner';
2
- import { P as ProvidedContext, U as UserConsoleLog, b as Awaitable$1, c as Arrayable$1, A as AfterSuiteRunMeta, L as LabelColor } from './environment.d.2fYMoz3o.js';
1
+ import { Task, CancelReason, TaskMeta, Suite, File, TestAnnotation, ImportDuration, TaskResultPack, SequenceSetupFiles, SequenceHooks } from '@vitest/runner';
3
2
  import { ParsedStack, Awaitable, TestError, SerializedError, Arrayable } from '@vitest/utils';
3
+ import { P as ProvidedContext, U as UserConsoleLog, b as Awaitable$1, c as Arrayable$1, A as AfterSuiteRunMeta, L as LabelColor } from './environment.d.2fYMoz3o.js';
4
4
  import { Writable } from 'node:stream';
5
5
  import { ViteDevServer, ModuleNode, TransformResult as TransformResult$1, DepOptimizationConfig, ServerOptions, UserConfig as UserConfig$1, ConfigEnv, AliasOptions } from 'vite';
6
6
  import { Console } from 'node:console';
@@ -1173,9 +1173,11 @@ declare class BlobReporter implements Reporter {
1173
1173
  start: number;
1174
1174
  ctx: Vitest;
1175
1175
  options: BlobOptions;
1176
+ coverage: unknown | undefined;
1176
1177
  constructor(options: BlobOptions);
1177
1178
  onInit(ctx: Vitest): void;
1178
- onFinished(files: File[] | undefined, errors: unknown[] | undefined, coverage: unknown): Promise<void>;
1179
+ onCoverage(coverage: unknown): void;
1180
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>): Promise<void>;
1179
1181
  }
1180
1182
  interface MergedBlobs {
1181
1183
  files: File[];
@@ -1510,26 +1512,6 @@ interface Reporter {
1510
1512
  * @experimental
1511
1513
  */
1512
1514
  onBrowserInit?: (project: TestProject) => Awaitable$1<void>;
1513
- /**
1514
- * @deprecated use `onTestRunStart` instead
1515
- */
1516
- onPathsCollected?: (paths?: string[]) => Awaitable$1<void>;
1517
- /**
1518
- * @deprecated use `onTestRunStart` instead
1519
- */
1520
- onSpecsCollected?: (specs?: SerializedTestSpecification[]) => Awaitable$1<void>;
1521
- /**
1522
- * @deprecated use `onTestModuleCollected` instead
1523
- */
1524
- onCollected?: (files: File[]) => Awaitable$1<void>;
1525
- /**
1526
- * @deprecated use `onTestRunEnd` instead
1527
- */
1528
- onFinished?: (files: File[], errors: unknown[], coverage?: unknown) => Awaitable$1<void>;
1529
- /**
1530
- * @deprecated use `onTestModuleQueued`, `onTestModuleStart`, `onTestModuleEnd`, `onTestCaseReady`, `onTestCaseResult` instead
1531
- */
1532
- onTaskUpdate?: (packs: TaskResultPack[], events: TaskEventPack[]) => Awaitable$1<void>;
1533
1515
  onTestRemoved?: (trigger?: string) => Awaitable$1<void>;
1534
1516
  onWatcherStart?: (files?: File[], errors?: unknown[]) => Awaitable$1<void>;
1535
1517
  onWatcherRerun?: (files: string[], trigger?: string) => Awaitable$1<void>;
@@ -1614,7 +1596,7 @@ declare abstract class BaseReporter implements Reporter {
1614
1596
  log(...messages: any): void;
1615
1597
  error(...messages: any): void;
1616
1598
  relative(path: string): string;
1617
- onFinished(files?: File[], errors?: unknown[]): void;
1599
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>, _reason: TestRunEndReason): void;
1618
1600
  onTestCaseResult(testCase: TestCase): void;
1619
1601
  onTestSuiteResult(testSuite: TestSuite): void;
1620
1602
  onTestModuleEnd(testModule: TestModule): void;
@@ -1650,6 +1632,7 @@ declare class DefaultReporter extends BaseReporter {
1650
1632
  private summary?;
1651
1633
  constructor(options?: DefaultReporterOptions);
1652
1634
  onTestRunStart(specifications: ReadonlyArray<TestSpecification>): void;
1635
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>, reason: TestRunEndReason): void;
1653
1636
  onTestModuleQueued(file: TestModule): void;
1654
1637
  onTestModuleCollected(module: TestModule): void;
1655
1638
  onTestModuleEnd(module: TestModule): void;
@@ -1658,7 +1641,6 @@ declare class DefaultReporter extends BaseReporter {
1658
1641
  onHookStart(hook: ReportedHookContext): void;
1659
1642
  onHookEnd(hook: ReportedHookContext): void;
1660
1643
  onInit(ctx: Vitest): void;
1661
- onTestRunEnd(): void;
1662
1644
  }
1663
1645
 
1664
1646
  interface HTMLOptions {
@@ -1819,10 +1801,11 @@ declare class JsonReporter implements Reporter {
1819
1801
  start: number;
1820
1802
  ctx: Vitest;
1821
1803
  options: JsonOptions$1;
1804
+ coverageMap?: CoverageMap;
1822
1805
  constructor(options: JsonOptions$1);
1823
1806
  onInit(ctx: Vitest): void;
1824
- protected logTasks(files: File[], coverageMap?: CoverageMap | null): Promise<void>;
1825
- onFinished(files?: File[], _errors?: unknown[], coverageMap?: unknown): Promise<void>;
1807
+ onCoverage(coverageMap: unknown): void;
1808
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>): Promise<void>;
1826
1809
  /**
1827
1810
  * Writes the report to an output file if specified in the config,
1828
1811
  * or logs it to the console otherwise.
@@ -1866,7 +1849,7 @@ declare class JUnitReporter implements Reporter {
1866
1849
  writeElement(name: string, attrs: Record<string, any>, children: () => Promise<void>): Promise<void>;
1867
1850
  writeLogs(task: Task, type: "err" | "out"): Promise<void>;
1868
1851
  writeTasks(tasks: Task[], filename: string): Promise<void>;
1869
- onFinished(files?: File[]): Promise<void>;
1852
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>): Promise<void>;
1870
1853
  }
1871
1854
 
1872
1855
  declare class DotReporter extends BaseReporter {
@@ -1877,7 +1860,7 @@ declare class DotReporter extends BaseReporter {
1877
1860
  // Ignore default logging of base reporter
1878
1861
  printTestModule(): void;
1879
1862
  onWatcherRerun(files: string[], trigger?: string): void;
1880
- onFinished(files?: File[], errors?: unknown[]): void;
1863
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>, reason: TestRunEndReason): void;
1881
1864
  onTestModuleCollected(module: TestModule): void;
1882
1865
  onTestCaseReady(test: TestCase): void;
1883
1866
  onTestCaseResult(test: TestCase): void;
@@ -1894,7 +1877,7 @@ declare class GithubActionsReporter implements Reporter {
1894
1877
  constructor(options?: GithubActionsReporterOptions);
1895
1878
  onInit(ctx: Vitest): void;
1896
1879
  onTestCaseAnnotate(testCase: TestCase, annotation: TestAnnotation): void;
1897
- onFinished(files?: File[], errors?: unknown[]): void;
1880
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>): void;
1898
1881
  }
1899
1882
 
1900
1883
  declare class HangingProcessReporter implements Reporter {
@@ -1910,12 +1893,12 @@ declare class TapReporter implements Reporter {
1910
1893
  static getComment(task: Task): string;
1911
1894
  private logErrorDetails;
1912
1895
  protected logTasks(tasks: Task[]): void;
1913
- onFinished(files?: File[]): void;
1896
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>): void;
1914
1897
  }
1915
1898
 
1916
1899
  declare class TapFlatReporter extends TapReporter {
1917
1900
  onInit(ctx: Vitest): void;
1918
- onFinished(files?: File[]): void;
1901
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>): void;
1919
1902
  }
1920
1903
 
1921
1904
  declare class VerboseReporter extends DefaultReporter {
@@ -1950,7 +1933,7 @@ declare class BenchmarkReporter extends DefaultReporter {
1950
1933
  onTestSuiteResult(testSuite: TestSuite): void;
1951
1934
  protected printTestModule(testModule: TestModule): void;
1952
1935
  private printSuiteTable;
1953
- onFinished(files?: File[], errors?: unknown[]): Promise<void>;
1936
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>, reason: TestRunEndReason): Promise<void>;
1954
1937
  }
1955
1938
 
1956
1939
  declare class VerboseBenchmarkReporter extends BenchmarkReporter {
@@ -2,39 +2,22 @@ import fs from 'node:fs';
2
2
 
3
3
  const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
4
4
  function normalizeWindowsPath(input = "") {
5
- if (!input) return input;
6
- return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
5
+ return input && input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
7
6
  }
8
- const _UNC_REGEX = /^[/\\]{2}/;
9
- const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
10
- const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
11
- const normalize = function(path) {
7
+ const _UNC_REGEX = /^[/\\]{2}/, _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/, _DRIVE_LETTER_RE = /^[A-Za-z]:$/, normalize = function(path) {
12
8
  if (path.length === 0) return ".";
13
9
  path = normalizeWindowsPath(path);
14
- const isUNCPath = path.match(_UNC_REGEX);
15
- const isPathAbsolute = isAbsolute(path);
16
- const trailingSeparator = path[path.length - 1] === "/";
17
- path = normalizeString(path, !isPathAbsolute);
18
- if (path.length === 0) {
19
- if (isPathAbsolute) return "/";
20
- return trailingSeparator ? "./" : ".";
21
- }
10
+ const isUNCPath = path.match(_UNC_REGEX), isPathAbsolute = isAbsolute(path), trailingSeparator = path[path.length - 1] === "/";
11
+ if (path = normalizeString(path, !isPathAbsolute), path.length === 0) return isPathAbsolute ? "/" : trailingSeparator ? "./" : ".";
22
12
  if (trailingSeparator) path += "/";
23
13
  if (_DRIVE_LETTER_RE.test(path)) path += "/";
24
- if (isUNCPath) {
25
- if (!isPathAbsolute) return `//./${path}`;
26
- return `//${path}`;
27
- }
28
- return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
29
- };
30
- const join = function(...segments) {
14
+ return isUNCPath ? isPathAbsolute ? `//${path}` : `//./${path}` : isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
15
+ }, join = function(...segments) {
31
16
  let path = "";
32
17
  for (const seg of segments) {
33
18
  if (!seg) continue;
34
19
  if (path.length > 0) {
35
- const pathTrailing = path[path.length - 1] === "/";
36
- const segLeading = seg[0] === "/";
37
- const both = pathTrailing && segLeading;
20
+ const pathTrailing = path[path.length - 1] === "/", segLeading = seg[0] === "/", both = pathTrailing && segLeading;
38
21
  if (both) path += seg.slice(1);
39
22
  else path += pathTrailing || segLeading ? seg : `/${seg}`;
40
23
  } else path += seg;
@@ -42,11 +25,7 @@ const join = function(...segments) {
42
25
  return normalize(path);
43
26
  };
44
27
  function normalizeString(path, allowAboveRoot) {
45
- let res = "";
46
- let lastSegmentLength = 0;
47
- let lastSlash = -1;
48
- let dots = 0;
49
- let char = null;
28
+ let res = "", lastSegmentLength = 0, lastSlash = -1, dots = 0, char = null;
50
29
  for (let index = 0; index <= path.length; ++index) {
51
30
  if (index < path.length) char = path[index];
52
31
  else if (char === "/") break;
@@ -57,35 +36,22 @@ function normalizeString(path, allowAboveRoot) {
57
36
  if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
58
37
  if (res.length > 2) {
59
38
  const lastSlashIndex = res.lastIndexOf("/");
60
- if (lastSlashIndex === -1) {
61
- res = "";
62
- lastSegmentLength = 0;
63
- } else {
64
- res = res.slice(0, lastSlashIndex);
65
- lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
66
- }
67
- lastSlash = index;
68
- dots = 0;
39
+ if (lastSlashIndex === -1) res = "", lastSegmentLength = 0;
40
+ else res = res.slice(0, lastSlashIndex), lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
41
+ lastSlash = index, dots = 0;
69
42
  continue;
70
43
  } else if (res.length > 0) {
71
- res = "";
72
- lastSegmentLength = 0;
73
- lastSlash = index;
74
- dots = 0;
44
+ res = "", lastSegmentLength = 0, lastSlash = index, dots = 0;
75
45
  continue;
76
46
  }
77
47
  }
78
- if (allowAboveRoot) {
79
- res += res.length > 0 ? "/.." : "..";
80
- lastSegmentLength = 2;
81
- }
48
+ if (allowAboveRoot) res += res.length > 0 ? "/.." : "..", lastSegmentLength = 2;
82
49
  } else {
83
50
  if (res.length > 0) res += `/${path.slice(lastSlash + 1, index)}`;
84
51
  else res = path.slice(lastSlash + 1, index);
85
52
  lastSegmentLength = index - lastSlash - 1;
86
53
  }
87
- lastSlash = index;
88
- dots = 0;
54
+ lastSlash = index, dots = 0;
89
55
  } else if (char === "." && dots !== -1) ++dots;
90
56
  else dots = -1;
91
57
  }
@@ -93,8 +59,7 @@ function normalizeString(path, allowAboveRoot) {
93
59
  }
94
60
  const isAbsolute = function(p) {
95
61
  return _IS_ABSOLUTE_RE.test(p);
96
- };
97
- const dirname = function(p) {
62
+ }, dirname = function(p) {
98
63
  const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
99
64
  if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) segments[0] += "/";
100
65
  return segments.join("/") || (isAbsolute(p) ? "/" : ".");
@@ -120,8 +85,7 @@ function findNearestPackageData(basedir) {
120
85
  return {};
121
86
  }
122
87
  function stripBomTag(content) {
123
- if (content.charCodeAt(0) === 65279) return content.slice(1);
124
- return content;
88
+ return content.charCodeAt(0) === 65279 ? content.slice(1) : content;
125
89
  }
126
90
  function tryStatSync(file) {
127
91
  try {
@@ -131,16 +95,12 @@ function tryStatSync(file) {
131
95
  }
132
96
  function getCachedData(cache, basedir, originalBasedir) {
133
97
  const pkgData = cache.get(getFnpdCacheKey(basedir));
134
- if (pkgData) {
135
- traverseBetweenDirs(originalBasedir, basedir, (dir) => {
136
- cache.set(getFnpdCacheKey(dir), pkgData);
137
- });
138
- return pkgData;
139
- }
98
+ if (pkgData) return traverseBetweenDirs(originalBasedir, basedir, (dir) => {
99
+ cache.set(getFnpdCacheKey(dir), pkgData);
100
+ }), pkgData;
140
101
  }
141
102
  function setCacheData(cache, data, basedir, originalBasedir) {
142
- cache.set(getFnpdCacheKey(basedir), data);
143
- traverseBetweenDirs(originalBasedir, basedir, (dir) => {
103
+ cache.set(getFnpdCacheKey(basedir), data), traverseBetweenDirs(originalBasedir, basedir, (dir) => {
144
104
  cache.set(getFnpdCacheKey(dir), data);
145
105
  });
146
106
  }
@@ -153,10 +113,7 @@ function getFnpdCacheKey(basedir) {
153
113
  * @param shorterDir Shorter dir path, e.g. `/User/foo`
154
114
  */
155
115
  function traverseBetweenDirs(longerDir, shorterDir, cb) {
156
- while (longerDir !== shorterDir) {
157
- cb(longerDir);
158
- longerDir = dirname(longerDir);
159
- }
116
+ while (longerDir !== shorterDir) cb(longerDir), longerDir = dirname(longerDir);
160
117
  }
161
118
 
162
119
  export { findNearestPackageData as f };
@@ -1,29 +1,18 @@
1
1
  import { getSafeTimers } from '@vitest/utils';
2
2
  import { c as createBirpc } from './index.Bgo3tNWt.js';
3
- import { g as getWorkerState } from './utils.B9FY3b73.js';
3
+ import { g as getWorkerState } from './utils.C7__0Iv5.js';
4
4
 
5
5
  const { get } = Reflect;
6
6
  function withSafeTimers(fn) {
7
- const { setTimeout, clearTimeout, nextTick, setImmediate, clearImmediate } = getSafeTimers();
8
- const currentSetTimeout = globalThis.setTimeout;
9
- const currentClearTimeout = globalThis.clearTimeout;
10
- const currentSetImmediate = globalThis.setImmediate;
11
- const currentClearImmediate = globalThis.clearImmediate;
12
- const currentNextTick = globalThis.process?.nextTick;
7
+ const { setTimeout, clearTimeout, nextTick, setImmediate, clearImmediate } = getSafeTimers(), currentSetTimeout = globalThis.setTimeout, currentClearTimeout = globalThis.clearTimeout, currentSetImmediate = globalThis.setImmediate, currentClearImmediate = globalThis.clearImmediate, currentNextTick = globalThis.process?.nextTick;
13
8
  try {
14
- globalThis.setTimeout = setTimeout;
15
- globalThis.clearTimeout = clearTimeout;
16
- if (setImmediate) globalThis.setImmediate = setImmediate;
9
+ if (globalThis.setTimeout = setTimeout, globalThis.clearTimeout = clearTimeout, setImmediate) globalThis.setImmediate = setImmediate;
17
10
  if (clearImmediate) globalThis.clearImmediate = clearImmediate;
18
11
  if (globalThis.process && nextTick) globalThis.process.nextTick = nextTick;
19
12
  const result = fn();
20
13
  return result;
21
14
  } finally {
22
- globalThis.setTimeout = currentSetTimeout;
23
- globalThis.clearTimeout = currentClearTimeout;
24
- globalThis.setImmediate = currentSetImmediate;
25
- globalThis.clearImmediate = currentClearImmediate;
26
- if (globalThis.process && nextTick) nextTick(() => {
15
+ if (globalThis.setTimeout = currentSetTimeout, globalThis.clearTimeout = currentClearTimeout, globalThis.setImmediate = currentSetImmediate, globalThis.clearImmediate = currentClearImmediate, globalThis.process && nextTick) nextTick(() => {
27
16
  globalThis.process.nextTick = currentNextTick;
28
17
  });
29
18
  }
@@ -38,8 +27,7 @@ function createRuntimeRpc(options) {
38
27
  let setCancel = (_reason) => {};
39
28
  const onCancel = new Promise((resolve) => {
40
29
  setCancel = resolve;
41
- });
42
- const rpc = createSafeRpc(createBirpc({ onCancel: setCancel }, {
30
+ }), rpc = createSafeRpc(createBirpc({ onCancel: setCancel }, {
43
31
  eventNames: [
44
32
  "onUserConsoleLog",
45
33
  "onCollected",
@@ -57,8 +45,7 @@ function createSafeRpc(rpc) {
57
45
  return new Proxy(rpc, { get(target, p, handler) {
58
46
  // keep $rejectPendingCalls as sync function
59
47
  if (p === "$rejectPendingCalls") return rpc.$rejectPendingCalls;
60
- const sendCall = get(target, p, handler);
61
- const safeSendCall = (...args) => withSafeTimers(async () => {
48
+ const sendCall = get(target, p, handler), safeSendCall = (...args) => withSafeTimers(async () => {
62
49
  const result = sendCall(...args);
63
50
  promises.add(result);
64
51
  try {
@@ -67,8 +54,7 @@ function createSafeRpc(rpc) {
67
54
  promises.delete(result);
68
55
  }
69
56
  });
70
- safeSendCall.asEvent = sendCall.asEvent;
71
- return safeSendCall;
57
+ return safeSendCall.asEvent = sendCall.asEvent, safeSendCall;
72
58
  } });
73
59
  }
74
60
  function rpc() {
@@ -1,21 +1,21 @@
1
1
  import { performance } from 'node:perf_hooks';
2
2
  import { startTests, collectTests } from '@vitest/runner';
3
- import { a as resolveSnapshotEnvironment, s as setupChaiConfig, r as resolveTestRunner } from './index.oWRWx-nj.js';
4
- import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './setup-common.lgPs-bYv.js';
5
- import { a as globalExpect, v as vi } from './vi.DGAfBY4R.js';
6
- import { c as closeInspector } from './inspector.C914Efll.js';
3
+ import { a as resolveSnapshotEnvironment, s as setupChaiConfig, r as resolveTestRunner } from './index.CsFXYRkW.js';
4
+ import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './setup-common.hLGRxhC8.js';
5
+ import { a as globalExpect, v as vi } from './vi.BfdOiD4j.js';
6
+ import { c as closeInspector } from './inspector.CvQD-Nie.js';
7
7
  import { createRequire } from 'node:module';
8
8
  import timers from 'node:timers';
9
9
  import timersPromises from 'node:timers/promises';
10
10
  import util from 'node:util';
11
11
  import { KNOWN_ASSET_TYPES, getSafeTimers } from '@vitest/utils';
12
- import { V as VitestIndex } from './index.QZr3S3vQ.js';
13
- import { g as getWorkerState, r as resetModules } from './utils.B9FY3b73.js';
12
+ import { V as VitestIndex } from './index.AR8aAkCC.js';
13
+ import { g as getWorkerState, r as resetModules } from './utils.C7__0Iv5.js';
14
14
  import 'chai';
15
15
  import 'node:path';
16
16
  import '../path.js';
17
17
  import 'node:url';
18
- import './rpc.DGoW_Vl-.js';
18
+ import './rpc.RpPylpp0.js';
19
19
  import './index.Bgo3tNWt.js';
20
20
  import './coverage.D_JHT54q.js';
21
21
  import '@vitest/snapshot';
@@ -25,16 +25,15 @@ import './_commonjsHelpers.BFTU3MAI.js';
25
25
  import '@vitest/utils/error';
26
26
  import '@vitest/spy';
27
27
  import '@vitest/utils/source-map';
28
- import './date.Bq6ZW5rf.js';
29
- import './benchmark.CtuRzf-i.js';
28
+ import './date.-jtEtIeV.js';
29
+ import './benchmark.UW6Ezvxy.js';
30
30
  import 'expect-type';
31
31
  import 'vite/module-runner';
32
32
 
33
33
  // this should only be used in Node
34
34
  let globalSetup = false;
35
35
  async function setupGlobalEnv(config, { environment }, moduleRunner) {
36
- await setupCommonEnv(config);
37
- Object.defineProperty(globalThis, "__vitest_index__", {
36
+ await setupCommonEnv(config), Object.defineProperty(globalThis, "__vitest_index__", {
38
37
  value: VitestIndex,
39
38
  enumerable: false
40
39
  });
@@ -45,24 +44,15 @@ async function setupGlobalEnv(config, { environment }, moduleRunner) {
45
44
  const viteEnvironment = environment.viteEnvironment || environment.name;
46
45
  if (viteEnvironment === "client") {
47
46
  const _require = createRequire(import.meta.url);
48
- // always mock "required" `css` files, because we cannot process them
49
- _require.extensions[".css"] = resolveCss;
50
- _require.extensions[".scss"] = resolveCss;
51
- _require.extensions[".sass"] = resolveCss;
52
- _require.extensions[".less"] = resolveCss;
53
- // since we are using Vite, we can assume how these will be resolved
54
- KNOWN_ASSET_TYPES.forEach((type) => {
47
+ _require.extensions[".css"] = resolveCss, _require.extensions[".scss"] = resolveCss, _require.extensions[".sass"] = resolveCss, _require.extensions[".less"] = resolveCss, KNOWN_ASSET_TYPES.forEach((type) => {
55
48
  _require.extensions[`.${type}`] = resolveAsset;
56
- });
57
- process.env.SSR = "";
49
+ }), process.env.SSR = "";
58
50
  } else process.env.SSR = "1";
59
- // @ts-expect-error not typed global for patched timers
60
- globalThis.__vitest_required__ = {
51
+ if (globalThis.__vitest_required__ = {
61
52
  util,
62
53
  timers,
63
54
  timersPromises
64
- };
65
- if (!config.disableConsoleIntercept) await setupConsoleLogSpy();
55
+ }, !config.disableConsoleIntercept) await setupConsoleLogSpy();
66
56
  }
67
57
  function resolveCss(mod) {
68
58
  mod.exports = "";
@@ -71,58 +61,39 @@ function resolveAsset(mod, url) {
71
61
  mod.exports = url;
72
62
  }
73
63
  async function setupConsoleLogSpy() {
74
- const { createCustomConsole } = await import('./console.Duv2dVIC.js');
64
+ const { createCustomConsole } = await import('./console.B0quX7yH.js');
75
65
  globalThis.console = createCustomConsole();
76
66
  }
77
67
  async function withEnv({ environment }, options, fn) {
78
- // @ts-expect-error untyped global
79
- globalThis.__vitest_environment__ = environment.name;
80
- globalExpect.setState({ environment: environment.name });
68
+ globalThis.__vitest_environment__ = environment.name, globalExpect.setState({ environment: environment.name });
81
69
  const env = await environment.setup(globalThis, options);
82
70
  try {
83
71
  await fn();
84
72
  } finally {
85
73
  // Run possible setTimeouts, e.g. the onces used by ConsoleLogSpy
86
74
  const { setTimeout } = getSafeTimers();
87
- await new Promise((resolve) => setTimeout(resolve));
88
- await env.teardown(globalThis);
75
+ await new Promise((resolve) => setTimeout(resolve)), await env.teardown(globalThis);
89
76
  }
90
77
  }
91
78
 
92
79
  // browser shouldn't call this!
93
80
  async function run(method, files, config, environment, moduleRunner) {
94
- const workerState = getWorkerState();
95
- const isIsolatedThreads = config.pool === "threads" && (config.poolOptions?.threads?.isolate ?? true);
96
- const isIsolatedForks = config.pool === "forks" && (config.poolOptions?.forks?.isolate ?? true);
97
- const isolate = isIsolatedThreads || isIsolatedForks;
98
- await setupGlobalEnv(config, environment, moduleRunner);
99
- await startCoverageInsideWorker(config.coverage, moduleRunner, { isolate });
100
- if (config.chaiConfig) setupChaiConfig(config.chaiConfig);
81
+ const workerState = getWorkerState(), isIsolatedThreads = config.pool === "threads" && (config.poolOptions?.threads?.isolate ?? true), isIsolatedForks = config.pool === "forks" && (config.poolOptions?.forks?.isolate ?? true), isolate = isIsolatedThreads || isIsolatedForks;
82
+ if (await setupGlobalEnv(config, environment, moduleRunner), await startCoverageInsideWorker(config.coverage, moduleRunner, { isolate }), config.chaiConfig) setupChaiConfig(config.chaiConfig);
101
83
  const runner = await resolveTestRunner(config, moduleRunner);
102
84
  workerState.onCancel.then((reason) => {
103
- closeInspector(config);
104
- runner.cancel?.(reason);
105
- });
106
- workerState.durations.prepare = performance.now() - workerState.durations.prepare;
107
- workerState.durations.environment = performance.now();
108
- await withEnv(environment, environment.options || config.environmentOptions || {}, async () => {
85
+ closeInspector(config), runner.cancel?.(reason);
86
+ }), workerState.durations.prepare = performance.now() - workerState.durations.prepare, workerState.durations.environment = performance.now(), await withEnv(environment, environment.options || config.environmentOptions || {}, async () => {
109
87
  workerState.durations.environment = performance.now() - workerState.durations.environment;
110
88
  for (const file of files) {
111
- if (isolate) {
112
- moduleRunner.mocker.reset();
113
- resetModules(workerState.evaluatedModules, true);
114
- }
115
- workerState.filepath = file.filepath;
116
- if (method === "run") await startTests([file], runner);
89
+ if (isolate) moduleRunner.mocker.reset(), resetModules(workerState.evaluatedModules, true);
90
+ if (workerState.filepath = file.filepath, method === "run") await startTests([file], runner);
117
91
  else await collectTests([file], runner);
118
- // reset after tests, because user might call `vi.setConfig` in setupFile
119
- vi.resetConfig();
120
92
  // mocks should not affect different files
121
- vi.restoreAllMocks();
93
+ vi.resetConfig(), vi.restoreAllMocks();
122
94
  }
123
95
  await stopCoverageInsideWorker(config.coverage, moduleRunner, { isolate });
124
- });
125
- workerState.environmentTeardownRun = true;
96
+ }), workerState.environmentTeardownRun = true;
126
97
  }
127
98
 
128
99
  export { run };