vitest 5.1.0-beta.1 → 5.1.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 (58) hide show
  1. package/dist/browser.d.ts +6 -5
  2. package/dist/browser.js +6 -6
  3. package/dist/chunks/{base.PJyN9N0u.js → base.Cof-UHJf.js} +14 -19
  4. package/dist/chunks/{browser.d.D7a15z82.d.ts → browser.d.C7tWgUvw.d.ts} +3 -3
  5. package/dist/chunks/{cac.Ccf5Je_F.js → cac.BYbt0aJp.js} +22 -20
  6. package/dist/chunks/{cli-api.DE22LIzq.js → cli-api.COfZo8lK.js} +714 -73
  7. package/dist/chunks/{config.d.BgktgHfG.d.ts → config.d.B3YV4t0O.d.ts} +37 -2
  8. package/dist/chunks/{console.DrMPSuFo.js → console.CQZ877Hi.js} +2 -2
  9. package/dist/chunks/{coverage.-bm5IxnW.js → coverage.9iqXE2gN.js} +1 -1
  10. package/dist/chunks/{coverage.cTDc4uSS.js → coverage.jGCktcGP.js} +1 -1
  11. package/dist/chunks/{creator.BQ3onxbh.js → creator.DHWmytIK.js} +10 -10
  12. package/dist/chunks/{doctor.CPlMs7-y.js → doctor.B-oPbwps.js} +2 -2
  13. package/dist/chunks/{environment.d.CbTLsZSj.d.ts → environment.d.BFQtFKdZ.d.ts} +1 -1
  14. package/dist/chunks/{globals.TipXUFcZ.js → globals.ZKtKSkEf.js} +6 -5
  15. package/dist/chunks/{index.BFXLpwll.js → index.Bi0NXYPf.js} +58 -32
  16. package/dist/chunks/{index.BXttT2gP.js → index.CZzC1gGg.js} +265 -425
  17. package/dist/chunks/{index.D14IAvnE.js → index.Di8au7q4.js} +68 -62
  18. package/dist/chunks/{index.B03wg4V0.js → index.w_oBZ9N8.js} +5 -5
  19. package/dist/chunks/{init-forks.BL1E3__4.js → init-forks.BaDXQSD8.js} +1 -1
  20. package/dist/chunks/{init-threads.CYXAGzKQ.js → init-threads.ZX_Vov0z.js} +1 -1
  21. package/dist/chunks/{init.DVorxUyL.js → init.CO4AB7HZ.js} +4 -4
  22. package/dist/chunks/{module-dependencies.CwNPkcV4.js → module-dependencies._2Eei3FO.js} +1 -1
  23. package/dist/chunks/{native.cdzHIdmv.js → native.upB-V0CK.js} +1 -1
  24. package/dist/chunks/{nativeModuleMocker.3uBcOd84.js → nativeModuleMocker.Dh5azSB4.js} +3 -3
  25. package/dist/chunks/{nativeModuleRunner.xi64Afb2.js → nativeModuleRunner.9xPIMzi7.js} +1 -1
  26. package/dist/chunks/{node.uQulW0ei.js → node.B9mkVmLH.js} +1 -1
  27. package/dist/chunks/{pathe.M-eThtNZ.Ba-7h1rE.js → pathe.M-eThtNZ.zq3TM4NT.js} +1 -1
  28. package/dist/chunks/{plugin.d.olEn8IL9.d.ts → plugin.d.LRFSN46m.d.ts} +90 -19
  29. package/dist/chunks/rawSnapshot.DqSiqIEx.js +356 -0
  30. package/dist/chunks/{resolver.CtCcxIy1.js → resolver.BzpmeQeT.js} +1 -1
  31. package/dist/chunks/{rpc.BV0XpJ5q.js → rpc.Uhkwr2NM.js} +2 -2
  32. package/dist/chunks/{rpc.d.DGFP7vWr.d.ts → rpc.d.3FOhdFx8.d.ts} +1 -1
  33. package/dist/chunks/{run.BfrMbGVD.js → run.CjdgFZiW.js} +7 -4
  34. package/dist/chunks/{setup-common.llxJkJaD.js → setup-common.CqAQCXzx.js} +2 -2
  35. package/dist/chunks/{source-map.BjWcsIL9.js → source-map.DakdQc29.js} +11 -13
  36. package/dist/chunks/{source-map.d.C5A_Tr6V.d.ts → source-map.d.BkG8YK_3.d.ts} +1 -1
  37. package/dist/chunks/{task-utils.d.BUh7ylUT.d.ts → task-utils.d.D-gFPNFi.d.ts} +1 -1
  38. package/dist/chunks/{utils.DSfl_w8V.js → utils.BBk_icFG.js} +6 -3
  39. package/dist/chunks/{vm.Cwj01UFE.js → vm.b4MbCAJQ.js} +15 -13
  40. package/dist/chunks/{worker.d.gsA26mmR.d.ts → worker.d.CyJRpyfZ.d.ts} +3 -3
  41. package/dist/cli.js +2 -2
  42. package/dist/config.d.ts +8 -8
  43. package/dist/index.d.ts +17 -12
  44. package/dist/index.js +6 -5
  45. package/dist/module-evaluator.d.ts +2 -2
  46. package/dist/node.d.ts +10 -10
  47. package/dist/node.js +15 -13
  48. package/dist/runtime.d.ts +4 -4
  49. package/dist/runtime.js +4 -4
  50. package/dist/task-utils.js +7 -3
  51. package/dist/worker.d.ts +4 -4
  52. package/dist/worker.js +14 -13
  53. package/dist/workers/forks.js +15 -14
  54. package/dist/workers/runVmTests.js +13 -10
  55. package/dist/workers/threads.js +15 -14
  56. package/dist/workers/vmForks.js +10 -10
  57. package/dist/workers/vmThreads.js +10 -10
  58. package/package.json +15 -15
