@lokascript/framework 2.3.0 → 2.4.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/dist/api/index.js +29 -516
  2. package/dist/api/index.js.map +1 -1
  3. package/dist/core/index.js +20 -128
  4. package/dist/core/index.js.map +1 -1
  5. package/dist/core/pattern-matching/index.js +19 -12
  6. package/dist/core/pattern-matching/index.js.map +1 -1
  7. package/dist/core/tokenization/index.js.map +1 -1
  8. package/dist/core/types.d.ts +7 -354
  9. package/dist/core/types.d.ts.map +1 -1
  10. package/dist/core/types.js +21 -129
  11. package/dist/core/types.js.map +1 -1
  12. package/dist/generation/diagnostics.d.ts +5 -115
  13. package/dist/generation/diagnostics.d.ts.map +1 -1
  14. package/dist/generation/index.js +20 -77
  15. package/dist/generation/index.js.map +1 -1
  16. package/dist/index.cjs +189 -1458
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.js +108 -1347
  19. package/dist/index.js.map +1 -1
  20. package/dist/interfaces/value-extractor.d.ts +20 -0
  21. package/dist/interfaces/value-extractor.d.ts.map +1 -1
  22. package/dist/ir/explicit-parser.d.ts +2 -83
  23. package/dist/ir/explicit-parser.d.ts.map +1 -1
  24. package/dist/ir/explicit-renderer.d.ts +2 -31
  25. package/dist/ir/explicit-renderer.d.ts.map +1 -1
  26. package/dist/ir/index.js +89 -1260
  27. package/dist/ir/index.js.map +1 -1
  28. package/dist/ir/protocol-json.d.ts +2 -70
  29. package/dist/ir/protocol-json.d.ts.map +1 -1
  30. package/dist/ir/references.d.ts +2 -16
  31. package/dist/ir/references.d.ts.map +1 -1
  32. package/dist/ir/types.d.ts +2 -148
  33. package/dist/ir/types.d.ts.map +1 -1
  34. package/dist/parsing/index.js +19 -12
  35. package/dist/parsing/index.js.map +1 -1
  36. package/dist/schema/command-schema.d.ts +3 -92
  37. package/dist/schema/command-schema.d.ts.map +1 -1
  38. package/dist/schema/index.js +3 -20
  39. package/dist/schema/index.js.map +1 -1
  40. package/dist/testing/index.js +1133 -755
  41. package/dist/testing/index.js.map +1 -1
  42. package/package.json +6 -2
  43. package/src/core/types.ts +71 -600
  44. package/src/generation/diagnostics.ts +12 -233
  45. package/src/interfaces/value-extractor.ts +32 -0
  46. package/src/ir/explicit-parser.ts +12 -792
  47. package/src/ir/explicit-renderer.ts +2 -195
  48. package/src/ir/from-interchange.test.ts +91 -4
  49. package/src/ir/from-interchange.ts +59 -0
  50. package/src/ir/protocol-json.test.ts +16 -7
  51. package/src/ir/protocol-json.ts +9 -748
  52. package/src/ir/references.ts +2 -30
  53. package/src/ir/types.ts +18 -190
  54. package/src/schema/command-schema.ts +3 -134
@@ -2429,15 +2429,25 @@ function findPlugin(plugins2, val) {
2429
2429
  return null;
2430
2430
  }
2431
2431
  function printer(val, config2, indentation, depth, refs, hasCalledToJSON) {
2432
+ var _a;
2433
+ let result;
2432
2434
  const plugin3 = findPlugin(config2.plugins, val);
2433
2435
  if (plugin3 !== null) {
2434
- return printPlugin(plugin3, val, config2, indentation, depth, refs);
2436
+ result = printPlugin(plugin3, val, config2, indentation, depth, refs);
2437
+ } else {
2438
+ const basicResult = printBasicValue(val, config2.printFunctionName, config2.escapeRegex, config2.escapeString);
2439
+ if (basicResult !== null) {
2440
+ result = basicResult;
2441
+ } else {
2442
+ result = printComplexValue(val, config2, indentation, depth, refs, hasCalledToJSON);
2443
+ }
2435
2444
  }
2436
- const basicResult = printBasicValue(val, config2.printFunctionName, config2.escapeRegex, config2.escapeString);
2437
- if (basicResult !== null) {
2438
- return basicResult;
2445
+ (_a = config2._outputLengthPerDepth)[depth] ?? (_a[depth] = 0);
2446
+ config2._outputLengthPerDepth[depth] += result.length;
2447
+ if (config2._outputLengthPerDepth[depth] > config2.maxOutputLength) {
2448
+ config2.maxDepth = 0;
2439
2449
  }
2440
- return printComplexValue(val, config2, indentation, depth, refs, hasCalledToJSON);
2450
+ return result;
2441
2451
  }
2442
2452
  var DEFAULT_THEME = {
2443
2453
  comment: "gray",
@@ -2455,6 +2465,7 @@ var DEFAULT_OPTIONS = {
2455
2465
  highlight: false,
2456
2466
  indent: 2,
2457
2467
  maxDepth: Number.POSITIVE_INFINITY,
2468
+ maxOutputLength: 1e6,
2458
2469
  maxWidth: Number.POSITIVE_INFINITY,
2459
2470
  min: false,
2460
2471
  plugins: [],
@@ -2519,7 +2530,9 @@ function getConfig(options) {
2519
2530
  printFunctionName: getPrintFunctionName(options),
2520
2531
  printShadowRoot: options?.printShadowRoot ?? true,
2521
2532
  spacingInner: options?.min ? " " : "\n",
2522
- spacingOuter: options?.min ? "" : "\n"
2533
+ spacingOuter: options?.min ? "" : "\n",
2534
+ maxOutputLength: options?.maxOutputLength ?? DEFAULT_OPTIONS.maxOutputLength,
2535
+ _outputLengthPerDepth: []
2523
2536
  };
2524
2537
  }
2525
2538
  function createIndent(indent) {
@@ -4882,7 +4895,8 @@ var FALLBACK_FORMAT_OPTIONS = {
4882
4895
  maxDepth: 8,
4883
4896
  plugins: PLUGINS2
4884
4897
  };
4885
- function diff(a, b2, options) {
4898
+ var DEFAULT_MEMORIZE = (_, v) => v;
4899
+ function diff(a, b2, options, memorize = DEFAULT_MEMORIZE) {
4886
4900
  if (Object.is(a, b2)) {
4887
4901
  return "";
4888
4902
  }
@@ -4909,8 +4923,8 @@ function diff(a, b2, options) {
4909
4923
  let aDisplay = format(a, formatOptions);
4910
4924
  let bDisplay = format(b2, formatOptions);
4911
4925
  const MAX_LENGTH = 1e5;
4912
- aDisplay = truncate4(aDisplay);
4913
- bDisplay = truncate4(bDisplay);
4926
+ aDisplay = memorize("expected", truncate4(aDisplay));
4927
+ bDisplay = memorize("actual", truncate4(bDisplay));
4914
4928
  const aDiff = `${aColor(`${aIndicator} ${aAnnotation}:`)}
4915
4929
  ${aDisplay}`;
4916
4930
  const bDiff = `${bColor(`${bIndicator} ${bAnnotation}:`)}
@@ -4927,18 +4941,24 @@ ${bDiff}`;
4927
4941
  return diffLinesUnified(a.split("\n"), b2.split("\n"), options);
4928
4942
  case "boolean":
4929
4943
  case "number":
4930
- return comparePrimitive(a, b2, options);
4944
+ return comparePrimitive(a, b2, options, memorize);
4931
4945
  case "map":
4932
- return compareObjects(sortMap(a), sortMap(b2), options);
4946
+ return compareObjects(sortMap(a), sortMap(b2), options, memorize);
4933
4947
  case "set":
4934
- return compareObjects(sortSet(a), sortSet(b2), options);
4948
+ return compareObjects(sortSet(a), sortSet(b2), options, memorize);
4935
4949
  default:
4936
- return compareObjects(a, b2, options);
4950
+ return compareObjects(a, b2, options, memorize);
4937
4951
  }
4938
4952
  }
4939
- function comparePrimitive(a, b2, options) {
4940
- const aFormat = format(a, FORMAT_OPTIONS);
4941
- const bFormat = format(b2, FORMAT_OPTIONS);
4953
+ function createMemorize(memory) {
4954
+ return (pointer, stringifiedValue) => {
4955
+ memory[pointer] = stringifiedValue;
4956
+ return stringifiedValue;
4957
+ };
4958
+ }
4959
+ function comparePrimitive(a, b2, options, memorize = DEFAULT_MEMORIZE) {
4960
+ const aFormat = memorize("expected", format(a, FORMAT_OPTIONS));
4961
+ const bFormat = memorize("actual", format(b2, FORMAT_OPTIONS));
4942
4962
  return aFormat === bFormat ? "" : diffLinesUnified(aFormat.split("\n"), bFormat.split("\n"), options);
4943
4963
  }
4944
4964
  function sortMap(map2) {
@@ -4947,19 +4967,19 @@ function sortMap(map2) {
4947
4967
  function sortSet(set3) {
4948
4968
  return new Set(Array.from(set3.values()).sort());
4949
4969
  }
4950
- function compareObjects(a, b2, options) {
4970
+ function compareObjects(a, b2, options, memorize = DEFAULT_MEMORIZE) {
4951
4971
  let difference;
4952
4972
  let hasThrown = false;
4953
4973
  try {
4954
4974
  const formatOptions = getFormatOptions(FORMAT_OPTIONS, options);
4955
- difference = getObjectsDifference(a, b2, formatOptions, options);
4975
+ difference = getObjectsDifference(a, b2, formatOptions, options, memorize);
4956
4976
  } catch {
4957
4977
  hasThrown = true;
4958
4978
  }
4959
4979
  const noDiffMessage = getCommonMessage(NO_DIFF_MESSAGE, options);
4960
4980
  if (difference === void 0 || difference === noDiffMessage) {
4961
4981
  const formatOptions = getFormatOptions(FALLBACK_FORMAT_OPTIONS, options);
4962
- difference = getObjectsDifference(a, b2, formatOptions, options);
4982
+ difference = getObjectsDifference(a, b2, formatOptions, options, memorize);
4963
4983
  if (difference !== noDiffMessage && !hasThrown) {
4964
4984
  difference = `${getCommonMessage(SIMILAR_MESSAGE, options)}
4965
4985
 
@@ -4968,6 +4988,9 @@ ${difference}`;
4968
4988
  }
4969
4989
  return difference;
4970
4990
  }
4991
+ function getDefaultFormatOptions(options) {
4992
+ return getFormatOptions(FORMAT_OPTIONS, options);
4993
+ }
4971
4994
  function getFormatOptions(formatOptions, options) {
4972
4995
  const { compareKeys, printBasicPrototype, maxDepth } = normalizeDiffOptions(options);
4973
4996
  return {
@@ -4977,7 +5000,7 @@ function getFormatOptions(formatOptions, options) {
4977
5000
  maxDepth: maxDepth ?? formatOptions.maxDepth
4978
5001
  };
4979
5002
  }
4980
- function getObjectsDifference(a, b2, formatOptions, options) {
5003
+ function getObjectsDifference(a, b2, formatOptions, options, memorize = DEFAULT_MEMORIZE) {
4981
5004
  const formatOptionsZeroIndent = {
4982
5005
  ...formatOptions,
4983
5006
  indent: 0
@@ -4987,8 +5010,8 @@ function getObjectsDifference(a, b2, formatOptions, options) {
4987
5010
  if (aCompare === bCompare) {
4988
5011
  return getCommonMessage(NO_DIFF_MESSAGE, options);
4989
5012
  } else {
4990
- const aDisplay = format(a, formatOptions);
4991
- const bDisplay = format(b2, formatOptions);
5013
+ const aDisplay = memorize("expected", format(a, formatOptions));
5014
+ const bDisplay = memorize("actual", format(b2, formatOptions));
4992
5015
  return diffLinesUnified2(aDisplay.split("\n"), bDisplay.split("\n"), aCompare.split("\n"), bCompare.split("\n"), options);
4993
5016
  }
4994
5017
  }
@@ -5002,7 +5025,7 @@ function isReplaceable(obj1, obj2) {
5002
5025
  const obj2Type = getType2(obj2);
5003
5026
  return obj1Type === obj2Type && (obj1Type === "Object" || obj1Type === "Array");
5004
5027
  }
5005
- function printDiffOrStringify(received, expected, options) {
5028
+ function printDiffOrStringify(received, expected, options, memory) {
5006
5029
  const { aAnnotation, bAnnotation } = normalizeDiffOptions(options);
5007
5030
  if (typeof expected === "string" && typeof received === "string" && expected.length > 0 && received.length > 0 && expected.length <= MAX_DIFF_STRING_LENGTH && received.length <= MAX_DIFF_STRING_LENGTH && expected !== received) {
5008
5031
  if (expected.includes("\n") || received.includes("\n")) {
@@ -5019,7 +5042,8 @@ ${receivedLine}`;
5019
5042
  const clonedExpected = deepClone(expected, { forceWritable: true });
5020
5043
  const clonedReceived = deepClone(received, { forceWritable: true });
5021
5044
  const { replacedExpected, replacedActual } = replaceAsymmetricMatcher(clonedReceived, clonedExpected);
5022
- const difference = diff(replacedExpected, replacedActual, options);
5045
+ const memorize = memory ? createMemorize(memory) : DEFAULT_MEMORIZE;
5046
+ const difference = diff(replacedExpected, replacedActual, options, memorize);
5023
5047
  return difference;
5024
5048
  }
5025
5049
  function replaceAsymmetricMatcher(actual, expected, actualReplaced = /* @__PURE__ */ new WeakSet(), expectedReplaced = /* @__PURE__ */ new WeakSet()) {
@@ -5212,16 +5236,13 @@ function processError(_err, diffOptions, seen = /* @__PURE__ */ new WeakSet()) {
5212
5236
  }
5213
5237
  const err = _err;
5214
5238
  if (err.showDiff || err.showDiff === void 0 && err.expected !== void 0 && err.actual !== void 0) {
5215
- err.diff = printDiffOrStringify(err.actual, err.expected, {
5239
+ const options = {
5216
5240
  ...diffOptions,
5217
5241
  ...err.diffOptions
5218
- });
5219
- }
5220
- if ("expected" in err && typeof err.expected !== "string") {
5221
- err.expected = stringify(err.expected, 10);
5222
- }
5223
- if ("actual" in err && typeof err.actual !== "string") {
5224
- err.actual = stringify(err.actual, 10);
5242
+ };
5243
+ err.diff = printDiffOrStringify(err.actual, err.expected, options, err);
5244
+ err.expected = prettifyValue(err.expected, options);
5245
+ err.actual = prettifyValue(err.actual, options);
5225
5246
  }
5226
5247
  try {
5227
5248
  if (!seen.has(err) && typeof err.cause === "object") {
@@ -5237,6 +5258,12 @@ function processError(_err, diffOptions, seen = /* @__PURE__ */ new WeakSet()) {
5237
5258
  Inner error message: ${err?.message}`));
5238
5259
  }
5239
5260
  }
5261
+ function prettifyValue(value, options) {
5262
+ if (typeof value !== "string") {
5263
+ return format(value, getDefaultFormatOptions(options));
5264
+ }
5265
+ return value;
5266
+ }
5240
5267
 
5241
5268
  // ../../node_modules/@vitest/utils/dist/timers.js
5242
5269
  var SAFE_TIMERS_SYMBOL = Symbol("vitest:SAFE_TIMERS");
@@ -5545,8 +5572,8 @@ function originalPositionFor(map2, needle) {
5545
5572
  function OMapping(source, line, column, name) {
5546
5573
  return { source, line, column, name };
5547
5574
  }
5548
- function traceSegmentInternal(segments, memo, line, column, bias) {
5549
- let index2 = memoizedBinarySearch(segments, column, memo, line);
5575
+ function traceSegmentInternal(segments, memo2, line, column, bias) {
5576
+ let index2 = memoizedBinarySearch(segments, column, memo2, line);
5550
5577
  if (found) {
5551
5578
  index2 = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index2);
5552
5579
  } else if (bias === LEAST_UPPER_BOUND) index2++;
@@ -5695,7 +5722,7 @@ function parseSingleV8Stack(raw) {
5695
5722
  function parseStacktrace(stack, options = {}) {
5696
5723
  const { ignoreStackEntries = stackIgnorePatterns } = options;
5697
5724
  let stacks = !CHROME_IE_STACK_REGEXP.test(stack) ? parseFFOrSafariStackTrace(stack) : parseV8Stacktrace(stack);
5698
- const helperIndex = stacks.findLastIndex((s) => s.method === "__VITEST_HELPER__" || s.method === "async*__VITEST_HELPER__");
5725
+ const helperIndex = stacks.findLastIndex((s) => s.method.includes("__VITEST_HELPER__"));
5699
5726
  if (helperIndex >= 0) {
5700
5727
  stacks = stacks.slice(helperIndex + 1);
5701
5728
  }
@@ -5798,93 +5825,7 @@ function getOriginalPosition(map2, needle) {
5798
5825
  return result;
5799
5826
  }
5800
5827
 
5801
- // ../../node_modules/@vitest/runner/dist/chunk-tasks.js
5802
- var kChainableContext = Symbol("kChainableContext");
5803
- function getChainableContext(chainable) {
5804
- return chainable?.[kChainableContext];
5805
- }
5806
- function createChainable(keys2, fn2, context) {
5807
- function create(context2) {
5808
- const chain2 = function(...args) {
5809
- return fn2.apply(context2, args);
5810
- };
5811
- Object.assign(chain2, fn2);
5812
- Object.defineProperty(chain2, kChainableContext, {
5813
- value: {
5814
- withContext: () => chain2.bind(context2),
5815
- getFixtures: () => context2.fixtures,
5816
- setContext: (key, value) => {
5817
- context2[key] = value;
5818
- },
5819
- mergeContext: (ctx) => {
5820
- Object.assign(context2, ctx);
5821
- }
5822
- },
5823
- enumerable: false
5824
- });
5825
- for (const key of keys2) {
5826
- Object.defineProperty(chain2, key, { get() {
5827
- return create({
5828
- ...context2,
5829
- [key]: true
5830
- });
5831
- } });
5832
- }
5833
- return chain2;
5834
- }
5835
- const chain = create(context ?? {});
5836
- Object.defineProperty(chain, "fn", {
5837
- value: fn2,
5838
- enumerable: false
5839
- });
5840
- return chain;
5841
- }
5842
- function findTestFileStackTrace(testFilePath, error) {
5843
- const lines = error.split("\n").slice(1);
5844
- for (const line of lines) {
5845
- const stack = parseSingleStack(line);
5846
- if (stack && stack.file === testFilePath) {
5847
- return stack;
5848
- }
5849
- }
5850
- }
5851
- function validateTags(config2, tags) {
5852
- if (!config2.strictTags) {
5853
- return;
5854
- }
5855
- const availableTags = new Set(config2.tags.map((tag) => tag.name));
5856
- for (const tag of tags) {
5857
- if (!availableTags.has(tag)) {
5858
- throw createNoTagsError(config2.tags, tag);
5859
- }
5860
- }
5861
- }
5862
- function createNoTagsError(availableTags, tag, prefix = "tag") {
5863
- if (!availableTags.length) {
5864
- throw new Error(`The Vitest config does't define any "tags", cannot apply "${tag}" ${prefix} for this test. See: https://vitest.dev/guide/test-tags`);
5865
- }
5866
- throw new Error(`The ${prefix} "${tag}" is not defined in the configuration. Available tags are:
5867
- ${availableTags.map((t) => `- ${t.name}${t.description ? `: ${t.description}` : ""}`).join("\n")}`);
5868
- }
5869
- function getNames(task) {
5870
- const names = [task.name];
5871
- let current = task;
5872
- while (current?.suite) {
5873
- current = current.suite;
5874
- if (current?.name) {
5875
- names.unshift(current.name);
5876
- }
5877
- }
5878
- if (current !== task.file) {
5879
- names.unshift(task.file.name);
5880
- }
5881
- return names;
5882
- }
5883
- function createTaskName(names, separator = " > ") {
5884
- return names.filter((name) => name !== void 0).join(separator);
5885
- }
5886
-
5887
- // ../../node_modules/@vitest/runner/dist/index.js
5828
+ // ../../node_modules/@vitest/runner/dist/chunk-artifact.js
5888
5829
  var PendingError = class extends Error {
5889
5830
  constructor(message, task, note) {
5890
5831
  super(message);
@@ -5931,6 +5872,7 @@ function setHooks(key, hooks) {
5931
5872
  function getHooks(key) {
5932
5873
  return hooksMap.get(key);
5933
5874
  }
5875
+ var FIXTURE_STACK_TRACE_KEY = Symbol.for("VITEST_FIXTURE_STACK_TRACE");
5934
5876
  var _TestFixtures = class _TestFixtures {
5935
5877
  constructor(registrations) {
5936
5878
  __publicField(this, "_suiteContexts");
@@ -5949,6 +5891,9 @@ var _TestFixtures = class _TestFixtures {
5949
5891
  static getFileContexts(file) {
5950
5892
  return _TestFixtures._definitions.map((f) => f.getFileContext(file));
5951
5893
  }
5894
+ static isFixtureOptions(obj) {
5895
+ return isObject(obj) && Object.keys(obj).some((key) => _TestFixtures._fixtureOptionKeys.includes(key));
5896
+ }
5952
5897
  extend(runner2, userFixtures) {
5953
5898
  const { suite: suite2 } = getCurrentSuite();
5954
5899
  const isTopLevel = !suite2 || suite2.file === suite2;
@@ -5999,7 +5944,7 @@ var _TestFixtures = class _TestFixtures {
5999
5944
  let options;
6000
5945
  let value;
6001
5946
  let _options;
6002
- if (Array.isArray(fn2) && fn2.length >= 2 && isObject(fn2[1]) && Object.keys(fn2[1]).some((key) => _TestFixtures._fixtureOptionKeys.includes(key))) {
5947
+ if (Array.isArray(fn2) && fn2.length >= 2 && _TestFixtures.isFixtureOptions(fn2[1])) {
6003
5948
  _options = fn2[1];
6004
5949
  options = {
6005
5950
  auto: _options.auto ?? false,
@@ -6047,6 +5992,9 @@ var _TestFixtures = class _TestFixtures {
6047
5992
  deps,
6048
5993
  parent
6049
5994
  };
5995
+ if (isFixtureFunction(value)) {
5996
+ Object.assign(value, { [FIXTURE_STACK_TRACE_KEY]: new Error("STACK_TRACE_ERROR") });
5997
+ }
6050
5998
  registrations.set(name, item);
6051
5999
  if (item.scope === "worker" && (runner2.pool === "vmThreads" || runner2.pool === "vmForks")) {
6052
6000
  item.scope = "file";
@@ -6125,7 +6073,7 @@ function withFixtures(fn2, options) {
6125
6073
  const usedFixtures = [];
6126
6074
  const usedProps = getUsedProps(fn2);
6127
6075
  for (const fixture of registrations.values()) {
6128
- if (fixture.auto || usedProps.has(fixture.name)) {
6076
+ if (isAutoFixture(fixture, options) || usedProps.has(fixture.name)) {
6129
6077
  usedFixtures.push(fixture);
6130
6078
  }
6131
6079
  }
@@ -6179,6 +6127,15 @@ function withFixtures(fn2, options) {
6179
6127
  return fn2(context);
6180
6128
  };
6181
6129
  }
6130
+ function isAutoFixture(fixture, options) {
6131
+ if (!fixture.auto) {
6132
+ return false;
6133
+ }
6134
+ if (options?.suiteHook && fixture.scope === "test") {
6135
+ return false;
6136
+ }
6137
+ return true;
6138
+ }
6182
6139
  function isFixtureFunction(value) {
6183
6140
  return typeof value === "function";
6184
6141
  }
@@ -6186,7 +6143,7 @@ function resolveTestFixtureValue(fixture, context, cleanupFnArray) {
6186
6143
  if (!isFixtureFunction(fixture.value)) {
6187
6144
  return fixture.value;
6188
6145
  }
6189
- return resolveFixtureFunction(fixture.value, context, cleanupFnArray);
6146
+ return resolveFixtureFunction(fixture.value, fixture.name, context, cleanupFnArray);
6190
6147
  }
6191
6148
  var scopedFixturePromiseCache = /* @__PURE__ */ new WeakMap();
6192
6149
  async function resolveScopeFixtureValue(fixtures, suite2, fixture) {
@@ -6207,7 +6164,7 @@ async function resolveScopeFixtureValue(fixtures, suite2, fixture) {
6207
6164
  cleanupFnArrayMap.set(fixtureContext, []);
6208
6165
  }
6209
6166
  const cleanupFnFileArray = cleanupFnArrayMap.get(fixtureContext);
6210
- const promise = resolveFixtureFunction(fixture.value, fixture.scope === "file" ? {
6167
+ const promise = resolveFixtureFunction(fixture.value, fixture.name, fixture.scope === "file" ? {
6211
6168
  ...workerContext,
6212
6169
  ...fileContext
6213
6170
  } : fixtureContext, cleanupFnFileArray).then((value) => {
@@ -6218,8 +6175,9 @@ async function resolveScopeFixtureValue(fixtures, suite2, fixture) {
6218
6175
  scopedFixturePromiseCache.set(fixture, promise);
6219
6176
  return promise;
6220
6177
  }
6221
- async function resolveFixtureFunction(fixtureFn, context, cleanupFnArray) {
6178
+ async function resolveFixtureFunction(fixtureFn, fixtureName, context, cleanupFnArray) {
6222
6179
  const useFnArgPromise = createDefer();
6180
+ const stackTraceError = FIXTURE_STACK_TRACE_KEY in fixtureFn && fixtureFn[FIXTURE_STACK_TRACE_KEY] instanceof Error ? fixtureFn[FIXTURE_STACK_TRACE_KEY] : void 0;
6223
6181
  let isUseFnArgResolved = false;
6224
6182
  const fixtureReturn = fixtureFn(context, async (useFnArg) => {
6225
6183
  isUseFnArgResolved = true;
@@ -6230,6 +6188,14 @@ async function resolveFixtureFunction(fixtureFn, context, cleanupFnArray) {
6230
6188
  await fixtureReturn;
6231
6189
  });
6232
6190
  await useReturnPromise;
6191
+ }).then(() => {
6192
+ if (!isUseFnArgResolved) {
6193
+ const error = new Error(`Fixture "${fixtureName}" returned without calling "use". Make sure to call "use" in every code path of the fixture function.`);
6194
+ if (stackTraceError?.stack) {
6195
+ error.stack = error.message + stackTraceError.stack.replace(stackTraceError.message, "");
6196
+ }
6197
+ useFnArgPromise.reject(error);
6198
+ }
6233
6199
  }).catch((e) => {
6234
6200
  if (!isUseFnArgResolved) {
6235
6201
  useFnArgPromise.reject(e);
@@ -6358,6 +6324,46 @@ var _test;
6358
6324
  function getCurrentTest() {
6359
6325
  return _test;
6360
6326
  }
6327
+ var kChainableContext = Symbol("kChainableContext");
6328
+ function getChainableContext(chainable) {
6329
+ return chainable?.[kChainableContext];
6330
+ }
6331
+ function createChainable(keys2, fn2, context) {
6332
+ function create(context2) {
6333
+ const chain2 = function(...args) {
6334
+ return fn2.apply(context2, args);
6335
+ };
6336
+ Object.assign(chain2, fn2);
6337
+ Object.defineProperty(chain2, kChainableContext, {
6338
+ value: {
6339
+ withContext: () => chain2.bind(context2),
6340
+ getFixtures: () => context2.fixtures,
6341
+ setContext: (key, value) => {
6342
+ context2[key] = value;
6343
+ },
6344
+ mergeContext: (ctx) => {
6345
+ Object.assign(context2, ctx);
6346
+ }
6347
+ },
6348
+ enumerable: false
6349
+ });
6350
+ for (const key of keys2) {
6351
+ Object.defineProperty(chain2, key, { get() {
6352
+ return create({
6353
+ ...context2,
6354
+ [key]: true
6355
+ });
6356
+ } });
6357
+ }
6358
+ return chain2;
6359
+ }
6360
+ const chain = create(context ?? {});
6361
+ Object.defineProperty(chain, "fn", {
6362
+ value: fn2,
6363
+ enumerable: false
6364
+ });
6365
+ return chain;
6366
+ }
6361
6367
  function getDefaultHookTimeout() {
6362
6368
  return getRunner().config.hookTimeout;
6363
6369
  }
@@ -6466,6 +6472,50 @@ function createTestHook(name, handler) {
6466
6472
  return handler(current, fn2, timeout);
6467
6473
  };
6468
6474
  }
6475
+ function findTestFileStackTrace(testFilePath, error) {
6476
+ const lines = error.split("\n").slice(1);
6477
+ for (const line of lines) {
6478
+ const stack = parseSingleStack(line);
6479
+ if (stack && stack.file === testFilePath) {
6480
+ return stack;
6481
+ }
6482
+ }
6483
+ }
6484
+ function validateTags(config2, tags) {
6485
+ if (!config2.strictTags) {
6486
+ return;
6487
+ }
6488
+ const availableTags = new Set(config2.tags.map((tag) => tag.name));
6489
+ for (const tag of tags) {
6490
+ if (!availableTags.has(tag)) {
6491
+ throw createNoTagsError(config2.tags, tag);
6492
+ }
6493
+ }
6494
+ }
6495
+ function createNoTagsError(availableTags, tag, prefix = "tag") {
6496
+ if (!availableTags.length) {
6497
+ throw new Error(`The Vitest config does't define any "tags", cannot apply "${tag}" ${prefix} for this test. See: https://vitest.dev/guide/test-tags`);
6498
+ }
6499
+ throw new Error(`The ${prefix} "${tag}" is not defined in the configuration. Available tags are:
6500
+ ${availableTags.map((t) => `- ${t.name}${t.description ? `: ${t.description}` : ""}`).join("\n")}`);
6501
+ }
6502
+ function getNames(task) {
6503
+ const names = [task.name];
6504
+ let current = task;
6505
+ while (current?.suite) {
6506
+ current = current.suite;
6507
+ if (current?.name) {
6508
+ names.unshift(current.name);
6509
+ }
6510
+ }
6511
+ if (current !== task.file) {
6512
+ names.unshift(task.file.name);
6513
+ }
6514
+ return names;
6515
+ }
6516
+ function createTaskName(names, separator = " > ") {
6517
+ return names.filter((name) => name !== void 0).join(separator);
6518
+ }
6469
6519
  var suite = createSuite();
6470
6520
  var test2 = createTest(function(name, optionsOrFn, optionsOrTest) {
6471
6521
  if (getCurrentTest()) {
@@ -6596,7 +6646,7 @@ function createSuiteCollector(name, factory = () => {
6596
6646
  if (task2.mode === "run" && !handler) {
6597
6647
  task2.mode = "todo";
6598
6648
  }
6599
- if (options.concurrent || !options.sequential && runner.config.sequence.concurrent) {
6649
+ if (options.concurrent ?? (!options.sequential && runner.config.sequence.concurrent)) {
6600
6650
  task2.concurrent = true;
6601
6651
  }
6602
6652
  task2.shuffle = suiteOptions?.shuffle;
@@ -6896,7 +6946,7 @@ function createTaskCollector(fn2) {
6896
6946
  fixtureOptions = optionsOrFn;
6897
6947
  fixtureValue = maybeFn;
6898
6948
  } else {
6899
- if (optionsOrFn !== null && typeof optionsOrFn === "object" && !Array.isArray(optionsOrFn) && ("scope" in optionsOrFn || "auto" in optionsOrFn)) {
6949
+ if (optionsOrFn !== null && typeof optionsOrFn === "object" && !Array.isArray(optionsOrFn) && TestFixtures.isFixtureOptions(optionsOrFn)) {
6900
6950
  fixtureOptions = optionsOrFn;
6901
6951
  fixtureValue = {};
6902
6952
  } else {
@@ -7341,9 +7391,15 @@ function manageArtifactAttachment(attachment) {
7341
7391
  if (attachment.body && attachment.path) {
7342
7392
  throw new TypeError(`Test attachment requires only one of "body" or "path" to be set. Both are specified.`);
7343
7393
  }
7394
+ if (attachment.path && attachment.bodyEncoding) {
7395
+ throw new TypeError(`Test attachment with "path" should not have "bodyEncoding" specified.`);
7396
+ }
7344
7397
  if (attachment.body instanceof Uint8Array) {
7345
7398
  attachment.body = encodeUint8Array(attachment.body);
7346
7399
  }
7400
+ if (attachment.body != null) {
7401
+ attachment.bodyEncoding ?? (attachment.bodyEncoding = "base64");
7402
+ }
7347
7403
  }
7348
7404
 
7349
7405
  // ../../node_modules/vitest/dist/chunks/utils.BX5Fg8C4.js
@@ -9443,29 +9499,29 @@ function stringDistanceCapped(strA, strB, cap) {
9443
9499
  if (Math.abs(strA.length - strB.length) >= cap) {
9444
9500
  return cap;
9445
9501
  }
9446
- let memo = [];
9502
+ let memo2 = [];
9447
9503
  for (let i2 = 0; i2 <= strA.length; i2++) {
9448
- memo[i2] = Array(strB.length + 1).fill(0);
9449
- memo[i2][0] = i2;
9504
+ memo2[i2] = Array(strB.length + 1).fill(0);
9505
+ memo2[i2][0] = i2;
9450
9506
  }
9451
9507
  for (let j = 0; j < strB.length; j++) {
9452
- memo[0][j] = j;
9508
+ memo2[0][j] = j;
9453
9509
  }
9454
9510
  for (let i2 = 1; i2 <= strA.length; i2++) {
9455
9511
  let ch = strA.charCodeAt(i2 - 1);
9456
9512
  for (let j = 1; j <= strB.length; j++) {
9457
9513
  if (Math.abs(i2 - j) >= cap) {
9458
- memo[i2][j] = cap;
9514
+ memo2[i2][j] = cap;
9459
9515
  continue;
9460
9516
  }
9461
- memo[i2][j] = Math.min(
9462
- memo[i2 - 1][j] + 1,
9463
- memo[i2][j - 1] + 1,
9464
- memo[i2 - 1][j - 1] + (ch === strB.charCodeAt(j - 1) ? 0 : 1)
9517
+ memo2[i2][j] = Math.min(
9518
+ memo2[i2 - 1][j] + 1,
9519
+ memo2[i2][j - 1] + 1,
9520
+ memo2[i2 - 1][j - 1] + (ch === strB.charCodeAt(j - 1) ? 0 : 1)
9465
9521
  );
9466
9522
  }
9467
9523
  }
9468
- return memo[strA.length][strB.length];
9524
+ return memo2[strA.length][strB.length];
9469
9525
  }
9470
9526
  __name(stringDistanceCapped, "stringDistanceCapped");
9471
9527
  function addMethod(ctx, name, method) {
@@ -11927,18 +11983,16 @@ var ChaiStyleAssertions = (chai, utils) => {
11927
11983
  });
11928
11984
  }
11929
11985
  function defMethod(name, delegateTo) {
11930
- utils.addChainableMethod(chai.Assertion.prototype, name, function(...args) {
11986
+ utils.addMethod(chai.Assertion.prototype, name, function(...args) {
11931
11987
  const jestMethod = chai.Assertion.prototype[delegateTo];
11932
11988
  if (!jestMethod) {
11933
11989
  throw new Error(`Cannot delegate to ${String(delegateTo)}: method not found. Ensure JestChaiExpect plugin is loaded first.`);
11934
11990
  }
11935
11991
  return jestMethod.call(this, ...args);
11936
- }, () => {
11937
11992
  });
11938
11993
  }
11939
11994
  defProperty("called", "toHaveBeenCalled");
11940
11995
  defProperty("calledOnce", "toHaveBeenCalledOnce");
11941
- defProperty("returned", "toHaveReturned");
11942
11996
  defPropertyWithArgs("calledTwice", "toHaveBeenCalledTimes", 2);
11943
11997
  defPropertyWithArgs("calledThrice", "toHaveBeenCalledTimes", 3);
11944
11998
  defMethod("callCount", "toHaveBeenCalledTimes");
@@ -11946,6 +12000,7 @@ var ChaiStyleAssertions = (chai, utils) => {
11946
12000
  defMethod("calledOnceWith", "toHaveBeenCalledExactlyOnceWith");
11947
12001
  defMethod("lastCalledWith", "toHaveBeenLastCalledWith");
11948
12002
  defMethod("nthCalledWith", "toHaveBeenNthCalledWith");
12003
+ defMethod("returned", "toHaveReturned");
11949
12004
  defMethod("returnedWith", "toHaveReturnedWith");
11950
12005
  defMethod("returnedTimes", "toHaveReturnedTimes");
11951
12006
  defMethod("lastReturnedWith", "toHaveLastReturnedWith");
@@ -13493,7 +13548,7 @@ var JestChaiExpect = (chai, utils) => {
13493
13548
  }
13494
13549
  throw err;
13495
13550
  });
13496
- return recordAsyncExpect(test5, promise, createAssertionMessage(utils, this, !!args.length), error);
13551
+ return recordAsyncExpect(test5, promise, createAssertionMessage(utils, this, !!args.length), error, utils.flag(this, "soft"));
13497
13552
  };
13498
13553
  } });
13499
13554
  return proxy;
@@ -13534,7 +13589,7 @@ var JestChaiExpect = (chai, utils) => {
13534
13589
  }
13535
13590
  throw err;
13536
13591
  });
13537
- return recordAsyncExpect(test5, promise, createAssertionMessage(utils, this, !!args.length), error);
13592
+ return recordAsyncExpect(test5, promise, createAssertionMessage(utils, this, !!args.length), error, utils.flag(this, "soft"));
13538
13593
  };
13539
13594
  } });
13540
13595
  return proxy;
@@ -13609,7 +13664,6 @@ function getMatcherState(assertion, expect2) {
13609
13664
  }
13610
13665
  const matcherState = {
13611
13666
  ...getState(expect2),
13612
- task,
13613
13667
  currentTestName,
13614
13668
  customTesters: getCustomEqualityTesters(),
13615
13669
  isNot,
@@ -13618,8 +13672,10 @@ function getMatcherState(assertion, expect2) {
13618
13672
  equals,
13619
13673
  suppressedErrors: [],
13620
13674
  soft: utils_exports.flag(assertion, "soft"),
13621
- poll: utils_exports.flag(assertion, "poll")
13675
+ poll: utils_exports.flag(assertion, "poll"),
13676
+ assertion
13622
13677
  };
13678
+ Object.assign(matcherState, { task });
13623
13679
  return {
13624
13680
  state: matcherState,
13625
13681
  isNot,
@@ -13628,36 +13684,47 @@ function getMatcherState(assertion, expect2) {
13628
13684
  };
13629
13685
  }
13630
13686
  var JestExtendError = class extends Error {
13631
- constructor(message, actual, expected) {
13687
+ constructor(message, actual, expected, __vitest_error_context__) {
13632
13688
  super(message);
13633
13689
  this.actual = actual;
13634
13690
  this.expected = expected;
13691
+ this.__vitest_error_context__ = __vitest_error_context__;
13635
13692
  }
13636
13693
  };
13637
13694
  function JestExtendPlugin(c, expect2, matchers) {
13638
13695
  return (_, utils) => {
13639
13696
  Object.entries(matchers).forEach(([expectAssertionName, expectAssertion]) => {
13640
- function expectWrapper(...args) {
13697
+ function __VITEST_EXTEND_ASSERTION__(...args) {
13641
13698
  const { state, isNot, obj, customMessage } = getMatcherState(this, expect2);
13642
13699
  const result = expectAssertion.call(state, obj, ...args);
13643
13700
  if (result && typeof result === "object" && typeof result.then === "function") {
13644
13701
  const thenable = result;
13645
- return thenable.then(({ pass: pass2, message: message2, actual: actual2, expected: expected2 }) => {
13702
+ return thenable.then(({ pass: pass2, message: message2, actual: actual2, expected: expected2, meta: meta2 }) => {
13646
13703
  if (pass2 && isNot || !pass2 && !isNot) {
13647
- const errorMessage = customMessage != null ? customMessage : message2();
13648
- throw new JestExtendError(errorMessage, actual2, expected2);
13704
+ const errorMessage = (customMessage ? `${customMessage}: ` : "") + message2();
13705
+ throw new JestExtendError(errorMessage, actual2, expected2, {
13706
+ assertionName: expectAssertionName,
13707
+ meta: meta2
13708
+ });
13649
13709
  }
13650
13710
  });
13651
13711
  }
13652
- const { pass, message, actual, expected } = result;
13712
+ const { pass, message, actual, expected, meta } = result;
13653
13713
  if (pass && isNot || !pass && !isNot) {
13654
- const errorMessage = customMessage != null ? customMessage : message();
13655
- throw new JestExtendError(errorMessage, actual, expected);
13714
+ const errorMessage = (customMessage ? `${customMessage}: ` : "") + message();
13715
+ throw new JestExtendError(errorMessage, actual, expected, {
13716
+ assertionName: expectAssertionName,
13717
+ meta
13718
+ });
13656
13719
  }
13657
13720
  }
13658
- const softWrapper = wrapAssertion(utils, expectAssertionName, expectWrapper);
13721
+ const softWrapper = wrapAssertion(utils, expectAssertionName, __VITEST_EXTEND_ASSERTION__);
13659
13722
  utils.addMethod(globalThis[JEST_MATCHERS_OBJECT].matchers, expectAssertionName, softWrapper);
13660
13723
  utils.addMethod(c.Assertion.prototype, expectAssertionName, softWrapper);
13724
+ if (expectAssertion.__vitest_poll_takeover__) {
13725
+ const addedMethod = c.Assertion.prototype[expectAssertionName];
13726
+ Object.defineProperty(addedMethod, "__vitest_poll_takeover__", { value: true });
13727
+ }
13661
13728
  class CustomMatcher extends AsymmetricMatcher3 {
13662
13729
  constructor(inverse = false, ...sample) {
13663
13730
  super(sample, inverse);
@@ -13736,157 +13803,59 @@ function offsetToLineNumber(source, offset) {
13736
13803
  return line + 1;
13737
13804
  }
13738
13805
 
13739
- // ../../node_modules/@vitest/snapshot/dist/index.js
13740
- async function saveInlineSnapshots(environment, snapshots) {
13741
- const MagicString2 = (await Promise.resolve().then(() => (init_magic_string_es(), magic_string_es_exports))).default;
13742
- const files = new Set(snapshots.map((i2) => i2.file));
13743
- await Promise.all(Array.from(files).map(async (file) => {
13744
- const snaps = snapshots.filter((i2) => i2.file === file);
13745
- const code = await environment.readSnapshotFile(file);
13746
- if (code == null) {
13747
- throw new Error(`cannot read ${file} when saving inline snapshot`);
13748
- }
13749
- const s = new MagicString2(code);
13750
- for (const snap of snaps) {
13751
- const index2 = positionToOffset(code, snap.line, snap.column);
13752
- replaceInlineSnap(code, s, index2, snap.snapshot);
13753
- }
13754
- const transformed = s.toString();
13755
- if (transformed !== code) {
13756
- await environment.saveSnapshotFile(file, transformed);
13806
+ // ../../node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.js
13807
+ var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
13808
+
13809
+ // ../../node_modules/vitest/dist/chunks/rpc.MzXet3jl.js
13810
+ var RealDate = Date;
13811
+ var now2 = null;
13812
+ var MockDate = class _MockDate extends RealDate {
13813
+ constructor(y2, m, d2, h, M, s, ms) {
13814
+ super();
13815
+ let date;
13816
+ switch (arguments.length) {
13817
+ case 0:
13818
+ if (now2 !== null) date = new RealDate(now2.valueOf());
13819
+ else date = new RealDate();
13820
+ break;
13821
+ case 1:
13822
+ date = new RealDate(y2);
13823
+ break;
13824
+ default:
13825
+ d2 = typeof d2 === "undefined" ? 1 : d2;
13826
+ h = h || 0;
13827
+ M = M || 0;
13828
+ s = s || 0;
13829
+ ms = ms || 0;
13830
+ date = new RealDate(y2, m, d2, h, M, s, ms);
13831
+ break;
13757
13832
  }
13758
- }));
13759
- }
13760
- var startObjectRegex = /(?:toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot)\s*\(\s*(?:\/\*[\s\S]*\*\/\s*|\/\/.*(?:[\n\r\u2028\u2029]\s*|[\t\v\f \xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF]))*\{/;
13761
- function replaceObjectSnap(code, s, index2, newSnap) {
13762
- let _code = code.slice(index2);
13763
- const startMatch = startObjectRegex.exec(_code);
13764
- if (!startMatch) {
13765
- return false;
13833
+ Object.setPrototypeOf(date, _MockDate.prototype);
13834
+ return date;
13766
13835
  }
13767
- _code = _code.slice(startMatch.index);
13768
- let callEnd = getCallLastIndex(_code);
13769
- if (callEnd === null) {
13770
- return false;
13771
- }
13772
- callEnd += index2 + startMatch.index;
13773
- const shapeStart = index2 + startMatch.index + startMatch[0].length;
13774
- const shapeEnd = getObjectShapeEndIndex(code, shapeStart);
13775
- const snap = `, ${prepareSnapString(newSnap, code, index2)}`;
13776
- if (shapeEnd === callEnd) {
13777
- s.appendLeft(callEnd, snap);
13778
- } else {
13779
- s.overwrite(shapeEnd, callEnd, snap);
13780
- }
13781
- return true;
13782
- }
13783
- function getObjectShapeEndIndex(code, index2) {
13784
- let startBraces = 1;
13785
- let endBraces = 0;
13786
- while (startBraces !== endBraces && index2 < code.length) {
13787
- const s = code[index2++];
13788
- if (s === "{") {
13789
- startBraces++;
13790
- } else if (s === "}") {
13791
- endBraces++;
13792
- }
13793
- }
13794
- return index2;
13795
- }
13796
- function prepareSnapString(snap, source, index2) {
13797
- const lineNumber = offsetToLineNumber(source, index2);
13798
- const line = source.split(lineSplitRE)[lineNumber - 1];
13799
- const indent = line.match(/^\s*/)[0] || "";
13800
- const indentNext = indent.includes(" ") ? `${indent} ` : `${indent} `;
13801
- const lines = snap.trim().replace(/\\/g, "\\\\").split(/\n/g);
13802
- const isOneline = lines.length <= 1;
13803
- const quote = "`";
13804
- if (isOneline) {
13805
- return `${quote}${lines.join("\n").replace(/`/g, "\\`").replace(/\$\{/g, "\\${")}${quote}`;
13806
- }
13807
- return `${quote}
13808
- ${lines.map((i2) => i2 ? indentNext + i2 : "").join("\n").replace(/`/g, "\\`").replace(/\$\{/g, "\\${")}
13809
- ${indent}${quote}`;
13810
- }
13811
- var toMatchInlineName = "toMatchInlineSnapshot";
13812
- var toThrowErrorMatchingInlineName = "toThrowErrorMatchingInlineSnapshot";
13813
- function getCodeStartingAtIndex(code, index2) {
13814
- const indexInline = index2 - toMatchInlineName.length;
13815
- if (code.slice(indexInline, index2) === toMatchInlineName) {
13816
- return {
13817
- code: code.slice(indexInline),
13818
- index: indexInline
13819
- };
13820
- }
13821
- const indexThrowInline = index2 - toThrowErrorMatchingInlineName.length;
13822
- if (code.slice(index2 - indexThrowInline, index2) === toThrowErrorMatchingInlineName) {
13823
- return {
13824
- code: code.slice(index2 - indexThrowInline),
13825
- index: index2 - indexThrowInline
13826
- };
13827
- }
13828
- return {
13829
- code: code.slice(index2),
13830
- index: index2
13831
- };
13832
- }
13833
- var startRegex = /(?:toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot)\s*\(\s*(?:\/\*[\s\S]*\*\/\s*|\/\/.*(?:[\n\r\u2028\u2029]\s*|[\t\v\f \xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF]))*[\w$]*(['"`)])/;
13834
- function replaceInlineSnap(code, s, currentIndex, newSnap) {
13835
- const { code: codeStartingAtIndex, index: index2 } = getCodeStartingAtIndex(code, currentIndex);
13836
- const startMatch = startRegex.exec(codeStartingAtIndex);
13837
- const firstKeywordMatch = /toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot/.exec(codeStartingAtIndex);
13838
- if (!startMatch || startMatch.index !== firstKeywordMatch?.index) {
13839
- return replaceObjectSnap(code, s, index2, newSnap);
13840
- }
13841
- const quote = startMatch[1];
13842
- const startIndex = index2 + startMatch.index + startMatch[0].length;
13843
- const snapString = prepareSnapString(newSnap, code, index2);
13844
- if (quote === ")") {
13845
- s.appendRight(startIndex - 1, snapString);
13846
- return true;
13847
- }
13848
- const quoteEndRE = new RegExp(`(?:^|[^\\\\])${quote}`);
13849
- const endMatch = quoteEndRE.exec(code.slice(startIndex));
13850
- if (!endMatch) {
13851
- return false;
13852
- }
13853
- const endIndex = startIndex + endMatch.index + endMatch[0].length;
13854
- s.overwrite(startIndex - 1, endIndex, snapString);
13855
- return true;
13856
- }
13857
- var INDENTATION_REGEX = /^([^\S\n]*)\S/m;
13858
- function stripSnapshotIndentation(inlineSnapshot) {
13859
- const match = inlineSnapshot.match(INDENTATION_REGEX);
13860
- if (!match || !match[1]) {
13861
- return inlineSnapshot;
13862
- }
13863
- const indentation = match[1];
13864
- const lines = inlineSnapshot.split(/\n/g);
13865
- if (lines.length <= 2) {
13866
- return inlineSnapshot;
13867
- }
13868
- if (lines[0].trim() !== "" || lines.at(-1)?.trim() !== "") {
13869
- return inlineSnapshot;
13870
- }
13871
- for (let i2 = 1; i2 < lines.length - 1; i2++) {
13872
- if (lines[i2] !== "") {
13873
- if (lines[i2].indexOf(indentation) !== 0) {
13874
- return inlineSnapshot;
13875
- }
13876
- lines[i2] = lines[i2].substring(indentation.length);
13877
- }
13878
- }
13879
- lines[lines.length - 1] = "";
13880
- inlineSnapshot = lines.join("\n");
13881
- return inlineSnapshot;
13836
+ };
13837
+ MockDate.UTC = RealDate.UTC;
13838
+ MockDate.now = function() {
13839
+ return new MockDate().valueOf();
13840
+ };
13841
+ MockDate.parse = function(dateString) {
13842
+ return RealDate.parse(dateString);
13843
+ };
13844
+ MockDate.toString = function() {
13845
+ return RealDate.toString();
13846
+ };
13847
+ function mockDate(date) {
13848
+ const dateObj = new RealDate(date.valueOf());
13849
+ if (Number.isNaN(dateObj.getTime())) throw new TypeError(`mockdate: The time set is an invalid date: ${date}`);
13850
+ globalThis.Date = MockDate;
13851
+ now2 = dateObj.valueOf();
13882
13852
  }
13883
- async function saveRawSnapshots(environment, snapshots) {
13884
- await Promise.all(snapshots.map(async (snap) => {
13885
- if (!snap.readonly) {
13886
- await environment.saveSnapshotFile(snap.file, snap.snapshot);
13887
- }
13888
- }));
13853
+ function resetDate() {
13854
+ globalThis.Date = RealDate;
13889
13855
  }
13856
+ var { get: get2 } = Reflect;
13857
+
13858
+ // ../../node_modules/@vitest/snapshot/dist/index.js
13890
13859
  function getDefaultExportFromCjs3(x) {
13891
13860
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
13892
13861
  }
@@ -14107,6 +14076,175 @@ var CounterMap = class extends DefaultMap {
14107
14076
  return total;
14108
14077
  }
14109
14078
  };
14079
+ // @__NO_SIDE_EFFECTS__
14080
+ function memo(fn2) {
14081
+ const cache = /* @__PURE__ */ new Map();
14082
+ return (arg) => {
14083
+ if (!cache.has(arg)) {
14084
+ cache.set(arg, fn2(arg));
14085
+ }
14086
+ return cache.get(arg);
14087
+ };
14088
+ }
14089
+ async function saveInlineSnapshots(environment, snapshots) {
14090
+ const MagicString2 = (await Promise.resolve().then(() => (init_magic_string_es(), magic_string_es_exports))).default;
14091
+ const files = new Set(snapshots.map((i2) => i2.file));
14092
+ await Promise.all(Array.from(files).map(async (file) => {
14093
+ const snaps = snapshots.filter((i2) => i2.file === file);
14094
+ const code = await environment.readSnapshotFile(file);
14095
+ if (code == null) {
14096
+ throw new Error(`cannot read ${file} when saving inline snapshot`);
14097
+ }
14098
+ const s = new MagicString2(code);
14099
+ for (const snap of snaps) {
14100
+ const index2 = positionToOffset(code, snap.line, snap.column);
14101
+ replaceInlineSnap(code, s, index2, snap.snapshot, snap.assertionName);
14102
+ }
14103
+ const transformed = s.toString();
14104
+ if (transformed !== code) {
14105
+ await environment.saveSnapshotFile(file, transformed);
14106
+ }
14107
+ }));
14108
+ }
14109
+ var defaultStartObjectRegex = /(?:toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot)\s*\(\s*(?:\/\*[\s\S]*\*\/\s*|\/\/.*(?:[\n\r\u2028\u2029]\s*|[\t\v\f \xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF]))*\{/;
14110
+ function escapeRegExp(s) {
14111
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
14112
+ }
14113
+ var buildStartObjectRegex = /* @__PURE__ */ memo((assertionName) => {
14114
+ const replaced = defaultStartObjectRegex.source.replace("toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot", escapeRegExp(assertionName));
14115
+ return new RegExp(replaced);
14116
+ });
14117
+ function replaceObjectSnap(code, s, index2, newSnap, assertionName) {
14118
+ let _code = code.slice(index2);
14119
+ const regex = assertionName ? buildStartObjectRegex(assertionName) : defaultStartObjectRegex;
14120
+ const startMatch = regex.exec(_code);
14121
+ if (!startMatch) {
14122
+ return false;
14123
+ }
14124
+ _code = _code.slice(startMatch.index);
14125
+ let callEnd = getCallLastIndex(_code);
14126
+ if (callEnd === null) {
14127
+ return false;
14128
+ }
14129
+ callEnd += index2 + startMatch.index;
14130
+ const shapeStart = index2 + startMatch.index + startMatch[0].length;
14131
+ const shapeEnd = getObjectShapeEndIndex(code, shapeStart);
14132
+ const snap = `, ${prepareSnapString(newSnap, code, index2)}`;
14133
+ if (shapeEnd === callEnd) {
14134
+ s.appendLeft(callEnd, snap);
14135
+ } else {
14136
+ s.overwrite(shapeEnd, callEnd, snap);
14137
+ }
14138
+ return true;
14139
+ }
14140
+ function getObjectShapeEndIndex(code, index2) {
14141
+ let startBraces = 1;
14142
+ let endBraces = 0;
14143
+ while (startBraces !== endBraces && index2 < code.length) {
14144
+ const s = code[index2++];
14145
+ if (s === "{") {
14146
+ startBraces++;
14147
+ } else if (s === "}") {
14148
+ endBraces++;
14149
+ }
14150
+ }
14151
+ return index2;
14152
+ }
14153
+ function prepareSnapString(snap, source, index2) {
14154
+ const lineNumber = offsetToLineNumber(source, index2);
14155
+ const line = source.split(lineSplitRE)[lineNumber - 1];
14156
+ const indent = line.match(/^\s*/)[0] || "";
14157
+ const indentNext = indent.includes(" ") ? `${indent} ` : `${indent} `;
14158
+ const lines = snap.trim().replace(/\\/g, "\\\\").split(/\n/g);
14159
+ const isOneline = lines.length <= 1;
14160
+ const quote = "`";
14161
+ if (isOneline) {
14162
+ return `${quote}${lines.join("\n").replace(/`/g, "\\`").replace(/\$\{/g, "\\${")}${quote}`;
14163
+ }
14164
+ return `${quote}
14165
+ ${lines.map((i2) => i2 ? indentNext + i2 : "").join("\n").replace(/`/g, "\\`").replace(/\$\{/g, "\\${")}
14166
+ ${indent}${quote}`;
14167
+ }
14168
+ var defaultMethodNames = ["toMatchInlineSnapshot", "toThrowErrorMatchingInlineSnapshot"];
14169
+ function getCodeStartingAtIndex(code, index2, methodNames) {
14170
+ for (const name of methodNames) {
14171
+ const adjusted = index2 - name.length;
14172
+ if (adjusted >= 0 && code.slice(adjusted, index2) === name) {
14173
+ return {
14174
+ code: code.slice(adjusted),
14175
+ index: adjusted
14176
+ };
14177
+ }
14178
+ }
14179
+ return {
14180
+ code: code.slice(index2),
14181
+ index: index2
14182
+ };
14183
+ }
14184
+ var 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$]*(['"`)])/;
14185
+ var buildStartRegex = /* @__PURE__ */ memo((assertionName) => {
14186
+ const replaced = defaultStartRegex.source.replace("toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot", escapeRegExp(assertionName));
14187
+ return new RegExp(replaced);
14188
+ });
14189
+ function replaceInlineSnap(code, s, currentIndex, newSnap, assertionName) {
14190
+ const methodNames = assertionName ? [assertionName] : defaultMethodNames;
14191
+ const { code: codeStartingAtIndex, index: index2 } = getCodeStartingAtIndex(code, currentIndex, methodNames);
14192
+ const startRegex = assertionName ? buildStartRegex(assertionName) : defaultStartRegex;
14193
+ const startMatch = startRegex.exec(codeStartingAtIndex);
14194
+ const keywordRegex = assertionName ? new RegExp(escapeRegExp(assertionName)) : /toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot/;
14195
+ const firstKeywordMatch = keywordRegex.exec(codeStartingAtIndex);
14196
+ if (!startMatch || startMatch.index !== firstKeywordMatch?.index) {
14197
+ return replaceObjectSnap(code, s, index2, newSnap, assertionName);
14198
+ }
14199
+ const quote = startMatch[1];
14200
+ const startIndex = index2 + startMatch.index + startMatch[0].length;
14201
+ const snapString = prepareSnapString(newSnap, code, index2);
14202
+ if (quote === ")") {
14203
+ s.appendRight(startIndex - 1, snapString);
14204
+ return true;
14205
+ }
14206
+ const quoteEndRE = new RegExp(`(?:^|[^\\\\])${quote}`);
14207
+ const endMatch = quoteEndRE.exec(code.slice(startIndex));
14208
+ if (!endMatch) {
14209
+ return false;
14210
+ }
14211
+ const endIndex = startIndex + endMatch.index + endMatch[0].length;
14212
+ s.overwrite(startIndex - 1, endIndex, snapString);
14213
+ return true;
14214
+ }
14215
+ var INDENTATION_REGEX = /^([^\S\n]*)\S/m;
14216
+ function stripSnapshotIndentation(inlineSnapshot) {
14217
+ const match = inlineSnapshot.match(INDENTATION_REGEX);
14218
+ if (!match || !match[1]) {
14219
+ return inlineSnapshot;
14220
+ }
14221
+ const indentation = match[1];
14222
+ const lines = inlineSnapshot.split(/\n/g);
14223
+ if (lines.length <= 2) {
14224
+ return inlineSnapshot;
14225
+ }
14226
+ if (lines[0].trim() !== "" || lines.at(-1)?.trim() !== "") {
14227
+ return inlineSnapshot;
14228
+ }
14229
+ for (let i2 = 1; i2 < lines.length - 1; i2++) {
14230
+ if (lines[i2] !== "") {
14231
+ if (lines[i2].indexOf(indentation) !== 0) {
14232
+ return inlineSnapshot;
14233
+ }
14234
+ lines[i2] = lines[i2].substring(indentation.length);
14235
+ }
14236
+ }
14237
+ lines[lines.length - 1] = "";
14238
+ inlineSnapshot = lines.join("\n");
14239
+ return inlineSnapshot;
14240
+ }
14241
+ async function saveRawSnapshots(environment, snapshots) {
14242
+ await Promise.all(snapshots.map(async (snap) => {
14243
+ if (!snap.readonly) {
14244
+ await environment.saveSnapshotFile(snap.file, snap.snapshot);
14245
+ }
14246
+ }));
14247
+ }
14110
14248
  function isSameStackPosition(x, y2) {
14111
14249
  return x.file === y2.file && x.column === y2.column && x.line === y2.line;
14112
14250
  }
@@ -14148,6 +14286,7 @@ var SnapshotState = class _SnapshotState {
14148
14286
  this._snapshotFormat = {
14149
14287
  printBasicPrototype: false,
14150
14288
  escapeString: false,
14289
+ maxOutputLength: 2 ** 27,
14151
14290
  ...options.snapshotFormat
14152
14291
  };
14153
14292
  this._environment = options.snapshotEnvironment;
@@ -14181,6 +14320,9 @@ var SnapshotState = class _SnapshotState {
14181
14320
  const content = await options.snapshotEnvironment.readSnapshotFile(snapshotPath);
14182
14321
  return new _SnapshotState(testFilePath, snapshotPath, content, options);
14183
14322
  }
14323
+ get snapshotUpdateState() {
14324
+ return this._updateSnapshot;
14325
+ }
14184
14326
  get environment() {
14185
14327
  return this._environment;
14186
14328
  }
@@ -14215,12 +14357,20 @@ var SnapshotState = class _SnapshotState {
14215
14357
  if (promiseIndex !== -1) {
14216
14358
  return stacks[promiseIndex + 3];
14217
14359
  }
14360
+ const pollChainIndex = stacks.findIndex((i2) => i2.method.match(/__VITEST_POLL_CHAIN__/));
14361
+ if (pollChainIndex !== -1) {
14362
+ return stacks[pollChainIndex + 1];
14363
+ }
14218
14364
  for (let i2 = 0; i2 < stacks.length; i2++) {
14219
14365
  const match = stacks[i2].method.match(/__INLINE_SNAPSHOT_OFFSET_(\d+)__/);
14220
14366
  if (match) {
14221
14367
  return stacks[i2 + Number(match[1])] ?? null;
14222
14368
  }
14223
14369
  }
14370
+ const customMatcherIndex = stacks.findIndex((i2) => i2.method.includes("__VITEST_EXTEND_ASSERTION__"));
14371
+ if (customMatcherIndex !== -1) {
14372
+ return stacks[customMatcherIndex + 3] ?? null;
14373
+ }
14224
14374
  const stackIndex = stacks.findIndex((i2) => i2.method.includes("__INLINE_SNAPSHOT__"));
14225
14375
  return stackIndex !== -1 ? stacks[stackIndex + 2] : null;
14226
14376
  }
@@ -14228,9 +14378,10 @@ var SnapshotState = class _SnapshotState {
14228
14378
  this._dirty = true;
14229
14379
  if (options.stack) {
14230
14380
  this._inlineSnapshots.push({
14381
+ ...options.stack,
14231
14382
  snapshot: receivedSerialized,
14232
14383
  testId: options.testId,
14233
- ...options.stack
14384
+ assertionName: options.assertionName
14234
14385
  });
14235
14386
  } else if (options.rawSnapshot) {
14236
14387
  this._rawSnapshots.push({
@@ -14241,6 +14392,103 @@ var SnapshotState = class _SnapshotState {
14241
14392
  this._snapshotData[key] = receivedSerialized;
14242
14393
  }
14243
14394
  }
14395
+ _resolveKey(testId, testName2, key) {
14396
+ this._counters.increment(testName2);
14397
+ const count = this._counters.get(testName2);
14398
+ if (!key) {
14399
+ key = testNameToKey(testName2, count);
14400
+ }
14401
+ this._testIdToKeys.get(testId).push(key);
14402
+ return {
14403
+ key,
14404
+ count
14405
+ };
14406
+ }
14407
+ _resolveInlineStack(options) {
14408
+ const { testId, snapshot, assertionName, error } = options;
14409
+ const stacks = parseErrorStacktrace(error, { ignoreStackEntries: [] });
14410
+ const _stack = this._inferInlineSnapshotStack(stacks);
14411
+ if (!_stack) {
14412
+ const message = stacks.map((s) => ` ${s.file}:${s.line}:${s.column}${s.method ? ` (${s.method})` : ""}`).join("\n");
14413
+ throw new Error(`@vitest/snapshot: Couldn't infer stack frame for inline snapshot.
14414
+ ${message}`);
14415
+ }
14416
+ const stack = this.environment.processStackTrace?.(_stack) || _stack;
14417
+ stack.column--;
14418
+ const snapshotsWithSameStack = this._inlineSnapshotStacks.filter((s) => isSameStackPosition(s, stack));
14419
+ if (snapshotsWithSameStack.length > 0) {
14420
+ this._inlineSnapshots = this._inlineSnapshots.filter((s) => !isSameStackPosition(s, stack));
14421
+ const differentSnapshot = snapshotsWithSameStack.find((s) => s.snapshot !== snapshot);
14422
+ if (differentSnapshot) {
14423
+ throw Object.assign(new Error(`${assertionName} with different snapshots cannot be called at the same location`), {
14424
+ actual: snapshot,
14425
+ expected: differentSnapshot.snapshot
14426
+ });
14427
+ }
14428
+ }
14429
+ this._inlineSnapshotStacks.push({
14430
+ ...stack,
14431
+ testId,
14432
+ snapshot
14433
+ });
14434
+ return stack;
14435
+ }
14436
+ _reconcile(opts) {
14437
+ if (opts.hasSnapshot && this._updateSnapshot === "all" || (!opts.hasSnapshot || !opts.snapshotIsPersisted) && (this._updateSnapshot === "new" || this._updateSnapshot === "all")) {
14438
+ if (this._updateSnapshot === "all") {
14439
+ if (!opts.pass) {
14440
+ if (opts.hasSnapshot) {
14441
+ this.updated.increment(opts.testId);
14442
+ } else {
14443
+ this.added.increment(opts.testId);
14444
+ }
14445
+ this._addSnapshot(opts.key, opts.addValue, {
14446
+ stack: opts.stack,
14447
+ testId: opts.testId,
14448
+ rawSnapshot: opts.rawSnapshot,
14449
+ assertionName: opts.assertionName
14450
+ });
14451
+ } else {
14452
+ this.matched.increment(opts.testId);
14453
+ }
14454
+ } else {
14455
+ this._addSnapshot(opts.key, opts.addValue, {
14456
+ stack: opts.stack,
14457
+ testId: opts.testId,
14458
+ rawSnapshot: opts.rawSnapshot,
14459
+ assertionName: opts.assertionName
14460
+ });
14461
+ this.added.increment(opts.testId);
14462
+ }
14463
+ return {
14464
+ actual: "",
14465
+ count: opts.count,
14466
+ expected: "",
14467
+ key: opts.key,
14468
+ pass: true
14469
+ };
14470
+ } else {
14471
+ if (!opts.pass) {
14472
+ this.unmatched.increment(opts.testId);
14473
+ return {
14474
+ actual: opts.actualDisplay,
14475
+ count: opts.count,
14476
+ expected: opts.expectedDisplay,
14477
+ key: opts.key,
14478
+ pass: false
14479
+ };
14480
+ } else {
14481
+ this.matched.increment(opts.testId);
14482
+ return {
14483
+ actual: "",
14484
+ count: opts.count,
14485
+ expected: "",
14486
+ key: opts.key,
14487
+ pass: true
14488
+ };
14489
+ }
14490
+ }
14491
+ }
14244
14492
  async save() {
14245
14493
  const hasExternalSnapshots = Object.keys(this._snapshotData).length;
14246
14494
  const hasInlineSnapshots = this._inlineSnapshots.length;
@@ -14284,13 +14532,24 @@ var SnapshotState = class _SnapshotState {
14284
14532
  this._uncheckedKeys.clear();
14285
14533
  }
14286
14534
  }
14287
- match({ testId, testName: testName2, received, key, inlineSnapshot, isInline, error, rawSnapshot }) {
14288
- this._counters.increment(testName2);
14289
- const count = this._counters.get(testName2);
14290
- if (!key) {
14291
- key = testNameToKey(testName2, count);
14292
- }
14293
- this._testIdToKeys.get(testId).push(key);
14535
+ probeExpectedSnapshot(options) {
14536
+ const count = this._counters.get(options.testName) + 1;
14537
+ const key = testNameToKey(options.testName, count);
14538
+ return {
14539
+ key,
14540
+ count,
14541
+ data: options?.isInline ? options.inlineSnapshot : this._snapshotData[key],
14542
+ markAsChecked: () => {
14543
+ this._counters.increment(options.testName);
14544
+ this._testIdToKeys.get(options.testId).push(key);
14545
+ this._uncheckedKeys.delete(key);
14546
+ }
14547
+ };
14548
+ }
14549
+ match({ testId, testName: testName2, received, key, inlineSnapshot, isInline, error, rawSnapshot, assertionName }) {
14550
+ const resolved = this._resolveKey(testId, testName2, key);
14551
+ key = resolved.key;
14552
+ const count = resolved.count;
14294
14553
  if (!(isInline && this._snapshotData[key] !== void 0)) {
14295
14554
  this._uncheckedKeys.delete(key);
14296
14555
  }
@@ -14311,85 +14570,49 @@ var SnapshotState = class _SnapshotState {
14311
14570
  if (pass && !isInline && !rawSnapshot) {
14312
14571
  this._snapshotData[key] = receivedSerialized;
14313
14572
  }
14314
- let stack;
14315
- if (isInline) {
14316
- const stacks = parseErrorStacktrace(error || new Error("snapshot"), { ignoreStackEntries: [] });
14317
- const _stack = this._inferInlineSnapshotStack(stacks);
14318
- if (!_stack) {
14319
- throw new Error(`@vitest/snapshot: Couldn't infer stack frame for inline snapshot.
14320
- ${JSON.stringify(stacks)}`);
14321
- }
14322
- stack = this.environment.processStackTrace?.(_stack) || _stack;
14323
- stack.column--;
14324
- const snapshotsWithSameStack = this._inlineSnapshotStacks.filter((s) => isSameStackPosition(s, stack));
14325
- if (snapshotsWithSameStack.length > 0) {
14326
- this._inlineSnapshots = this._inlineSnapshots.filter((s) => !isSameStackPosition(s, stack));
14327
- const differentSnapshot = snapshotsWithSameStack.find((s) => s.snapshot !== receivedSerialized);
14328
- if (differentSnapshot) {
14329
- throw Object.assign(new Error("toMatchInlineSnapshot with different snapshots cannot be called at the same location"), {
14330
- actual: receivedSerialized,
14331
- expected: differentSnapshot.snapshot
14332
- });
14333
- }
14334
- }
14335
- this._inlineSnapshotStacks.push({
14336
- ...stack,
14337
- testId,
14338
- snapshot: receivedSerialized
14339
- });
14340
- }
14341
- if (hasSnapshot && this._updateSnapshot === "all" || (!hasSnapshot || !snapshotIsPersisted) && (this._updateSnapshot === "new" || this._updateSnapshot === "all")) {
14342
- if (this._updateSnapshot === "all") {
14343
- if (!pass) {
14344
- if (hasSnapshot) {
14345
- this.updated.increment(testId);
14346
- } else {
14347
- this.added.increment(testId);
14348
- }
14349
- this._addSnapshot(key, receivedSerialized, {
14350
- stack,
14351
- testId,
14352
- rawSnapshot
14353
- });
14354
- } else {
14355
- this.matched.increment(testId);
14356
- }
14357
- } else {
14358
- this._addSnapshot(key, receivedSerialized, {
14359
- stack,
14360
- testId,
14361
- rawSnapshot
14362
- });
14363
- this.added.increment(testId);
14364
- }
14365
- return {
14366
- actual: "",
14367
- count,
14368
- expected: "",
14369
- key,
14370
- pass: true
14371
- };
14372
- } else {
14373
- if (!pass) {
14374
- this.unmatched.increment(testId);
14375
- return {
14376
- actual: rawSnapshot ? receivedSerialized : removeExtraLineBreaks(receivedSerialized),
14377
- count,
14378
- expected: expectedTrimmed !== void 0 ? rawSnapshot ? expectedTrimmed : removeExtraLineBreaks(expectedTrimmed) : void 0,
14379
- key,
14380
- pass: false
14381
- };
14382
- } else {
14383
- this.matched.increment(testId);
14384
- return {
14385
- actual: "",
14386
- count,
14387
- expected: "",
14388
- key,
14389
- pass: true
14390
- };
14391
- }
14392
- }
14573
+ const stack = isInline ? this._resolveInlineStack({
14574
+ testId,
14575
+ snapshot: receivedSerialized,
14576
+ assertionName: assertionName || "toMatchInlineSnapshot",
14577
+ error: error || new Error("snapshot")
14578
+ }) : void 0;
14579
+ return this._reconcile({
14580
+ testId,
14581
+ key,
14582
+ count,
14583
+ pass,
14584
+ hasSnapshot,
14585
+ snapshotIsPersisted: !!snapshotIsPersisted,
14586
+ addValue: receivedSerialized,
14587
+ actualDisplay: rawSnapshot ? receivedSerialized : removeExtraLineBreaks(receivedSerialized),
14588
+ expectedDisplay: expectedTrimmed !== void 0 ? rawSnapshot ? expectedTrimmed : removeExtraLineBreaks(expectedTrimmed) : void 0,
14589
+ stack,
14590
+ rawSnapshot,
14591
+ assertionName
14592
+ });
14593
+ }
14594
+ processDomainSnapshot({ testId, received, expectedSnapshot, matchResult, isInline, error, assertionName }) {
14595
+ const stack = isInline ? this._resolveInlineStack({
14596
+ testId,
14597
+ snapshot: received,
14598
+ assertionName,
14599
+ error: error || new Error("STACK_TRACE_ERROR")
14600
+ }) : void 0;
14601
+ const actualResolved = matchResult?.resolved ?? received;
14602
+ const expectedResolved = matchResult?.expected ?? expectedSnapshot.data;
14603
+ return this._reconcile({
14604
+ testId,
14605
+ key: expectedSnapshot.key,
14606
+ count: expectedSnapshot.count,
14607
+ pass: matchResult?.pass ?? false,
14608
+ hasSnapshot: !!expectedSnapshot.data,
14609
+ snapshotIsPersisted: isInline ? true : this._fileExists,
14610
+ addValue: actualResolved,
14611
+ actualDisplay: removeExtraLineBreaks(actualResolved),
14612
+ expectedDisplay: expectedResolved !== void 0 ? removeExtraLineBreaks(expectedResolved) : void 0,
14613
+ stack,
14614
+ assertionName
14615
+ });
14393
14616
  }
14394
14617
  async pack() {
14395
14618
  const snapshot = {
@@ -14467,30 +14690,43 @@ var SnapshotClient = class {
14467
14690
  }
14468
14691
  return state;
14469
14692
  }
14470
- assert(options) {
14471
- const { filepath, name, testId = name, message, isInline = false, properties, inlineSnapshot, error, errorMessage, rawSnapshot } = options;
14693
+ match(options) {
14694
+ const { filepath, name, testId = name, message, isInline = false, properties, inlineSnapshot, error, errorMessage, rawSnapshot, assertionName } = options;
14472
14695
  let { received } = options;
14473
14696
  if (!filepath) {
14474
14697
  throw new Error("Snapshot cannot be used outside of test");
14475
14698
  }
14476
14699
  const snapshotState = this.getSnapshotState(filepath);
14700
+ const testName2 = [name, ...message ? [message] : []].join(" > ");
14701
+ const expectedSnapshot = snapshotState.probeExpectedSnapshot({
14702
+ testName: testName2,
14703
+ testId,
14704
+ isInline,
14705
+ inlineSnapshot
14706
+ });
14477
14707
  if (typeof properties === "object") {
14478
14708
  if (typeof received !== "object" || !received) {
14709
+ expectedSnapshot.markAsChecked();
14479
14710
  throw new Error("Received value must be an object when the matcher has properties");
14480
14711
  }
14712
+ let propertiesPass;
14481
14713
  try {
14482
- const pass2 = this.options.isEqual?.(received, properties) ?? false;
14483
- if (!pass2) {
14484
- throw createMismatchError("Snapshot properties mismatched", snapshotState.expand, received, properties);
14485
- } else {
14486
- received = deepMergeSnapshot(received, properties);
14487
- }
14714
+ propertiesPass = this.options.isEqual?.(received, properties) ?? false;
14488
14715
  } catch (err) {
14489
- err.message = errorMessage || "Snapshot mismatched";
14716
+ expectedSnapshot.markAsChecked();
14490
14717
  throw err;
14491
14718
  }
14719
+ if (!propertiesPass) {
14720
+ expectedSnapshot.markAsChecked();
14721
+ return {
14722
+ pass: false,
14723
+ message: () => errorMessage || "Snapshot properties mismatched",
14724
+ actual: received,
14725
+ expected: properties
14726
+ };
14727
+ }
14728
+ received = deepMergeSnapshot(received, properties);
14492
14729
  }
14493
- const testName2 = [name, ...message ? [message] : []].join(" > ");
14494
14730
  const { actual, expected, key, pass } = snapshotState.match({
14495
14731
  testId,
14496
14732
  testName: testName2,
@@ -14498,12 +14734,105 @@ var SnapshotClient = class {
14498
14734
  isInline,
14499
14735
  error,
14500
14736
  inlineSnapshot,
14501
- rawSnapshot
14737
+ rawSnapshot,
14738
+ assertionName
14502
14739
  });
14503
- if (!pass) {
14504
- throw createMismatchError(`Snapshot \`${key || "unknown"}\` mismatched`, snapshotState.expand, rawSnapshot ? actual : actual?.trim(), rawSnapshot ? expected : expected?.trim());
14740
+ return {
14741
+ pass,
14742
+ message: () => `Snapshot \`${key || "unknown"}\` mismatched`,
14743
+ actual: rawSnapshot ? actual : actual?.trim(),
14744
+ expected: rawSnapshot ? expected : expected?.trim()
14745
+ };
14746
+ }
14747
+ assert(options) {
14748
+ const result = this.match(options);
14749
+ if (!result.pass) {
14750
+ const snapshotState = this.getSnapshotState(options.filepath);
14751
+ throw createMismatchError(result.message(), snapshotState.expand, result.actual, result.expected);
14505
14752
  }
14506
14753
  }
14754
+ matchDomain(options) {
14755
+ const { received, filepath, name, testId = name, message, adapter, isInline = false, inlineSnapshot, error } = options;
14756
+ if (!filepath) {
14757
+ throw new Error("Snapshot cannot be used outside of test");
14758
+ }
14759
+ const captured = adapter.capture(received);
14760
+ const rendered = adapter.render(captured);
14761
+ const snapshotState = this.getSnapshotState(filepath);
14762
+ const testName2 = [name, ...message ? [message] : []].join(" > ");
14763
+ const expectedSnapshot = snapshotState.probeExpectedSnapshot({
14764
+ testName: testName2,
14765
+ testId,
14766
+ isInline,
14767
+ inlineSnapshot
14768
+ });
14769
+ expectedSnapshot.markAsChecked();
14770
+ const matchResult = expectedSnapshot.data ? adapter.match(captured, adapter.parseExpected(expectedSnapshot.data)) : void 0;
14771
+ const { actual, expected, key, pass } = snapshotState.processDomainSnapshot({
14772
+ testId,
14773
+ received: rendered,
14774
+ expectedSnapshot,
14775
+ matchResult,
14776
+ isInline,
14777
+ error,
14778
+ assertionName: options.assertionName
14779
+ });
14780
+ return {
14781
+ pass,
14782
+ message: () => `Snapshot \`${key}\` mismatched`,
14783
+ actual: actual?.trim(),
14784
+ expected: expected?.trim()
14785
+ };
14786
+ }
14787
+ async pollMatchDomain(options) {
14788
+ const { poll, filepath, name, testId = name, message, adapter, isInline = false, inlineSnapshot, error, timeout = 1e3, interval = 50 } = options;
14789
+ if (!filepath) {
14790
+ throw new Error("Snapshot cannot be used outside of test");
14791
+ }
14792
+ const snapshotState = this.getSnapshotState(filepath);
14793
+ const testName2 = [name, ...message ? [message] : []].join(" > ");
14794
+ const expectedSnapshot = snapshotState.probeExpectedSnapshot({
14795
+ testName: testName2,
14796
+ testId,
14797
+ isInline,
14798
+ inlineSnapshot
14799
+ });
14800
+ const reference = expectedSnapshot.data && snapshotState.snapshotUpdateState !== "all" ? adapter.parseExpected(expectedSnapshot.data) : void 0;
14801
+ const timedOut = timeout > 0 ? new Promise((r) => setTimeout(r, timeout)) : void 0;
14802
+ const stableResult = await getStableSnapshot({
14803
+ adapter,
14804
+ poll,
14805
+ interval,
14806
+ timedOut,
14807
+ match: reference ? (captured) => adapter.match(captured, reference).pass : void 0
14808
+ });
14809
+ expectedSnapshot.markAsChecked();
14810
+ if (!stableResult?.rendered) {
14811
+ if (stableResult?.lastPollError) {
14812
+ throw stableResult.lastPollError;
14813
+ }
14814
+ return {
14815
+ pass: false,
14816
+ message: () => `poll() did not produce a stable snapshot within the timeout`
14817
+ };
14818
+ }
14819
+ const matchResult = expectedSnapshot.data ? adapter.match(stableResult.captured, adapter.parseExpected(expectedSnapshot.data)) : void 0;
14820
+ const { actual, expected, key, pass } = snapshotState.processDomainSnapshot({
14821
+ testId,
14822
+ received: stableResult.rendered,
14823
+ expectedSnapshot,
14824
+ matchResult,
14825
+ isInline,
14826
+ error,
14827
+ assertionName: options.assertionName
14828
+ });
14829
+ return {
14830
+ pass,
14831
+ message: () => `Snapshot \`${key}\` mismatched`,
14832
+ actual: actual?.trim(),
14833
+ expected: expected?.trim()
14834
+ };
14835
+ }
14507
14836
  async assertRaw(options) {
14508
14837
  if (!options.rawSnapshot) {
14509
14838
  throw new Error("Raw snapshot is required");
@@ -14524,363 +14853,60 @@ var SnapshotClient = class {
14524
14853
  this.snapshotStateMap.clear();
14525
14854
  }
14526
14855
  };
14527
-
14528
- // ../../node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.js
14529
- var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
14530
-
14531
- // ../../node_modules/vitest/dist/chunks/rpc.MzXet3jl.js
14532
- var RealDate = Date;
14533
- var now2 = null;
14534
- var MockDate = class _MockDate extends RealDate {
14535
- constructor(y2, m, d2, h, M, s, ms) {
14536
- super();
14537
- let date;
14538
- switch (arguments.length) {
14539
- case 0:
14540
- if (now2 !== null) date = new RealDate(now2.valueOf());
14541
- else date = new RealDate();
14542
- break;
14543
- case 1:
14544
- date = new RealDate(y2);
14545
- break;
14546
- default:
14547
- d2 = typeof d2 === "undefined" ? 1 : d2;
14548
- h = h || 0;
14549
- M = M || 0;
14550
- s = s || 0;
14551
- ms = ms || 0;
14552
- date = new RealDate(y2, m, d2, h, M, s, ms);
14856
+ async function getStableSnapshot({ adapter, poll, interval, timedOut, match }) {
14857
+ let lastRendered;
14858
+ let lastPollError;
14859
+ let lastStable;
14860
+ while (true) {
14861
+ try {
14862
+ const pollResult = await raceWith(Promise.resolve(poll()), timedOut);
14863
+ if (!pollResult.ok) {
14553
14864
  break;
14554
- }
14555
- Object.setPrototypeOf(date, _MockDate.prototype);
14556
- return date;
14557
- }
14558
- };
14559
- MockDate.UTC = RealDate.UTC;
14560
- MockDate.now = function() {
14561
- return new MockDate().valueOf();
14562
- };
14563
- MockDate.parse = function(dateString) {
14564
- return RealDate.parse(dateString);
14565
- };
14566
- MockDate.toString = function() {
14567
- return RealDate.toString();
14568
- };
14569
- function mockDate(date) {
14570
- const dateObj = new RealDate(date.valueOf());
14571
- if (Number.isNaN(dateObj.getTime())) throw new TypeError(`mockdate: The time set is an invalid date: ${date}`);
14572
- globalThis.Date = MockDate;
14573
- now2 = dateObj.valueOf();
14574
- }
14575
- function resetDate() {
14576
- globalThis.Date = RealDate;
14577
- }
14578
- var { get: get2 } = Reflect;
14579
-
14580
- // ../../node_modules/vitest/dist/chunks/test.CTcmp4Su.js
14581
- var unsupported = [
14582
- "matchSnapshot",
14583
- "toMatchSnapshot",
14584
- "toMatchInlineSnapshot",
14585
- "toThrowErrorMatchingSnapshot",
14586
- "toThrowErrorMatchingInlineSnapshot",
14587
- "throws",
14588
- "Throw",
14589
- "throw",
14590
- "toThrow",
14591
- "toThrowError"
14592
- ];
14593
- function throwWithCause(error, source) {
14594
- if (error.cause == null) error.cause = /* @__PURE__ */ new Error("Matcher did not succeed in time.");
14595
- throw copyStackTrace$1(error, source);
14596
- }
14597
- function createExpectPoll(expect2) {
14598
- return function poll(fn2, options = {}) {
14599
- const defaults = getWorkerState().config.expect?.poll ?? {};
14600
- const { interval = defaults.interval ?? 50, timeout = defaults.timeout ?? 1e3, message } = options;
14601
- const assertion = expect2(null, message).withContext({ poll: true });
14602
- fn2 = fn2.bind(assertion);
14603
- const test5 = chai_exports.util.flag(assertion, "vitest-test");
14604
- if (!test5) throw new Error("expect.poll() must be called inside a test");
14605
- const proxy = new Proxy(assertion, { get(target, key, receiver) {
14606
- const assertionFunction = Reflect.get(target, key, receiver);
14607
- if (typeof assertionFunction !== "function") return assertionFunction instanceof chai_exports.Assertion ? proxy : assertionFunction;
14608
- if (key === "assert") return assertionFunction;
14609
- if (typeof key === "string" && unsupported.includes(key)) throw new SyntaxError(`expect.poll() is not supported in combination with .${key}(). Use vi.waitFor() if your assertion condition is unstable.`);
14610
- return function(...args) {
14611
- const STACK_TRACE_ERROR = /* @__PURE__ */ new Error("STACK_TRACE_ERROR");
14612
- const promise = async () => {
14613
- const { setTimeout: setTimeout3, clearTimeout: clearTimeout3 } = getSafeTimers();
14614
- let executionPhase = "fn";
14615
- let hasTimedOut = false;
14616
- const timerId = setTimeout3(() => {
14617
- hasTimedOut = true;
14618
- }, timeout);
14619
- chai_exports.util.flag(assertion, "_name", key);
14620
- const onSettled = chai_exports.util.flag(assertion, "_poll.onSettled");
14621
- try {
14622
- while (true) {
14623
- const isLastAttempt = hasTimedOut;
14624
- if (isLastAttempt) chai_exports.util.flag(assertion, "_isLastPollAttempt", true);
14625
- try {
14626
- executionPhase = "fn";
14627
- const obj = await fn2();
14628
- chai_exports.util.flag(assertion, "object", obj);
14629
- executionPhase = "assertion";
14630
- const output = await assertionFunction.call(assertion, ...args);
14631
- await onSettled?.({
14632
- assertion,
14633
- status: "pass"
14634
- });
14635
- return output;
14636
- } catch (err) {
14637
- if (isLastAttempt || executionPhase === "assertion" && chai_exports.util.flag(assertion, "_poll.assert_once")) {
14638
- await onSettled?.({
14639
- assertion,
14640
- status: "fail"
14641
- });
14642
- throwWithCause(err, STACK_TRACE_ERROR);
14643
- }
14644
- await delay(interval, setTimeout3);
14645
- }
14646
- }
14647
- } finally {
14648
- clearTimeout3(timerId);
14649
- }
14650
- };
14651
- let awaited = false;
14652
- test5.onFinished ?? (test5.onFinished = []);
14653
- test5.onFinished.push(() => {
14654
- if (!awaited) {
14655
- const negated = chai_exports.util.flag(assertion, "negate") ? "not." : "";
14656
- const assertionString = `expect.${chai_exports.util.flag(assertion, "_poll.element") ? "element(locator)" : "poll(assertion)"}.${negated}${String(key)}()`;
14657
- throw copyStackTrace$1(/* @__PURE__ */ new Error(`${assertionString} was not awaited. This assertion is asynchronous and must be awaited; otherwise, it is not executed to avoid unhandled rejections:
14658
-
14659
- await ${assertionString}
14660
- `), STACK_TRACE_ERROR);
14661
- }
14662
- });
14663
- let resultPromise;
14664
- return {
14665
- then(onFulfilled, onRejected) {
14666
- awaited = true;
14667
- return (resultPromise || (resultPromise = promise())).then(onFulfilled, onRejected);
14668
- },
14669
- catch(onRejected) {
14670
- awaited = true;
14671
- return (resultPromise || (resultPromise = promise())).catch(onRejected);
14672
- },
14673
- finally(onFinally) {
14674
- awaited = true;
14675
- return (resultPromise || (resultPromise = promise())).finally(onFinally);
14676
- },
14677
- [Symbol.toStringTag]: "Promise"
14865
+ }
14866
+ const captured = adapter.capture(pollResult.value);
14867
+ const rendered = adapter.render(captured);
14868
+ if (lastRendered !== void 0 && rendered === lastRendered) {
14869
+ lastStable = {
14870
+ captured,
14871
+ rendered
14678
14872
  };
14679
- };
14680
- } });
14681
- return proxy;
14682
- };
14683
- }
14684
- function copyStackTrace$1(target, source) {
14685
- if (source.stack !== void 0) target.stack = source.stack.replace(source.message, target.message);
14686
- return target;
14687
- }
14688
- var _client;
14689
- function getSnapshotClient() {
14690
- if (!_client) _client = new SnapshotClient({ isEqual: (received, expected) => {
14691
- return equals(received, expected, [iterableEquality, subsetEquality]);
14692
- } });
14693
- return _client;
14694
- }
14695
- function getError(expected, promise) {
14696
- if (typeof expected !== "function") {
14697
- if (!promise) throw new Error(`expected must be a function, received ${typeof expected}`);
14698
- return expected;
14699
- }
14700
- try {
14701
- expected();
14702
- } catch (e) {
14703
- return e;
14873
+ if (!match || match(captured)) {
14874
+ break;
14875
+ }
14876
+ } else {
14877
+ lastRendered = rendered;
14878
+ lastStable = void 0;
14879
+ }
14880
+ } catch (pollError) {
14881
+ lastRendered = void 0;
14882
+ lastStable = void 0;
14883
+ lastPollError = pollError;
14884
+ }
14885
+ const delayed = await raceWith(new Promise((r) => setTimeout(r, interval)), timedOut);
14886
+ if (!delayed.ok) {
14887
+ break;
14888
+ }
14704
14889
  }
14705
- throw new Error("snapshot function didn't throw");
14706
- }
14707
- function getTestNames(test5) {
14708
14890
  return {
14709
- filepath: test5.file.filepath,
14710
- name: getNames(test5).slice(1).join(" > "),
14711
- testId: test5.id
14891
+ ...lastStable,
14892
+ lastPollError
14712
14893
  };
14713
14894
  }
14714
- var SnapshotPlugin = (chai, utils) => {
14715
- function getTest(assertionName, obj) {
14716
- const test5 = utils.flag(obj, "vitest-test");
14717
- if (!test5) throw new Error(`'${assertionName}' cannot be used without test context`);
14718
- return test5;
14719
- }
14720
- for (const key of ["matchSnapshot", "toMatchSnapshot"]) utils.addMethod(chai.Assertion.prototype, key, wrapAssertion(utils, key, function(properties, message) {
14721
- utils.flag(this, "_name", key);
14722
- if (utils.flag(this, "negate")) throw new Error(`${key} cannot be used with "not"`);
14723
- const expected = utils.flag(this, "object");
14724
- const test5 = getTest(key, this);
14725
- if (typeof properties === "string" && typeof message === "undefined") {
14726
- message = properties;
14727
- properties = void 0;
14728
- }
14729
- const errorMessage = utils.flag(this, "message");
14730
- getSnapshotClient().assert({
14731
- received: expected,
14732
- message,
14733
- isInline: false,
14734
- properties,
14735
- errorMessage,
14736
- ...getTestNames(test5)
14737
- });
14738
- }));
14739
- utils.addMethod(chai.Assertion.prototype, "toMatchFileSnapshot", function(file, message) {
14740
- utils.flag(this, "_name", "toMatchFileSnapshot");
14741
- if (utils.flag(this, "negate")) throw new Error('toMatchFileSnapshot cannot be used with "not"');
14742
- const error = /* @__PURE__ */ new Error("resolves");
14743
- const expected = utils.flag(this, "object");
14744
- const test5 = getTest("toMatchFileSnapshot", this);
14745
- const errorMessage = utils.flag(this, "message");
14746
- return recordAsyncExpect(test5, getSnapshotClient().assertRaw({
14747
- received: expected,
14748
- message,
14749
- isInline: false,
14750
- rawSnapshot: { file },
14751
- errorMessage,
14752
- ...getTestNames(test5)
14753
- }), createAssertionMessage(utils, this, true), error, utils.flag(this, "soft"));
14754
- });
14755
- utils.addMethod(chai.Assertion.prototype, "toMatchInlineSnapshot", wrapAssertion(utils, "toMatchInlineSnapshot", function __INLINE_SNAPSHOT_OFFSET_3__(properties, inlineSnapshot, message) {
14756
- utils.flag(this, "_name", "toMatchInlineSnapshot");
14757
- if (utils.flag(this, "negate")) throw new Error('toMatchInlineSnapshot cannot be used with "not"');
14758
- const test5 = getTest("toMatchInlineSnapshot", this);
14759
- const expected = utils.flag(this, "object");
14760
- const error = utils.flag(this, "error");
14761
- if (typeof properties === "string") {
14762
- message = inlineSnapshot;
14763
- inlineSnapshot = properties;
14764
- properties = void 0;
14765
- }
14766
- if (inlineSnapshot) inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
14767
- const errorMessage = utils.flag(this, "message");
14768
- getSnapshotClient().assert({
14769
- received: expected,
14770
- message,
14771
- isInline: true,
14772
- properties,
14773
- inlineSnapshot,
14774
- error,
14775
- errorMessage,
14776
- ...getTestNames(test5)
14777
- });
14778
- }));
14779
- utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingSnapshot", wrapAssertion(utils, "toThrowErrorMatchingSnapshot", function(properties, message) {
14780
- utils.flag(this, "_name", "toThrowErrorMatchingSnapshot");
14781
- if (utils.flag(this, "negate")) throw new Error('toThrowErrorMatchingSnapshot cannot be used with "not"');
14782
- const expected = utils.flag(this, "object");
14783
- const test5 = getTest("toThrowErrorMatchingSnapshot", this);
14784
- const promise = utils.flag(this, "promise");
14785
- const errorMessage = utils.flag(this, "message");
14786
- getSnapshotClient().assert({
14787
- received: getError(expected, promise),
14788
- message,
14789
- errorMessage,
14790
- ...getTestNames(test5)
14791
- });
14792
- }));
14793
- utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingInlineSnapshot", wrapAssertion(utils, "toThrowErrorMatchingInlineSnapshot", function __INLINE_SNAPSHOT_OFFSET_3__(inlineSnapshot, message) {
14794
- if (utils.flag(this, "negate")) throw new Error('toThrowErrorMatchingInlineSnapshot cannot be used with "not"');
14795
- const test5 = getTest("toThrowErrorMatchingInlineSnapshot", this);
14796
- const expected = utils.flag(this, "object");
14797
- const error = utils.flag(this, "error");
14798
- const promise = utils.flag(this, "promise");
14799
- const errorMessage = utils.flag(this, "message");
14800
- if (inlineSnapshot) inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
14801
- getSnapshotClient().assert({
14802
- received: getError(expected, promise),
14803
- message,
14804
- inlineSnapshot,
14805
- isInline: true,
14806
- error,
14807
- errorMessage,
14808
- ...getTestNames(test5)
14809
- });
14810
- }));
14811
- utils.addMethod(chai.expect, "addSnapshotSerializer", addSerializer);
14812
- };
14813
- chai_exports.use(JestExtend);
14814
- chai_exports.use(JestChaiExpect);
14815
- chai_exports.use(ChaiStyleAssertions);
14816
- chai_exports.use(SnapshotPlugin);
14817
- chai_exports.use(JestAsymmetricMatchers);
14818
- function createExpect(test5) {
14819
- const expect2 = ((value, message) => {
14820
- const { assertionCalls } = getState(expect2);
14821
- setState({ assertionCalls: assertionCalls + 1 }, expect2);
14822
- const assert5 = chai_exports.expect(value, message);
14823
- const _test2 = test5 || getCurrentTest();
14824
- if (_test2)
14825
- return assert5.withTest(_test2);
14826
- else return assert5;
14827
- });
14828
- Object.assign(expect2, chai_exports.expect);
14829
- Object.assign(expect2, globalThis[ASYMMETRIC_MATCHERS_OBJECT]);
14830
- expect2.getState = () => getState(expect2);
14831
- expect2.setState = (state) => setState(state, expect2);
14832
- const globalState = getState(globalThis[GLOBAL_EXPECT]) || {};
14833
- setState({
14834
- ...globalState,
14835
- assertionCalls: 0,
14836
- isExpectingAssertions: false,
14837
- isExpectingAssertionsError: null,
14838
- expectedAssertionsNumber: null,
14839
- expectedAssertionsNumberErrorGen: null,
14840
- get testPath() {
14841
- return getWorkerState().filepath;
14842
- },
14843
- currentTestName: test5 ? test5.fullTestName ?? "" : globalState.currentTestName
14844
- }, expect2);
14845
- expect2.assert = chai_exports.assert;
14846
- expect2.extend = (matchers) => chai_exports.expect.extend(expect2, matchers);
14847
- expect2.addEqualityTesters = (customTesters) => addCustomEqualityTesters(customTesters);
14848
- expect2.soft = (...args) => {
14849
- return expect2(...args).withContext({ soft: true });
14850
- };
14851
- expect2.poll = createExpectPoll(expect2);
14852
- expect2.unreachable = (message) => {
14853
- chai_exports.assert.fail(`expected${message ? ` "${message}" ` : " "}not to be reached`);
14854
- };
14855
- function assertions(expected) {
14856
- const errorGen = () => /* @__PURE__ */ new Error(`expected number of assertions to be ${expected}, but got ${expect2.getState().assertionCalls}`);
14857
- if (Error.captureStackTrace) Error.captureStackTrace(errorGen(), assertions);
14858
- expect2.setState({
14859
- expectedAssertionsNumber: expected,
14860
- expectedAssertionsNumberErrorGen: errorGen
14861
- });
14862
- }
14863
- function hasAssertions() {
14864
- const error = /* @__PURE__ */ new Error("expected any number of assertion, but got none");
14865
- if (Error.captureStackTrace) Error.captureStackTrace(error, hasAssertions);
14866
- expect2.setState({
14867
- isExpectingAssertions: true,
14868
- isExpectingAssertionsError: error
14869
- });
14895
+ function raceWith(promise, other) {
14896
+ const left = promise.then((value) => ({
14897
+ ok: true,
14898
+ value
14899
+ }));
14900
+ if (!other) {
14901
+ return left;
14870
14902
  }
14871
- chai_exports.util.addMethod(expect2, "assertions", assertions);
14872
- chai_exports.util.addMethod(expect2, "hasAssertions", hasAssertions);
14873
- expect2.extend(customMatchers);
14874
- return expect2;
14903
+ return Promise.race([left, other.then((value) => ({
14904
+ ok: false,
14905
+ value
14906
+ }))]);
14875
14907
  }
14876
- var globalExpect = createExpect();
14877
- Object.defineProperty(globalThis, GLOBAL_EXPECT, {
14878
- value: globalExpect,
14879
- writable: true,
14880
- configurable: true
14881
- });
14882
- var assert4 = chai_exports.assert;
14883
- var should2 = chai_exports.should;
14908
+
14909
+ // ../../node_modules/vitest/dist/chunks/test.DNmyFkvJ.js
14884
14910
  var fakeTimersSrc = {};
14885
14911
  var global2;
14886
14912
  var hasRequiredGlobal;
@@ -16902,7 +16928,7 @@ var FakeTimers = class {
16902
16928
  return this._fakingTime;
16903
16929
  }
16904
16930
  };
16905
- function copyStackTrace(target, source) {
16931
+ function copyStackTrace$1(target, source) {
16906
16932
  if (source.stack !== void 0) target.stack = source.stack.replace(source.message, target.message);
16907
16933
  return target;
16908
16934
  }
@@ -16923,7 +16949,7 @@ function waitFor(callback, options = {}) {
16923
16949
  const handleTimeout = () => {
16924
16950
  if (intervalId) clearInterval2(intervalId);
16925
16951
  let error = lastError;
16926
- if (!error) error = copyStackTrace(/* @__PURE__ */ new Error("Timed out in waitFor!"), STACK_TRACE_ERROR);
16952
+ if (!error) error = copyStackTrace$1(/* @__PURE__ */ new Error("Timed out in waitFor!"), STACK_TRACE_ERROR);
16927
16953
  reject(error);
16928
16954
  };
16929
16955
  const checkCallback = () => {
@@ -16964,7 +16990,7 @@ function waitUntil(callback, options = {}) {
16964
16990
  let intervalId;
16965
16991
  const onReject = (error) => {
16966
16992
  if (intervalId) clearInterval2(intervalId);
16967
- if (!error) error = copyStackTrace(/* @__PURE__ */ new Error("Timed out in waitUntil!"), STACK_TRACE_ERROR);
16993
+ if (!error) error = copyStackTrace$1(/* @__PURE__ */ new Error("Timed out in waitUntil!"), STACK_TRACE_ERROR);
16968
16994
  reject(error);
16969
16995
  };
16970
16996
  const onResolve = (result) => {
@@ -17101,7 +17127,7 @@ function createVitest() {
17101
17127
  waitUntil,
17102
17128
  defineHelper: (fn2) => {
17103
17129
  return function __VITEST_HELPER__(...args) {
17104
- const result = fn2(...args);
17130
+ const result = fn2.apply(this, args);
17105
17131
  if (result && typeof result === "object" && typeof result.then === "function") return (async function __VITEST_HELPER__2() {
17106
17132
  return await result;
17107
17133
  })();
@@ -17230,6 +17256,358 @@ function getImporter(name) {
17230
17256
  return stack.includes(` at Object.${name}`) || stack.includes(`${name}@`) || stack.includes(` at ${name} (`);
17231
17257
  }) + 1])?.file || "";
17232
17258
  }
17259
+ var unsupported = [
17260
+ "matchSnapshot",
17261
+ "toMatchSnapshot",
17262
+ "toMatchInlineSnapshot",
17263
+ "toThrowErrorMatchingSnapshot",
17264
+ "toThrowErrorMatchingInlineSnapshot",
17265
+ "throws",
17266
+ "Throw",
17267
+ "throw",
17268
+ "toThrow",
17269
+ "toThrowError"
17270
+ ];
17271
+ function throwWithCause(error, source) {
17272
+ if (error.cause == null) error.cause = /* @__PURE__ */ new Error("Matcher did not succeed in time.");
17273
+ throw copyStackTrace(error, source);
17274
+ }
17275
+ function createExpectPoll(expect2) {
17276
+ return function poll(fn2, options = {}) {
17277
+ const defaults = getWorkerState().config.expect?.poll ?? {};
17278
+ const { interval = defaults.interval ?? 50, timeout = defaults.timeout ?? 1e3, message } = options;
17279
+ const assertion = expect2(null, message).withContext({ poll: true });
17280
+ fn2 = fn2.bind(assertion);
17281
+ chai_exports.util.flag(assertion, "_poll.fn", fn2);
17282
+ chai_exports.util.flag(assertion, "_poll.timeout", timeout);
17283
+ chai_exports.util.flag(assertion, "_poll.interval", interval);
17284
+ const test5 = chai_exports.util.flag(assertion, "vitest-test");
17285
+ if (!test5) throw new Error("expect.poll() must be called inside a test");
17286
+ const proxy = new Proxy(assertion, { get(target, key, receiver) {
17287
+ const assertionFunction = Reflect.get(target, key, receiver);
17288
+ if (typeof assertionFunction !== "function") return assertionFunction instanceof chai_exports.Assertion ? proxy : assertionFunction;
17289
+ if (key === "assert") return assertionFunction;
17290
+ if (typeof key === "string" && unsupported.includes(key)) throw new SyntaxError(`expect.poll() is not supported in combination with .${key}(). Use vi.waitFor() if your assertion condition is unstable.`);
17291
+ return function __VITEST_POLL_CHAIN__(...args) {
17292
+ const STACK_TRACE_ERROR = /* @__PURE__ */ new Error("STACK_TRACE_ERROR");
17293
+ const promise = async () => {
17294
+ chai_exports.util.flag(assertion, "_name", key);
17295
+ chai_exports.util.flag(assertion, "error", STACK_TRACE_ERROR);
17296
+ const onSettled = chai_exports.util.flag(assertion, "_poll.onSettled");
17297
+ if (Object.getOwnPropertyDescriptor(assertionFunction, "__vitest_poll_takeover__")?.value) try {
17298
+ const output = await assertionFunction.call(assertion, ...args);
17299
+ await onSettled?.({
17300
+ assertion,
17301
+ status: "pass"
17302
+ });
17303
+ return output;
17304
+ } catch (err) {
17305
+ await onSettled?.({
17306
+ assertion,
17307
+ status: "fail"
17308
+ });
17309
+ throwWithCause(err, STACK_TRACE_ERROR);
17310
+ }
17311
+ const { setTimeout: setTimeout3, clearTimeout: clearTimeout3 } = getSafeTimers();
17312
+ let executionPhase = "fn";
17313
+ let hasTimedOut = false;
17314
+ const timerId = setTimeout3(() => {
17315
+ hasTimedOut = true;
17316
+ }, timeout);
17317
+ try {
17318
+ while (true) {
17319
+ const isLastAttempt = hasTimedOut;
17320
+ if (isLastAttempt) chai_exports.util.flag(assertion, "_isLastPollAttempt", true);
17321
+ try {
17322
+ executionPhase = "fn";
17323
+ const obj = await fn2();
17324
+ chai_exports.util.flag(assertion, "object", obj);
17325
+ executionPhase = "assertion";
17326
+ const output = await assertionFunction.call(assertion, ...args);
17327
+ await onSettled?.({
17328
+ assertion,
17329
+ status: "pass"
17330
+ });
17331
+ return output;
17332
+ } catch (err) {
17333
+ if (isLastAttempt || executionPhase === "assertion" && chai_exports.util.flag(assertion, "_poll.assert_once")) {
17334
+ await onSettled?.({
17335
+ assertion,
17336
+ status: "fail"
17337
+ });
17338
+ throwWithCause(err, STACK_TRACE_ERROR);
17339
+ }
17340
+ await delay(interval, setTimeout3);
17341
+ if (vi.isFakeTimers()) vi.advanceTimersByTime(interval);
17342
+ }
17343
+ }
17344
+ } finally {
17345
+ clearTimeout3(timerId);
17346
+ }
17347
+ };
17348
+ let awaited = false;
17349
+ test5.onFinished ?? (test5.onFinished = []);
17350
+ test5.onFinished.push(() => {
17351
+ if (!awaited) {
17352
+ const negated = chai_exports.util.flag(assertion, "negate") ? "not." : "";
17353
+ const assertionString = `expect.${chai_exports.util.flag(assertion, "_poll.element") ? "element(locator)" : "poll(assertion)"}.${negated}${String(key)}()`;
17354
+ throw copyStackTrace(/* @__PURE__ */ new Error(`${assertionString} was not awaited. This assertion is asynchronous and must be awaited; otherwise, it is not executed to avoid unhandled rejections:
17355
+
17356
+ await ${assertionString}
17357
+ `), STACK_TRACE_ERROR);
17358
+ }
17359
+ });
17360
+ let resultPromise;
17361
+ return {
17362
+ then(onFulfilled, onRejected) {
17363
+ awaited = true;
17364
+ return (resultPromise || (resultPromise = promise())).then(onFulfilled, onRejected);
17365
+ },
17366
+ catch(onRejected) {
17367
+ awaited = true;
17368
+ return (resultPromise || (resultPromise = promise())).catch(onRejected);
17369
+ },
17370
+ finally(onFinally) {
17371
+ awaited = true;
17372
+ return (resultPromise || (resultPromise = promise())).finally(onFinally);
17373
+ },
17374
+ [Symbol.toStringTag]: "Promise"
17375
+ };
17376
+ };
17377
+ } });
17378
+ return proxy;
17379
+ };
17380
+ }
17381
+ function copyStackTrace(target, source) {
17382
+ if (source.stack !== void 0) target.stack = source.stack.replace(source.message, target.message);
17383
+ return target;
17384
+ }
17385
+ var _client;
17386
+ function getSnapshotClient() {
17387
+ if (!_client) _client = new SnapshotClient({ isEqual: (received, expected) => {
17388
+ return equals(received, expected, [iterableEquality, subsetEquality]);
17389
+ } });
17390
+ return _client;
17391
+ }
17392
+ function getError(expected, promise) {
17393
+ if (typeof expected !== "function") {
17394
+ if (!promise) throw new Error(`expected must be a function, received ${typeof expected}`);
17395
+ return expected;
17396
+ }
17397
+ try {
17398
+ expected();
17399
+ } catch (e) {
17400
+ return e;
17401
+ }
17402
+ throw new Error("snapshot function didn't throw");
17403
+ }
17404
+ function getTestNames(test5) {
17405
+ return {
17406
+ filepath: test5.file.filepath,
17407
+ name: getNames(test5).slice(1).join(" > "),
17408
+ testId: test5.id
17409
+ };
17410
+ }
17411
+ function getAssertionName(assertion) {
17412
+ const name = chai_exports.util.flag(assertion, "_name");
17413
+ if (!name) throw new Error("Assertion name is not set. This is a bug in Vitest. Please, open a new issue with reproduction.");
17414
+ return name;
17415
+ }
17416
+ function getTest(obj) {
17417
+ const test5 = chai_exports.util.flag(obj, "vitest-test");
17418
+ if (!test5) throw new Error(`'${getAssertionName(obj)}' cannot be used without test context`);
17419
+ return test5;
17420
+ }
17421
+ function validateAssertion(assertion) {
17422
+ if (chai_exports.util.flag(assertion, "negate")) throw new Error(`${getAssertionName(assertion)} cannot be used with "not"`);
17423
+ }
17424
+ var SnapshotPlugin = (chai, utils) => {
17425
+ for (const key of ["matchSnapshot", "toMatchSnapshot"]) utils.addMethod(chai.Assertion.prototype, key, wrapAssertion(utils, key, function(propertiesOrHint, hint) {
17426
+ return assertMatchResult(toMatchSnapshotImpl({
17427
+ assertion: this,
17428
+ received: utils.flag(this, "object"),
17429
+ ...normalizeArguments(propertiesOrHint, hint)
17430
+ }), chai.util.flag(this, "message"));
17431
+ }));
17432
+ utils.addMethod(chai.Assertion.prototype, "toMatchFileSnapshot", function(filepath, hint) {
17433
+ utils.flag(this, "_name", "toMatchFileSnapshot");
17434
+ validateAssertion(this);
17435
+ const assertPromise = toMatchFileSnapshotImpl({
17436
+ assertion: this,
17437
+ received: utils.flag(this, "object"),
17438
+ filepath,
17439
+ hint
17440
+ }).then((result) => assertMatchResult(result, chai.util.flag(this, "message")));
17441
+ return recordAsyncExpect(getTest(this), assertPromise, createAssertionMessage(utils, this, true), /* @__PURE__ */ new Error("resolves"), utils.flag(this, "soft"));
17442
+ });
17443
+ utils.addMethod(chai.Assertion.prototype, "toMatchInlineSnapshot", wrapAssertion(utils, "toMatchInlineSnapshot", function __INLINE_SNAPSHOT_OFFSET_3__(propertiesOrInlineSnapshot, inlineSnapshotOrHint, hint) {
17444
+ return assertMatchResult(toMatchSnapshotImpl({
17445
+ assertion: this,
17446
+ received: utils.flag(this, "object"),
17447
+ isInline: true,
17448
+ ...normalizeInlineArguments(propertiesOrInlineSnapshot, inlineSnapshotOrHint, hint)
17449
+ }), chai.util.flag(this, "message"));
17450
+ }));
17451
+ utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingSnapshot", wrapAssertion(utils, "toThrowErrorMatchingSnapshot", function(propertiesOrHint, hint) {
17452
+ validateAssertion(this);
17453
+ const received = utils.flag(this, "object");
17454
+ const promise = utils.flag(this, "promise");
17455
+ return assertMatchResult(toMatchSnapshotImpl({
17456
+ assertion: this,
17457
+ received: getError(received, promise),
17458
+ ...normalizeArguments(propertiesOrHint, hint)
17459
+ }), chai.util.flag(this, "message"));
17460
+ }));
17461
+ utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingInlineSnapshot", wrapAssertion(utils, "toThrowErrorMatchingInlineSnapshot", function __INLINE_SNAPSHOT_OFFSET_3__(inlineSnapshotOrHint, hint) {
17462
+ validateAssertion(this);
17463
+ const received = utils.flag(this, "object");
17464
+ const promise = utils.flag(this, "promise");
17465
+ return assertMatchResult(toMatchSnapshotImpl({
17466
+ assertion: this,
17467
+ received: getError(received, promise),
17468
+ isInline: true,
17469
+ ...normalizeInlineArguments(void 0, inlineSnapshotOrHint, hint)
17470
+ }), chai.util.flag(this, "message"));
17471
+ }));
17472
+ utils.addMethod(chai.expect, "addSnapshotSerializer", addSerializer);
17473
+ };
17474
+ function normalizeArguments(propertiesOrHint, hint) {
17475
+ if (typeof propertiesOrHint === "string") return { hint: propertiesOrHint };
17476
+ return {
17477
+ properties: propertiesOrHint,
17478
+ hint
17479
+ };
17480
+ }
17481
+ function normalizeInlineArguments(propertiesOrInlineSnapshot, inlineSnapshotOrHint, hint) {
17482
+ let inlineSnapshot;
17483
+ if (typeof propertiesOrInlineSnapshot === "string") {
17484
+ inlineSnapshot = stripSnapshotIndentation(propertiesOrInlineSnapshot);
17485
+ return {
17486
+ inlineSnapshot,
17487
+ hint: inlineSnapshotOrHint
17488
+ };
17489
+ }
17490
+ if (inlineSnapshotOrHint) inlineSnapshot = stripSnapshotIndentation(inlineSnapshotOrHint);
17491
+ return {
17492
+ properties: propertiesOrInlineSnapshot,
17493
+ inlineSnapshot,
17494
+ hint
17495
+ };
17496
+ }
17497
+ function toMatchSnapshotImpl(options) {
17498
+ const { assertion } = options;
17499
+ validateAssertion(assertion);
17500
+ const assertionName = getAssertionName(assertion);
17501
+ const test5 = getTest(assertion);
17502
+ return getSnapshotClient().match({
17503
+ received: options.received,
17504
+ properties: options.properties,
17505
+ message: options.hint,
17506
+ isInline: options.isInline,
17507
+ inlineSnapshot: options.inlineSnapshot,
17508
+ assertionName,
17509
+ error: chai_exports.util.flag(assertion, "error"),
17510
+ ...getTestNames(test5)
17511
+ });
17512
+ }
17513
+ async function toMatchFileSnapshotImpl(options) {
17514
+ const { assertion } = options;
17515
+ validateAssertion(assertion);
17516
+ const testNames = getTestNames(getTest(assertion));
17517
+ const snapshotState = getSnapshotClient().getSnapshotState(testNames.filepath);
17518
+ const rawSnapshotFile = await snapshotState.environment.resolveRawPath(testNames.filepath, options.filepath);
17519
+ const rawSnapshotContent = await snapshotState.environment.readSnapshotFile(rawSnapshotFile);
17520
+ return getSnapshotClient().match({
17521
+ received: options.received,
17522
+ message: options.hint,
17523
+ rawSnapshot: {
17524
+ file: rawSnapshotFile,
17525
+ content: rawSnapshotContent ?? void 0
17526
+ },
17527
+ ...testNames
17528
+ });
17529
+ }
17530
+ function assertMatchResult(result, customMessage) {
17531
+ if (!result.pass) {
17532
+ const errorMessage = (customMessage ? `${customMessage}: ` : "") + result.message();
17533
+ throw Object.assign(new Error(errorMessage), {
17534
+ actual: result.actual,
17535
+ expected: result.expected,
17536
+ diffOptions: { expand: getWorkerState().config.snapshotOptions.expand }
17537
+ });
17538
+ }
17539
+ }
17540
+ chai_exports.use(JestExtend);
17541
+ chai_exports.use(JestChaiExpect);
17542
+ chai_exports.use(ChaiStyleAssertions);
17543
+ chai_exports.use(SnapshotPlugin);
17544
+ chai_exports.use(JestAsymmetricMatchers);
17545
+ function createExpect(test5) {
17546
+ const expect2 = ((value, message) => {
17547
+ const { assertionCalls } = getState(expect2);
17548
+ setState({ assertionCalls: assertionCalls + 1 }, expect2);
17549
+ const assert5 = chai_exports.expect(value, message);
17550
+ const _test2 = test5 || getCurrentTest();
17551
+ if (_test2)
17552
+ return assert5.withTest(_test2);
17553
+ else return assert5;
17554
+ });
17555
+ Object.assign(expect2, chai_exports.expect);
17556
+ Object.assign(expect2, globalThis[ASYMMETRIC_MATCHERS_OBJECT]);
17557
+ expect2.getState = () => getState(expect2);
17558
+ expect2.setState = (state) => setState(state, expect2);
17559
+ const globalState = getState(globalThis[GLOBAL_EXPECT]) || {};
17560
+ setState({
17561
+ ...globalState,
17562
+ assertionCalls: 0,
17563
+ isExpectingAssertions: false,
17564
+ isExpectingAssertionsError: null,
17565
+ expectedAssertionsNumber: null,
17566
+ expectedAssertionsNumberErrorGen: null,
17567
+ get testPath() {
17568
+ return getWorkerState().filepath;
17569
+ },
17570
+ currentTestName: test5 ? test5.fullTestName ?? "" : globalState.currentTestName
17571
+ }, expect2);
17572
+ expect2.assert = chai_exports.assert;
17573
+ expect2.extend = (matchers) => chai_exports.expect.extend(expect2, matchers);
17574
+ expect2.addEqualityTesters = (customTesters) => addCustomEqualityTesters(customTesters);
17575
+ expect2.soft = (...args) => {
17576
+ return expect2(...args).withContext({ soft: true });
17577
+ };
17578
+ expect2.poll = createExpectPoll(expect2);
17579
+ expect2.unreachable = (message) => {
17580
+ chai_exports.assert.fail(`expected${message ? ` "${message}" ` : " "}not to be reached`);
17581
+ };
17582
+ function assertions(expected) {
17583
+ const errorGen = () => /* @__PURE__ */ new Error(`expected number of assertions to be ${expected}, but got ${expect2.getState().assertionCalls}`);
17584
+ if (Error.captureStackTrace) Error.captureStackTrace(errorGen(), assertions);
17585
+ expect2.setState({
17586
+ expectedAssertionsNumber: expected,
17587
+ expectedAssertionsNumberErrorGen: errorGen
17588
+ });
17589
+ }
17590
+ function hasAssertions() {
17591
+ const error = /* @__PURE__ */ new Error("expected any number of assertion, but got none");
17592
+ if (Error.captureStackTrace) Error.captureStackTrace(error, hasAssertions);
17593
+ expect2.setState({
17594
+ isExpectingAssertions: true,
17595
+ isExpectingAssertionsError: error
17596
+ });
17597
+ }
17598
+ chai_exports.util.addMethod(expect2, "assertions", assertions);
17599
+ chai_exports.util.addMethod(expect2, "hasAssertions", hasAssertions);
17600
+ expect2.extend(customMatchers);
17601
+ return expect2;
17602
+ }
17603
+ var globalExpect = createExpect();
17604
+ Object.defineProperty(globalThis, GLOBAL_EXPECT, {
17605
+ value: globalExpect,
17606
+ writable: true,
17607
+ configurable: true
17608
+ });
17609
+ var assert4 = chai_exports.assert;
17610
+ var should2 = chai_exports.should;
17233
17611
 
17234
17612
  // ../../node_modules/vite/dist/node/module-runner.js
17235
17613
  var SOURCEMAPPING_URL = "sourceMa";