@@ -1,13 +1,13 @@
1
- import { DevEnvironment, IndexHtmlTransformContext, IndexHtmlTransformResult, ViteDevServer, UserConfig as UserConfig$1, Plugin, ResolvedConfig as ResolvedConfig$1, TransformResult as TransformResult$1, InlineConfig as InlineConfig$1, DepOptimizationConfig, ServerOptions, ConfigEnv, AliasOptions } from 'vite';
2
- import { aW as TaskMeta, U as UserConsoleLog, Q as Suite, a as File, bk as SerializableRetry, T as TestError, h as TestAnnotation, j as TestArtifact, b2 as TestBenchmark, aL as SerializedError, a1 as ImportDuration, n as Test, A as Awaitable, Z as CancelReason, P as ParsedStack, bl as BrowserTraceViewMode, a6 as BaselineData, p as ProvidedContext, b as SerializedConfig, bm as Arrayable, a3 as AfterSuiteRunMeta, aQ as SnapshotStateOptions, aR as SnapshotSummary, aO as SnapshotResult, Y as Task, bn as AsyncLeak, k as TaskResultPack, F as FileSpecification, m as SerializedRootConfig, L as LabelColor, c as SerializedDiffOptions, bi as SequenceSetupFiles, bh as SequenceHooks, bo as PrettyFormatOptions, e as FakeTimersConfig, g as TestTagDefinition } from './config.d.BgktgHfG.js';
1
+ import { DevEnvironment, IndexHtmlTransformContext, IndexHtmlTransformResult, ViteDevServer, UserConfig as UserConfig$1, Plugin, ResolvedConfig as ResolvedConfig$1, ESTree, TransformResult as TransformResult$1, InlineConfig as InlineConfig$1, DepOptimizationConfig, ServerOptions, ConfigEnv, AliasOptions } from 'vite';
2
+ import { aW as TaskMeta, U as UserConsoleLog, Q as Suite, a as File, bk as SerializableRetry, T as TestError, h as TestAnnotation, j as TestArtifact, b2 as TestBenchmark, aL as SerializedError, a1 as ImportDuration, n as Test, A as Awaitable, Z as CancelReason, P as ParsedStack, bl as BrowserTraceViewMode, bm as BrowserTraceViewRecordingMode, a6 as BaselineData, p as ProvidedContext, b as SerializedConfig, bn as Arrayable, a3 as AfterSuiteRunMeta, aQ as SnapshotStateOptions, aR as SnapshotSummary, aO as SnapshotResult, Y as Task, bo as AsyncLeak, k as TaskResultPack, F as FileSpecification, m as SerializedRootConfig, L as LabelColor, c as SerializedDiffOptions, bi as SequenceSetupFiles, bh as SequenceHooks, bp as PrettyFormatOptions, e as FakeTimersConfig, g as TestTagDefinition } from './config.d.B3YV4t0O.js';
3
3
  import { Writable } from 'node:stream';
4
- import { S as SerializedTestSpecification, B as BrowserTesterOptions, c as SourceModuleDiagnostic } from './browser.d.D7a15z82.js';
4
+ import { S as SerializedTestSpecification, B as BrowserTesterOptions, c as SourceModuleDiagnostic } from './browser.d.C7tWgUvw.js';
5
5
  import * as chai from 'chai';
6
6
  import { happyDomTypes, jsdomTypes } from 'vitest/optional-types.js';
7
- import { a as ContextTestEnvironment, b as WorkerExecuteContext, c as WorkerTestEnvironment } from './worker.d.gsA26mmR.js';
8
- import { O as OTELCarrier } from './rpc.d.DGFP7vWr.js';
7
+ import { a as ContextTestEnvironment, b as WorkerExecuteContext, c as WorkerTestEnvironment } from './worker.d.CyJRpyfZ.js';
8
+ import { O as OTELCarrier } from './rpc.d.3FOhdFx8.js';
9
9
  import { MockedModule } from '@vitest/mocker';
10
- import { S as StackTraceParserOptions, a as RuntimeCoverageProviderModule } from './source-map.d.C5A_Tr6V.js';
10
+ import { S as StackTraceParserOptions, a as RuntimeCoverageProviderModule } from './source-map.d.BkG8YK_3.js';
11
11
  import { CDPSession, BrowserCommands, MarkOptions } from 'vitest/browser';
12
12
  import path from 'node:path';
13
13
  import { Console } from 'node:console';
@@ -571,13 +571,22 @@ type BrowserBuiltinProvider = "webdriverio" | "playwright" | "preview";
571
571
  interface _BrowserNames {}
572
572
  interface BrowserTraceViewOptions {
573
573
  /**
574
- * Enable Vitest trace view artifacts collection.
574
+ * @deprecated Use `mode` instead. `true` is the same as `mode: 'on'`.
575
+ */
576
+ enabled?: boolean;
577
+ /**
578
+ * How trace view records tests.
575
579
  *
576
- * This option controls Vitest's own trace-view pipeline, independently from provider-specific trace retention.
580
+ * - `'on'`: every test gets a trace with a snapshot at every step, and Vitest UI shows steps live as tests run.
581
+ * - `'failure-only'`: only failed tests get a trace, with the full step timeline and a snapshot at the end.
582
+ * - `'off'`: no traces.
577
583
  *
578
- * @default false
584
+ * Takes precedence over `enabled`.
585
+ *
586
+ * @default 'failure-only'
587
+ * @experimental
579
588
  */
580
- enabled?: boolean;
589
+ mode?: BrowserTraceViewRecordingMode;
581
590
  /**
582
591
  * Capture canvas pixels in trace view snapshots.
583
592
  *
@@ -599,7 +608,7 @@ interface BrowserTraceViewOptions {
599
608
  /**
600
609
  * Capture the accessibility tree alongside each trace view snapshot.
601
610
  *
602
- * The trace viewer can switch from the DOM snapshot to an "Aria" view.
611
+ * The trace viewer's snapshot pane can then switch between "DOM" and "Aria" views.
603
612
  *
604
613
  * @default true
605
614
  * @experimental
@@ -722,14 +731,16 @@ interface BrowserConfigOptions {
722
731
  snapshots?: boolean;
723
732
  };
724
733
  /**
734
+ * Records the actions, assertions, and marks of browser tests with DOM snapshots for the trace viewer.
725
735
  *
726
- * Enable Vitest trace view artifacts collection.
727
- *
728
- * This option controls Vitest's own trace-view pipeline, independently from provider-specific trace retention.
736
+ * - `'failure-only'`: records only failed tests.
737
+ * - `true` or `'on'`: records every test.
738
+ * - `false` or `'off'`: turns trace view off.
729
739
  *
730
- * @default false
740
+ * @default 'failure-only'
741
+ * @see {@link https://vitest.dev/guide/browser/trace-view}
731
742
  */
732
- traceView?: boolean | BrowserTraceViewOptions;
743
+ traceView?: boolean | BrowserTraceViewRecordingMode | BrowserTraceViewOptions;
733
744
  /**
734
745
  * Directory where screenshots will be saved when page.screenshot() is called
735
746
  * If not set, all screenshots are saved to __screenshots__ directory in the same folder as the test file.
@@ -1155,7 +1166,6 @@ declare class TestProject {
1155
1166
  * Test if a file matches the test globs. This does the actual glob matching if the test is not cached, unlike `isCachedTestFile`.
1156
1167
  */
1157
1168
  matchesTestGlob(moduleId: string, source?: () => string): boolean;
1158
- private filterFiles;
1159
1169
  /**
1160
1170
  * Closes the project and all associated resources. This can only be called once; the closing promise is cached until the server restarts.
1161
1171
  * If the resources are needed again, create a new project.
@@ -1699,6 +1709,8 @@ interface LinkMapper {
1699
1709
  relativePath(source: ReportNode | string, target: ReportNode | string): string;
1700
1710
  assetPath(node: ReportNode, name: string): string;
1701
1711
  }
1712
+ /** color themes of the html report, `legacy` being the classic istanbul colors */
1713
+ type HtmlTheme = "light" | "dark" | "legacy";
1702
1714
  /** options accepted by {@link HtmlReport} */
1703
1715
  interface HtmlOptions {
1704
1716
  /** show extra logging while the report is generated */
@@ -1709,11 +1721,17 @@ interface HtmlOptions {
1709
1721
  subdir?: string;
1710
1722
  /** skip nodes with no coverage */
1711
1723
  skipEmpty?: boolean;
1724
+ /**
1725
+ * fixes the report's theme and hides the theme picker; when unset, viewers
1726
+ * pick a theme in the report, which otherwise follows their light/dark
1727
+ * preference, or the page embedding the report, like Vitest UI
1728
+ */
1729
+ theme?: HtmlTheme;
1712
1730
  }
1713
1731
 
1714
1732
  //#region src/reports/html-spa/index.d.ts
1715
1733
  /** options accepted by {@link HtmlSpaReport} */
1716
- interface HtmlSpaOptions extends HtmlOptions {
1734
+ interface HtmlSpaOptions extends Omit<HtmlOptions, "theme"> {
1717
1735
  /** the metrics to show in the report UI, defaults to lines, branches and functions */
1718
1736
  metricsToShow?: ("lines" | "branches" | "functions" | "statements")[];
1719
1737
  }
@@ -1828,6 +1846,24 @@ interface CoverageProvider {
1828
1846
  * @experimental
1829
1847
  */
1830
1848
  requiresTransform?: (id: string) => boolean;
1849
+ /**
1850
+ * Version of the coverage provider. Can be used as cache key in various caching mechanisms.
1851
+ * @experimental
1852
+ */
1853
+ version?: string;
1854
+ /**
1855
+ * Return data that should be stored with the transformed module in `fsModuleCache`,
1856
+ * e.g. data collected in `onFileTransform`. The data must be JSON serializable.
1857
+ * When the module is later loaded from `fsModuleCache`, `onFileTransform` is not called.
1858
+ * The data is passed to `restoreModuleCacheData` instead.
1859
+ * @experimental
1860
+ */
1861
+ getModuleCacheData?: (environment: DevEnvironment, id: string) => unknown;
1862
+ /**
1863
+ * Called with the data returned by `getModuleCacheData` when the module is loaded from `fsModuleCache`.
1864
+ * @experimental
1865
+ */
1866
+ restoreModuleCacheData?: (environment: DevEnvironment, id: string, data: unknown) => void;
1831
1867
  /** Callback that's called when the coverage is enabled via a programmatic `enableCoverage` API. */
1832
1868
  onEnabled?: () => void | Promise<void>;
1833
1869
  }
@@ -1984,6 +2020,18 @@ interface CoverageOptions {
1984
2020
  */
1985
2021
  ignoreClassMethods?: string[];
1986
2022
  /**
2023
+ * Filter to ignore code from coverage based on its AST node.
2024
+ * Called only for nodes that Vitest's built-in filters don't already ignore.
2025
+ * Return `'ignore-this-and-nested-nodes'` to also ignore all nodes inside the given node.
2026
+ * Supported only by `v8` provider.
2027
+ *
2028
+ * @example
2029
+ * ```ts
2030
+ * ignoreNode: (node, type) => type === 'statement' && node.type === 'DebuggerStatement'
2031
+ * ```
2032
+ */
2033
+ ignoreNode?: (node: ESTree.Node, type: "function" | "statement" | "branch") => boolean | "ignore-this-and-nested-nodes" | void;
2034
+ /**
1987
2035
  * Custom instrumenter factory to use instead of the default `@vitest/istanbul-lib-instrument`.
1988
2036
  *
1989
2037
  * The factory receives the same runtime coverage options Vitest passes to its
@@ -2342,6 +2390,12 @@ declare class StateManager {
2342
2390
  cancelFiles(files: FileSpecification[], project: TestProject): void;
2343
2391
  }
2344
2392
 
2393
+ type EventName = "add" | "addDir" | "change" | "unlink" | "unlinkDir";
2394
+ type TrackEventName = EventName | "any";
2395
+ type Track = (filepath: string, options?: {
2396
+ timeout?: number;
2397
+ type?: TrackEventName;
2398
+ }) => Promise<void>;
2345
2399
  declare class VitestWatcher {
2346
2400
  private vitest;
2347
2401
  /**
@@ -2353,6 +2407,7 @@ declare class VitestWatcher {
2353
2407
  */
2354
2408
  readonly changedTests: Set<string>;
2355
2409
  private readonly _onRerun;
2410
+ private trackers;
2356
2411
  constructor(vitest: Vitest);
2357
2412
  close(): void;
2358
2413
  unregisterWatcher: () => void;
@@ -2367,6 +2422,13 @@ declare class VitestWatcher {
2367
2422
  * @returns A value indicating whether rerun is needed (changedTests was mutated)
2368
2423
  */
2369
2424
  private handleFileChanged;
2425
+ createTracker(): {
2426
+ track: Track;
2427
+ stop: () => void;
2428
+ };
2429
+ private track;
2430
+ private handleTrackEvent;
2431
+ private resolveTrackEvent;
2370
2432
  }
2371
2433
  interface WatcherTriggerPattern {
2372
2434
  pattern: RegExp;
@@ -3591,7 +3653,8 @@ interface DepsOptions {
3591
3653
  */
3592
3654
  interopDefault?: boolean;
3593
3655
  /**
3594
- * A list of directories relative to the config file that should be treated as module directories.
3656
+ * A list of directories that contain dependencies. A file is a dependency if its path includes `/<directory>/`.
3657
+ * `node_modules` is always included.
3595
3658
  *
3596
3659
  * @default ['node_modules']
3597
3660
  */
@@ -4288,6 +4351,14 @@ interface InlineConfig {
4288
4351
  */
4289
4352
  nodeLoader?: boolean;
4290
4353
  /**
4354
+ * Record `expect.poll`, `vi.waitFor`, and `vi.waitUntil` steps of each test and print them as a timeline when the test fails.
4355
+ * Steps of passing tests are dropped without being reported.
4356
+ *
4357
+ * This has no effect in browser mode, which records its steps with `browser.traceView`.
4358
+ * @default false
4359
+ */
4360
+ traceTimeline?: boolean;
4361
+ /**
4291
4362
  * Provider for detecting changed files. Used with the `--changed` flag
4292
4363
  * to determine which files have been modified.
4293
4364
  *
@@ -0,0 +1,356 @@
1
+ import { f as isObject, h as getCallLastIndex } from './pathe.M-eThtNZ.zq3TM4NT.js';
2
+ import { p as positionToOffset, o as offsetToLineNumber, l as lineSplitRE } from './offset.Dy-5Fdfn.js';
3
+ import { g as getDefaultExportFromCjs, f as format } from './index.D0heQG4v.js';
4
+ import { g as getSerializers } from './plugins.DPQHVT0p.js';
5
+
6
+ var naturalCompare$1 = {exports: {}};
7
+
8
+ var hasRequiredNaturalCompare;
9
+
10
+ function requireNaturalCompare () {
11
+ if (hasRequiredNaturalCompare) return naturalCompare$1.exports;
12
+ hasRequiredNaturalCompare = 1;
13
+ /*
14
+ * @version 1.4.0
15
+ * @date 2015-10-26
16
+ * @stability 3 - Stable
17
+ * @author Lauri Rooden (https://github.com/litejs/natural-compare-lite)
18
+ * @license MIT License
19
+ */
20
+
21
+
22
+ var naturalCompare = function(a, b) {
23
+ var i, codeA
24
+ , codeB = 1
25
+ , posA = 0
26
+ , posB = 0
27
+ , alphabet = String.alphabet;
28
+
29
+ function getCode(str, pos, code) {
30
+ if (code) {
31
+ for (i = pos; code = getCode(str, i), code < 76 && code > 65;) ++i;
32
+ return +str.slice(pos - 1, i)
33
+ }
34
+ code = alphabet && alphabet.indexOf(str.charAt(pos));
35
+ return code > -1 ? code + 76 : ((code = str.charCodeAt(pos) || 0), code < 45 || code > 127) ? code
36
+ : code < 46 ? 65 // -
37
+ : code < 48 ? code - 1
38
+ : code < 58 ? code + 18 // 0-9
39
+ : code < 65 ? code - 11
40
+ : code < 91 ? code + 11 // A-Z
41
+ : code < 97 ? code - 37
42
+ : code < 123 ? code + 5 // a-z
43
+ : code - 63
44
+ }
45
+
46
+
47
+ if ((a+="") != (b+="")) for (;codeB;) {
48
+ codeA = getCode(a, posA++);
49
+ codeB = getCode(b, posB++);
50
+
51
+ if (codeA < 76 && codeB < 76 && codeA > 66 && codeB > 66) {
52
+ codeA = getCode(a, posA, posA);
53
+ codeB = getCode(b, posB, posA = i);
54
+ posB = i;
55
+ }
56
+
57
+ if (codeA != codeB) return (codeA < codeB) ? -1 : 1
58
+ }
59
+ return 0
60
+ };
61
+
62
+ try {
63
+ naturalCompare$1.exports = naturalCompare;
64
+ } catch (e) {
65
+ String.naturalCompare = naturalCompare;
66
+ }
67
+ return naturalCompare$1.exports;
68
+ }
69
+
70
+ var naturalCompareExports = requireNaturalCompare();
71
+ var naturalCompare = /*@__PURE__*/getDefaultExportFromCjs(naturalCompareExports);
72
+
73
+ // TODO: rewrite and clean up
74
+ function testNameToKey(testName, count) {
75
+ return `${testName} ${count}`;
76
+ }
77
+ function keyToTestName(key) {
78
+ if (!/ \d+$/.test(key)) throw new Error("Snapshot keys must end with a number.");
79
+ return key.replace(/ \d+$/, "");
80
+ }
81
+ // Evaluate a snapshot file's content into its snapshot key/value pairs.
82
+ function evaluateSnapshotFile(filepath, content) {
83
+ const data = Object.create(null);
84
+ try {
85
+ new Function("exports", content)(data);
86
+ } catch (cause) {
87
+ throw new Error(`Invalid snapshot file, please manually fix or delete it: ${filepath}`, { cause });
88
+ }
89
+ return data;
90
+ }
91
+ // Add extra line breaks at beginning and end of multiline snapshot
92
+ // to make the content easier to read.
93
+ function addExtraLineBreaks(string) {
94
+ return string.includes("\n") ? `\n${string}\n` : string;
95
+ }
96
+ // Remove extra line breaks at beginning and end of multiline snapshot.
97
+ // Instead of trim, which can remove additional newlines or spaces
98
+ // at beginning or end of the content from a custom serializer.
99
+ function removeExtraLineBreaks(string) {
100
+ return string.length > 2 && string[0] === "\n" && string.endsWith("\n") ? string.slice(1, -1) : string;
101
+ }
102
+ // export const removeLinesBeforeExternalMatcherTrap = (stack: string): string => {
103
+ // const lines = stack.split('\n')
104
+ // for (let i = 0; i < lines.length; i += 1) {
105
+ // // It's a function name specified in `packages/expect/src/index.ts`
106
+ // // for external custom matchers.
107
+ // if (lines[i].includes('__EXTERNAL_MATCHER_TRAP__'))
108
+ // return lines.slice(i + 1).join('\n')
109
+ // }
110
+ // return stack
111
+ // }
112
+ const escapeRegex = true;
113
+ const printFunctionName = false;
114
+ function serialize(val, indent = 2, formatOverrides = {}) {
115
+ return normalizeNewlines(format(val, {
116
+ escapeRegex,
117
+ indent,
118
+ plugins: getSerializers(),
119
+ printFunctionName,
120
+ ...formatOverrides
121
+ }));
122
+ }
123
+ function escapeBacktickString(str) {
124
+ // a raw CR inside a template literal is read back as LF
125
+ return str.replace(/`|\\|\$\{/g, "\\$&").replace(/\r/g, "\\r");
126
+ }
127
+ function printBacktickString(str) {
128
+ return `\`${escapeBacktickString(str)}\``;
129
+ }
130
+ function normalizeNewlines(string) {
131
+ return string.replace(/\r\n|\r/g, "\n");
132
+ }
133
+ async function saveSnapshotFile(environment, snapshotData, snapshotPath) {
134
+ const snapshots = Object.keys(snapshotData).sort(naturalCompare).map((key) => `exports[${printBacktickString(key)}] = ${printBacktickString(normalizeNewlines(snapshotData[key]))};`);
135
+ const content = `${environment.getHeader()}\n\n${snapshots.join("\n\n")}\n`;
136
+ const oldContent = await environment.readSnapshotFile(snapshotPath);
137
+ if (oldContent != null && oldContent === content) return;
138
+ await environment.saveSnapshotFile(snapshotPath, content);
139
+ }
140
+ function deepMergeArray(target = [], source = []) {
141
+ const mergedOutput = Array.from(target);
142
+ source.forEach((sourceElement, index) => {
143
+ const targetElement = mergedOutput[index];
144
+ if (Array.isArray(target[index])) mergedOutput[index] = deepMergeArray(target[index], sourceElement);
145
+ else if (isObject(targetElement)) mergedOutput[index] = deepMergeSnapshot(target[index], sourceElement);
146
+ else
147
+ // Source does not exist in target or target is primitive and cannot be deep merged
148
+ mergedOutput[index] = sourceElement;
149
+ });
150
+ return mergedOutput;
151
+ }
152
+ /**
153
+ * Deep merge, but considers asymmetric matchers. Unlike base util's deep merge,
154
+ * will merge any object-like instance.
155
+ * Compatible with Jest's snapshot matcher. Should not be used outside of snapshot.
156
+ *
157
+ * @example
158
+ * ```ts
159
+ * toMatchSnapshot({
160
+ * name: expect.stringContaining('text')
161
+ * })
162
+ * ```
163
+ */
164
+ function deepMergeSnapshot(target, source) {
165
+ if (isObject(target) && isObject(source)) {
166
+ const mergedOutput = { ...target };
167
+ Object.keys(source).forEach((key) => {
168
+ if (isObject(source[key]) && !source[key].$$typeof) {
169
+ if (!(key in target)) Object.assign(mergedOutput, { [key]: source[key] });
170
+ else mergedOutput[key] = deepMergeSnapshot(target[key], source[key]);
171
+ } else if (Array.isArray(source[key])) mergedOutput[key] = deepMergeArray(target[key], source[key]);
172
+ else Object.assign(mergedOutput, { [key]: source[key] });
173
+ });
174
+ return mergedOutput;
175
+ } else if (Array.isArray(target) && Array.isArray(source)) return deepMergeArray(target, source);
176
+ return target;
177
+ }
178
+ class DefaultMap extends Map {
179
+ defaultFn;
180
+ constructor(defaultFn, entries) {
181
+ super(entries);
182
+ this.defaultFn = defaultFn;
183
+ }
184
+ get(key) {
185
+ if (!this.has(key)) this.set(key, this.defaultFn(key));
186
+ return super.get(key);
187
+ }
188
+ }
189
+ class CounterMap extends DefaultMap {
190
+ constructor() {
191
+ super(() => 0);
192
+ }
193
+ // compat for jest-image-snapshot https://github.com/vitest-dev/vitest/issues/7322
194
+ // `valueOf` and `Snapshot.added` setter allows
195
+ // snapshotState.added = snapshotState.added + 1
196
+ // to function as
197
+ // snapshotState.added.total_ = snapshotState.added.total() + 1
198
+ _total;
199
+ valueOf() {
200
+ return this._total = this.total();
201
+ }
202
+ increment(key) {
203
+ if (typeof this._total !== "undefined") this._total++;
204
+ this.set(key, this.get(key) + 1);
205
+ }
206
+ total() {
207
+ if (typeof this._total !== "undefined") return this._total;
208
+ let total = 0;
209
+ for (const x of this.values()) total += x;
210
+ return total;
211
+ }
212
+ }
213
+ /* @__NO_SIDE_EFFECTS__ */
214
+ function memo(fn) {
215
+ const cache = /* @__PURE__ */ new Map();
216
+ return (arg) => {
217
+ if (!cache.has(arg)) cache.set(arg, fn(arg));
218
+ return cache.get(arg);
219
+ };
220
+ }
221
+
222
+ async function saveInlineSnapshots(environment, snapshots) {
223
+ const MagicString = (await import('magic-string')).default;
224
+ const files = new Set(snapshots.map((i) => i.file));
225
+ await Promise.all(Array.from(files).map(async (file) => {
226
+ const snaps = snapshots.filter((i) => i.file === file);
227
+ const code = await environment.readSnapshotFile(file);
228
+ if (code == null) throw new Error(`cannot read ${file} when saving inline snapshot`);
229
+ const s = new MagicString(code);
230
+ for (const snap of snaps) replaceInlineSnap(code, s, positionToOffset(code, snap.line, snap.column), snap.snapshot, snap.assertionName);
231
+ const transformed = s.toString();
232
+ if (transformed !== code) await environment.saveSnapshotFile(file, transformed);
233
+ }));
234
+ }
235
+ const defaultStartObjectRegex = /(?:toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot)\s*\(\s*(?:\/\*[\s\S]*\*\/\s*|\/\/.*(?:[\n\r\u2028\u2029]\s*|[\t\v\f \xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF]))*\{/;
236
+ function escapeRegExp(s) {
237
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
238
+ }
239
+ const buildStartObjectRegex = memo((assertionName) => {
240
+ const replaced = defaultStartObjectRegex.source.replace("toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot", escapeRegExp(assertionName));
241
+ return new RegExp(replaced);
242
+ });
243
+ function replaceObjectSnap(code, s, index, newSnap, assertionName) {
244
+ let _code = code.slice(index);
245
+ const startMatch = (assertionName ? buildStartObjectRegex(assertionName) : defaultStartObjectRegex).exec(_code);
246
+ if (!startMatch) return false;
247
+ _code = _code.slice(startMatch.index);
248
+ let callEnd = getCallLastIndex(_code);
249
+ if (callEnd === null) return false;
250
+ callEnd += index + startMatch.index;
251
+ const shapeEnd = getObjectShapeEndIndex(code, index + startMatch.index + startMatch[0].length);
252
+ const snap = `, ${prepareSnapString(newSnap, code, index)}`;
253
+ if (shapeEnd === callEnd)
254
+ // toMatchInlineSnapshot({ foo: expect.any(String) })
255
+ s.appendLeft(callEnd, snap);
256
+ else
257
+ // toMatchInlineSnapshot({ foo: expect.any(String) }, ``)
258
+ s.overwrite(shapeEnd, callEnd, snap);
259
+ return true;
260
+ }
261
+ function getObjectShapeEndIndex(code, index) {
262
+ let startBraces = 1;
263
+ let endBraces = 0;
264
+ while (startBraces !== endBraces && index < code.length) {
265
+ const s = code[index++];
266
+ if (s === "{") startBraces++;
267
+ else if (s === "}") endBraces++;
268
+ }
269
+ return index;
270
+ }
271
+ function prepareSnapString(snap, source, index) {
272
+ const lineNumber = offsetToLineNumber(source, index);
273
+ const indent = source.split(lineSplitRE)[lineNumber - 1].match(/^\s*/)[0] || "";
274
+ const indentNext = indent.includes(" ") ? `${indent}\t` : `${indent} `;
275
+ const lines = snap.trim().replace(/\\/g, "\\\\").split(/\n/g);
276
+ const isOneline = lines.length <= 1;
277
+ const quote = "`";
278
+ if (isOneline) return `${quote}${lines.join("\n").replace(/`/g, "\\`").replace(/\$\{/g, "\\${")}${quote}`;
279
+ return `${quote}\n${lines.map((i) => i ? indentNext + i : "").join("\n").replace(/`/g, "\\`").replace(/\$\{/g, "\\${")}\n${indent}${quote}`;
280
+ }
281
+ const defaultMethodNames = ["toMatchInlineSnapshot", "toThrowErrorMatchingInlineSnapshot"];
282
+ // on webkit, the line number is at the end of the method, not at the start
283
+ function getCodeStartingAtIndex(code, index, methodNames) {
284
+ for (const name of methodNames) {
285
+ const adjusted = index - name.length;
286
+ if (adjusted >= 0 && code.slice(adjusted, index) === name) return {
287
+ code: code.slice(adjusted),
288
+ index: adjusted
289
+ };
290
+ }
291
+ return {
292
+ code: code.slice(index),
293
+ index
294
+ };
295
+ }
296
+ const defaultStartRegex = /(?:toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot)\s*\(\s*(?:\/\*[\s\S]*\*\/\s*|\/\/.*(?:[\n\r\u2028\u2029]\s*|[\t\v\f \xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF]))*[\w$]*(['"`)])/;
297
+ const buildStartRegex = memo((assertionName) => {
298
+ const replaced = defaultStartRegex.source.replace("toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot", escapeRegExp(assertionName));
299
+ return new RegExp(replaced);
300
+ });
301
+ function replaceInlineSnap(code, s, currentIndex, newSnap, assertionName) {
302
+ const { code: codeStartingAtIndex, index } = getCodeStartingAtIndex(code, currentIndex, assertionName ? [assertionName] : defaultMethodNames);
303
+ const startMatch = (assertionName ? buildStartRegex(assertionName) : defaultStartRegex).exec(codeStartingAtIndex);
304
+ const firstKeywordMatch = (assertionName ? new RegExp(escapeRegExp(assertionName)) : /toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot/).exec(codeStartingAtIndex);
305
+ if (!startMatch || startMatch.index !== firstKeywordMatch?.index) return replaceObjectSnap(code, s, index, newSnap, assertionName);
306
+ const quote = startMatch[1];
307
+ const startIndex = index + startMatch.index + startMatch[0].length;
308
+ const snapString = prepareSnapString(newSnap, code, index);
309
+ if (quote === ")") {
310
+ s.appendRight(startIndex - 1, snapString);
311
+ return true;
312
+ }
313
+ const endMatch = new RegExp(`(?:^|[^\\\\])${quote}`).exec(code.slice(startIndex));
314
+ if (!endMatch) return false;
315
+ const endIndex = startIndex + endMatch.index + endMatch[0].length;
316
+ s.overwrite(startIndex - 1, endIndex, snapString);
317
+ return true;
318
+ }
319
+ const INDENTATION_REGEX = /^([^\S\n]*)\S/m;
320
+ function stripSnapshotIndentation(inlineSnapshot) {
321
+ // Find indentation if exists.
322
+ const match = inlineSnapshot.match(INDENTATION_REGEX);
323
+ if (!match || !match[1])
324
+ // No indentation.
325
+ return inlineSnapshot;
326
+ const indentation = match[1];
327
+ const lines = inlineSnapshot.split(/\n/g);
328
+ if (lines.length <= 2)
329
+ // Must be at least 3 lines.
330
+ return inlineSnapshot;
331
+ if (lines[0].trim() !== "" || lines.at(-1)?.trim() !== "")
332
+ // If not blank first and last lines, abort.
333
+ return inlineSnapshot;
334
+ for (let i = 1; i < lines.length - 1; i++) if (lines[i] !== "") {
335
+ if (lines[i].indexOf(indentation) !== 0)
336
+ // All lines except first and last should either be blank or have the same
337
+ // indent as the first line (or more). If this isn't the case we don't
338
+ // want to touch the snapshot at all.
339
+ return inlineSnapshot;
340
+ lines[i] = lines[i].substring(indentation.length);
341
+ }
342
+ // Last line is a special case because it won't have the same indent as others
343
+ // but may still have been given some indent to line up.
344
+ lines[lines.length - 1] = "";
345
+ // Return inline snapshot, now at indent 0.
346
+ inlineSnapshot = lines.join("\n");
347
+ return inlineSnapshot;
348
+ }
349
+
350
+ async function saveRawSnapshots(environment, snapshots) {
351
+ await Promise.all(snapshots.map(async (snap) => {
352
+ if (!snap.readonly) await environment.saveSnapshotFile(snap.file, snap.snapshot);
353
+ }));
354
+ }
355
+
356
+ export { CounterMap as C, DefaultMap as D, saveInlineSnapshots as a, saveRawSnapshots as b, serialize as c, addExtraLineBreaks as d, evaluateSnapshotFile as e, deepMergeSnapshot as f, stripSnapshotIndentation as g, keyToTestName as k, normalizeNewlines as n, removeExtraLineBreaks as r, saveSnapshotFile as s, testNameToKey as t };
@@ -1,5 +1,5 @@
1
1
  import fs__default from 'node:fs';
2
- import { b as basename, j as join, d as dirname } from './pathe.M-eThtNZ.Ba-7h1rE.js';
2
+ import { b as basename, j as join, d as dirname } from './pathe.M-eThtNZ.zq3TM4NT.js';
3
3
 
4
4
  const packageScopeTypeCache = /* @__PURE__ */ new Map();
5
5
  // mirrors LOOKUP_PACKAGE_SCOPE from the ESM resolution algorithm:
@@ -1,6 +1,6 @@
1
1
  import { EvaluatedModules } from 'vite/module-runner';
2
- import { d as dirname, r as resolve } from './pathe.M-eThtNZ.Ba-7h1rE.js';
3
- import { a as getSafeTimers } from './source-map.BjWcsIL9.js';
2
+ import { d as dirname, r as resolve } from './pathe.M-eThtNZ.zq3TM4NT.js';
3
+ import { a as getSafeTimers } from './source-map.DakdQc29.js';
4
4
  import { c as createBirpc } from './index.DmDMHCg8.js';
5
5
  import { g as getWorkerState } from './utils.DYj33du9.js';
6
6
 
@@ -1,4 +1,4 @@
1
- import { bv as FetchCachedFileSystemResult, bw as ResolveFunctionResult, U as UserConsoleLog, bn as AsyncLeak, a as File, a3 as AfterSuiteRunMeta, b2 as TestBenchmark, j as TestArtifact, k as TaskResultPack, l as TaskEventPack, Z as CancelReason, aO as SnapshotResult, a6 as BaselineData } from './config.d.BgktgHfG.js';
1
+ import { bw as FetchCachedFileSystemResult, bx as ResolveFunctionResult, U as UserConsoleLog, bo as AsyncLeak, a as File, a3 as AfterSuiteRunMeta, b2 as TestBenchmark, j as TestArtifact, k as TaskResultPack, l as TaskEventPack, Z as CancelReason, aO as SnapshotResult, a6 as BaselineData } from './config.d.B3YV4t0O.js';
2
2
  import { FetchFunctionOptions, FetchResult } from 'vite/module-runner';
3
3
 
4
4
  interface OTELCarrier {
@@ -1,8 +1,8 @@
1
1
  import { f as format, p as plugins } from './index.D0heQG4v.js';
2
2
  import { $ } from './tinyrainbow.Do8I1XRG.js';
3
3
  import { s as stringify, f as format$1, a as formatRegExp, t as truncateString, i as inspect } from './display.BlTmubjj.js';
4
- import { p as deepClone, q as getOwnProperties, g as getType$1, u as isObject, v as filterOutComments, w as ordinal, e as createDefer, x as assertTypes, t as toArray, y as isNegativeNaN, z as unique, A as objectAttr } from './pathe.M-eThtNZ.Ba-7h1rE.js';
5
- import { d as diffSequences, b as serializeValue, p as parseStacktrace, a as getSafeTimers } from './source-map.BjWcsIL9.js';
4
+ import { u as deepClone, v as getOwnProperties, g as getType$1, f as isObject, w as filterOutComments, x as ordinal, e as createDefer, y as assertTypes, t as toArray, z as isNegativeNaN, A as unique, B as objectAttr } from './pathe.M-eThtNZ.zq3TM4NT.js';
5
+ import { d as diffSequences, b as serializeValue, p as parseStacktrace, a as getSafeTimers } from './source-map.DakdQc29.js';
6
6
  import { createTaskName, createFileTask, calculateSuiteHash, interpretTaskModes, hasFailed } from '../task-utils.js';
7
7
 
8
8
  const RealDate = Date;
@@ -3814,7 +3814,10 @@ function throttle(fn, ms) {
3814
3814
  return fn.apply(this, args);
3815
3815
  }
3816
3816
  // Make sure fn is still called even if there are no further calls
3817
- pendingCall ??= setTimeout(call.bind(this), ms, ...args);
3817
+ pendingCall ??= setTimeout(() => {
3818
+ pendingCall = void 0;
3819
+ call.apply(this, args);
3820
+ }, ms);
3818
3821
  };
3819
3822
  }
3820
3823
  // throttle based on summary reporter's DURATION_UPDATE_INTERVAL_MS
@@ -4225,4 +4228,4 @@ async function publicCollect(specs, runner) {
4225
4228
  return files;
4226
4229
  }
4227
4230
 
4228
- export { createTagsFilter as A, validateTags as B, shuffle as C, TestSyntaxError as T, processError as a, printDiffOrStringify as b, createTaskCollector as c, diff as d, getCurrentSuite as e, createChainable as f, getCurrentTest as g, getHooks as h, getFn as i, afterAll as j, afterEach as k, aroundAll as l, matchesTags as m, aroundEach as n, beforeAll as o, publicCollect as p, beforeEach as q, describe as r, startTests as s, it as t, onTestFailed as u, onTestFinished as v, recordArtifact as w, suite as x, test as y, limitConcurrency as z };
4231
+ export { limitConcurrency as A, createTagsFilter as B, validateTags as C, shuffle as D, TestSyntaxError as T, processError as a, printDiffOrStringify as b, getCurrentTest as c, diff as d, createTaskCollector as e, getCurrentSuite as f, getRunningTests as g, createChainable as h, getHooks as i, getFn as j, afterAll as k, afterEach as l, matchesTags as m, aroundAll as n, aroundEach as o, publicCollect as p, beforeAll as q, recordArtifact as r, startTests as s, beforeEach as t, describe as u, it as v, onTestFailed as w, onTestFinished as x, suite as y, test as z };
@@ -1,4 +1,4 @@
1
- import { s as setSafeTimers } from './source-map.BjWcsIL9.js';
1
+ import { s as setSafeTimers } from './source-map.DakdQc29.js';
2
2
  import { a as addSerializer } from './plugins.DPQHVT0p.js';
3
3
 
4
4
  let globalSetup = false;
@@ -7,7 +7,7 @@ async function setupCommonEnv(config) {
7
7
  if (globalSetup) return;
8
8
  globalSetup = true;
9
9
  setSafeTimers();
10
- if (config.globals) (await import('./globals.TipXUFcZ.js')).registerApiGlobally();
10
+ if (config.globals) (await import('./globals.ZKtKSkEf.js')).registerApiGlobally();
11
11
  }
12
12
  function setupDefines(config) {
13
13
  for (const key in config.defines) globalThis[key] = config.defines[key];