@lokascript/framework 2.3.1 → 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.
- package/dist/api/index.js +29 -516
- package/dist/api/index.js.map +1 -1
- package/dist/core/index.js +20 -128
- package/dist/core/index.js.map +1 -1
- package/dist/core/pattern-matching/index.js +19 -12
- package/dist/core/pattern-matching/index.js.map +1 -1
- package/dist/core/tokenization/index.js.map +1 -1
- package/dist/core/types.d.ts +7 -354
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js +21 -129
- package/dist/core/types.js.map +1 -1
- package/dist/generation/diagnostics.d.ts +5 -115
- package/dist/generation/diagnostics.d.ts.map +1 -1
- package/dist/generation/index.js +20 -77
- package/dist/generation/index.js.map +1 -1
- package/dist/index.cjs +189 -1458
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +108 -1347
- package/dist/index.js.map +1 -1
- package/dist/interfaces/value-extractor.d.ts +20 -0
- package/dist/interfaces/value-extractor.d.ts.map +1 -1
- package/dist/ir/explicit-parser.d.ts +2 -83
- package/dist/ir/explicit-parser.d.ts.map +1 -1
- package/dist/ir/explicit-renderer.d.ts +2 -31
- package/dist/ir/explicit-renderer.d.ts.map +1 -1
- package/dist/ir/index.js +89 -1260
- package/dist/ir/index.js.map +1 -1
- package/dist/ir/protocol-json.d.ts +2 -70
- package/dist/ir/protocol-json.d.ts.map +1 -1
- package/dist/ir/references.d.ts +2 -16
- package/dist/ir/references.d.ts.map +1 -1
- package/dist/ir/types.d.ts +2 -148
- package/dist/ir/types.d.ts.map +1 -1
- package/dist/parsing/index.js +19 -12
- package/dist/parsing/index.js.map +1 -1
- package/dist/schema/command-schema.d.ts +3 -92
- package/dist/schema/command-schema.d.ts.map +1 -1
- package/dist/schema/index.js +3 -20
- package/dist/schema/index.js.map +1 -1
- package/dist/testing/index.js +1066 -712
- package/dist/testing/index.js.map +1 -1
- package/package.json +6 -2
- package/src/core/types.ts +71 -600
- package/src/generation/diagnostics.ts +12 -233
- package/src/interfaces/value-extractor.ts +32 -0
- package/src/ir/explicit-parser.ts +12 -792
- package/src/ir/explicit-renderer.ts +2 -195
- package/src/ir/from-interchange.test.ts +91 -4
- package/src/ir/from-interchange.ts +59 -0
- package/src/ir/protocol-json.test.ts +16 -7
- package/src/ir/protocol-json.ts +9 -748
- package/src/ir/references.ts +2 -30
- package/src/ir/types.ts +18 -190
- package/src/schema/command-schema.ts +3 -134
package/dist/testing/index.js
CHANGED
|
@@ -2429,6 +2429,7 @@ function findPlugin(plugins2, val) {
|
|
|
2429
2429
|
return null;
|
|
2430
2430
|
}
|
|
2431
2431
|
function printer(val, config2, indentation, depth, refs, hasCalledToJSON) {
|
|
2432
|
+
var _a;
|
|
2432
2433
|
let result;
|
|
2433
2434
|
const plugin3 = findPlugin(config2.plugins, val);
|
|
2434
2435
|
if (plugin3 !== null) {
|
|
@@ -2441,8 +2442,9 @@ function printer(val, config2, indentation, depth, refs, hasCalledToJSON) {
|
|
|
2441
2442
|
result = printComplexValue(val, config2, indentation, depth, refs, hasCalledToJSON);
|
|
2442
2443
|
}
|
|
2443
2444
|
}
|
|
2444
|
-
config2.
|
|
2445
|
-
|
|
2445
|
+
(_a = config2._outputLengthPerDepth)[depth] ?? (_a[depth] = 0);
|
|
2446
|
+
config2._outputLengthPerDepth[depth] += result.length;
|
|
2447
|
+
if (config2._outputLengthPerDepth[depth] > config2.maxOutputLength) {
|
|
2446
2448
|
config2.maxDepth = 0;
|
|
2447
2449
|
}
|
|
2448
2450
|
return result;
|
|
@@ -2530,7 +2532,7 @@ function getConfig(options) {
|
|
|
2530
2532
|
spacingInner: options?.min ? " " : "\n",
|
|
2531
2533
|
spacingOuter: options?.min ? "" : "\n",
|
|
2532
2534
|
maxOutputLength: options?.maxOutputLength ?? DEFAULT_OPTIONS.maxOutputLength,
|
|
2533
|
-
|
|
2535
|
+
_outputLengthPerDepth: []
|
|
2534
2536
|
};
|
|
2535
2537
|
}
|
|
2536
2538
|
function createIndent(indent) {
|
|
@@ -4893,7 +4895,8 @@ var FALLBACK_FORMAT_OPTIONS = {
|
|
|
4893
4895
|
maxDepth: 8,
|
|
4894
4896
|
plugins: PLUGINS2
|
|
4895
4897
|
};
|
|
4896
|
-
|
|
4898
|
+
var DEFAULT_MEMORIZE = (_, v) => v;
|
|
4899
|
+
function diff(a, b2, options, memorize = DEFAULT_MEMORIZE) {
|
|
4897
4900
|
if (Object.is(a, b2)) {
|
|
4898
4901
|
return "";
|
|
4899
4902
|
}
|
|
@@ -4920,8 +4923,8 @@ function diff(a, b2, options) {
|
|
|
4920
4923
|
let aDisplay = format(a, formatOptions);
|
|
4921
4924
|
let bDisplay = format(b2, formatOptions);
|
|
4922
4925
|
const MAX_LENGTH = 1e5;
|
|
4923
|
-
aDisplay = truncate4(aDisplay);
|
|
4924
|
-
bDisplay = truncate4(bDisplay);
|
|
4926
|
+
aDisplay = memorize("expected", truncate4(aDisplay));
|
|
4927
|
+
bDisplay = memorize("actual", truncate4(bDisplay));
|
|
4925
4928
|
const aDiff = `${aColor(`${aIndicator} ${aAnnotation}:`)}
|
|
4926
4929
|
${aDisplay}`;
|
|
4927
4930
|
const bDiff = `${bColor(`${bIndicator} ${bAnnotation}:`)}
|
|
@@ -4938,18 +4941,24 @@ ${bDiff}`;
|
|
|
4938
4941
|
return diffLinesUnified(a.split("\n"), b2.split("\n"), options);
|
|
4939
4942
|
case "boolean":
|
|
4940
4943
|
case "number":
|
|
4941
|
-
return comparePrimitive(a, b2, options);
|
|
4944
|
+
return comparePrimitive(a, b2, options, memorize);
|
|
4942
4945
|
case "map":
|
|
4943
|
-
return compareObjects(sortMap(a), sortMap(b2), options);
|
|
4946
|
+
return compareObjects(sortMap(a), sortMap(b2), options, memorize);
|
|
4944
4947
|
case "set":
|
|
4945
|
-
return compareObjects(sortSet(a), sortSet(b2), options);
|
|
4948
|
+
return compareObjects(sortSet(a), sortSet(b2), options, memorize);
|
|
4946
4949
|
default:
|
|
4947
|
-
return compareObjects(a, b2, options);
|
|
4950
|
+
return compareObjects(a, b2, options, memorize);
|
|
4948
4951
|
}
|
|
4949
4952
|
}
|
|
4950
|
-
function
|
|
4951
|
-
|
|
4952
|
-
|
|
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));
|
|
4953
4962
|
return aFormat === bFormat ? "" : diffLinesUnified(aFormat.split("\n"), bFormat.split("\n"), options);
|
|
4954
4963
|
}
|
|
4955
4964
|
function sortMap(map2) {
|
|
@@ -4958,19 +4967,19 @@ function sortMap(map2) {
|
|
|
4958
4967
|
function sortSet(set3) {
|
|
4959
4968
|
return new Set(Array.from(set3.values()).sort());
|
|
4960
4969
|
}
|
|
4961
|
-
function compareObjects(a, b2, options) {
|
|
4970
|
+
function compareObjects(a, b2, options, memorize = DEFAULT_MEMORIZE) {
|
|
4962
4971
|
let difference;
|
|
4963
4972
|
let hasThrown = false;
|
|
4964
4973
|
try {
|
|
4965
4974
|
const formatOptions = getFormatOptions(FORMAT_OPTIONS, options);
|
|
4966
|
-
difference = getObjectsDifference(a, b2, formatOptions, options);
|
|
4975
|
+
difference = getObjectsDifference(a, b2, formatOptions, options, memorize);
|
|
4967
4976
|
} catch {
|
|
4968
4977
|
hasThrown = true;
|
|
4969
4978
|
}
|
|
4970
4979
|
const noDiffMessage = getCommonMessage(NO_DIFF_MESSAGE, options);
|
|
4971
4980
|
if (difference === void 0 || difference === noDiffMessage) {
|
|
4972
4981
|
const formatOptions = getFormatOptions(FALLBACK_FORMAT_OPTIONS, options);
|
|
4973
|
-
difference = getObjectsDifference(a, b2, formatOptions, options);
|
|
4982
|
+
difference = getObjectsDifference(a, b2, formatOptions, options, memorize);
|
|
4974
4983
|
if (difference !== noDiffMessage && !hasThrown) {
|
|
4975
4984
|
difference = `${getCommonMessage(SIMILAR_MESSAGE, options)}
|
|
4976
4985
|
|
|
@@ -4979,6 +4988,9 @@ ${difference}`;
|
|
|
4979
4988
|
}
|
|
4980
4989
|
return difference;
|
|
4981
4990
|
}
|
|
4991
|
+
function getDefaultFormatOptions(options) {
|
|
4992
|
+
return getFormatOptions(FORMAT_OPTIONS, options);
|
|
4993
|
+
}
|
|
4982
4994
|
function getFormatOptions(formatOptions, options) {
|
|
4983
4995
|
const { compareKeys, printBasicPrototype, maxDepth } = normalizeDiffOptions(options);
|
|
4984
4996
|
return {
|
|
@@ -4988,7 +5000,7 @@ function getFormatOptions(formatOptions, options) {
|
|
|
4988
5000
|
maxDepth: maxDepth ?? formatOptions.maxDepth
|
|
4989
5001
|
};
|
|
4990
5002
|
}
|
|
4991
|
-
function getObjectsDifference(a, b2, formatOptions, options) {
|
|
5003
|
+
function getObjectsDifference(a, b2, formatOptions, options, memorize = DEFAULT_MEMORIZE) {
|
|
4992
5004
|
const formatOptionsZeroIndent = {
|
|
4993
5005
|
...formatOptions,
|
|
4994
5006
|
indent: 0
|
|
@@ -4998,8 +5010,8 @@ function getObjectsDifference(a, b2, formatOptions, options) {
|
|
|
4998
5010
|
if (aCompare === bCompare) {
|
|
4999
5011
|
return getCommonMessage(NO_DIFF_MESSAGE, options);
|
|
5000
5012
|
} else {
|
|
5001
|
-
const aDisplay = format(a, formatOptions);
|
|
5002
|
-
const bDisplay = format(b2, formatOptions);
|
|
5013
|
+
const aDisplay = memorize("expected", format(a, formatOptions));
|
|
5014
|
+
const bDisplay = memorize("actual", format(b2, formatOptions));
|
|
5003
5015
|
return diffLinesUnified2(aDisplay.split("\n"), bDisplay.split("\n"), aCompare.split("\n"), bCompare.split("\n"), options);
|
|
5004
5016
|
}
|
|
5005
5017
|
}
|
|
@@ -5013,7 +5025,7 @@ function isReplaceable(obj1, obj2) {
|
|
|
5013
5025
|
const obj2Type = getType2(obj2);
|
|
5014
5026
|
return obj1Type === obj2Type && (obj1Type === "Object" || obj1Type === "Array");
|
|
5015
5027
|
}
|
|
5016
|
-
function printDiffOrStringify(received, expected, options) {
|
|
5028
|
+
function printDiffOrStringify(received, expected, options, memory) {
|
|
5017
5029
|
const { aAnnotation, bAnnotation } = normalizeDiffOptions(options);
|
|
5018
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) {
|
|
5019
5031
|
if (expected.includes("\n") || received.includes("\n")) {
|
|
@@ -5030,7 +5042,8 @@ ${receivedLine}`;
|
|
|
5030
5042
|
const clonedExpected = deepClone(expected, { forceWritable: true });
|
|
5031
5043
|
const clonedReceived = deepClone(received, { forceWritable: true });
|
|
5032
5044
|
const { replacedExpected, replacedActual } = replaceAsymmetricMatcher(clonedReceived, clonedExpected);
|
|
5033
|
-
const
|
|
5045
|
+
const memorize = memory ? createMemorize(memory) : DEFAULT_MEMORIZE;
|
|
5046
|
+
const difference = diff(replacedExpected, replacedActual, options, memorize);
|
|
5034
5047
|
return difference;
|
|
5035
5048
|
}
|
|
5036
5049
|
function replaceAsymmetricMatcher(actual, expected, actualReplaced = /* @__PURE__ */ new WeakSet(), expectedReplaced = /* @__PURE__ */ new WeakSet()) {
|
|
@@ -5223,16 +5236,13 @@ function processError(_err, diffOptions, seen = /* @__PURE__ */ new WeakSet()) {
|
|
|
5223
5236
|
}
|
|
5224
5237
|
const err = _err;
|
|
5225
5238
|
if (err.showDiff || err.showDiff === void 0 && err.expected !== void 0 && err.actual !== void 0) {
|
|
5226
|
-
|
|
5239
|
+
const options = {
|
|
5227
5240
|
...diffOptions,
|
|
5228
5241
|
...err.diffOptions
|
|
5229
|
-
}
|
|
5230
|
-
|
|
5231
|
-
|
|
5232
|
-
err.
|
|
5233
|
-
}
|
|
5234
|
-
if ("actual" in err && typeof err.actual !== "string") {
|
|
5235
|
-
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);
|
|
5236
5246
|
}
|
|
5237
5247
|
try {
|
|
5238
5248
|
if (!seen.has(err) && typeof err.cause === "object") {
|
|
@@ -5248,6 +5258,12 @@ function processError(_err, diffOptions, seen = /* @__PURE__ */ new WeakSet()) {
|
|
|
5248
5258
|
Inner error message: ${err?.message}`));
|
|
5249
5259
|
}
|
|
5250
5260
|
}
|
|
5261
|
+
function prettifyValue(value, options) {
|
|
5262
|
+
if (typeof value !== "string") {
|
|
5263
|
+
return format(value, getDefaultFormatOptions(options));
|
|
5264
|
+
}
|
|
5265
|
+
return value;
|
|
5266
|
+
}
|
|
5251
5267
|
|
|
5252
5268
|
// ../../node_modules/@vitest/utils/dist/timers.js
|
|
5253
5269
|
var SAFE_TIMERS_SYMBOL = Symbol("vitest:SAFE_TIMERS");
|
|
@@ -5556,8 +5572,8 @@ function originalPositionFor(map2, needle) {
|
|
|
5556
5572
|
function OMapping(source, line, column, name) {
|
|
5557
5573
|
return { source, line, column, name };
|
|
5558
5574
|
}
|
|
5559
|
-
function traceSegmentInternal(segments,
|
|
5560
|
-
let index2 = memoizedBinarySearch(segments, column,
|
|
5575
|
+
function traceSegmentInternal(segments, memo2, line, column, bias) {
|
|
5576
|
+
let index2 = memoizedBinarySearch(segments, column, memo2, line);
|
|
5561
5577
|
if (found) {
|
|
5562
5578
|
index2 = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index2);
|
|
5563
5579
|
} else if (bias === LEAST_UPPER_BOUND) index2++;
|
|
@@ -5706,7 +5722,7 @@ function parseSingleV8Stack(raw) {
|
|
|
5706
5722
|
function parseStacktrace(stack, options = {}) {
|
|
5707
5723
|
const { ignoreStackEntries = stackIgnorePatterns } = options;
|
|
5708
5724
|
let stacks = !CHROME_IE_STACK_REGEXP.test(stack) ? parseFFOrSafariStackTrace(stack) : parseV8Stacktrace(stack);
|
|
5709
|
-
const helperIndex = stacks.findLastIndex((s) => s.method
|
|
5725
|
+
const helperIndex = stacks.findLastIndex((s) => s.method.includes("__VITEST_HELPER__"));
|
|
5710
5726
|
if (helperIndex >= 0) {
|
|
5711
5727
|
stacks = stacks.slice(helperIndex + 1);
|
|
5712
5728
|
}
|
|
@@ -6057,7 +6073,7 @@ function withFixtures(fn2, options) {
|
|
|
6057
6073
|
const usedFixtures = [];
|
|
6058
6074
|
const usedProps = getUsedProps(fn2);
|
|
6059
6075
|
for (const fixture of registrations.values()) {
|
|
6060
|
-
if (fixture
|
|
6076
|
+
if (isAutoFixture(fixture, options) || usedProps.has(fixture.name)) {
|
|
6061
6077
|
usedFixtures.push(fixture);
|
|
6062
6078
|
}
|
|
6063
6079
|
}
|
|
@@ -6111,6 +6127,15 @@ function withFixtures(fn2, options) {
|
|
|
6111
6127
|
return fn2(context);
|
|
6112
6128
|
};
|
|
6113
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
|
+
}
|
|
6114
6139
|
function isFixtureFunction(value) {
|
|
6115
6140
|
return typeof value === "function";
|
|
6116
6141
|
}
|
|
@@ -6621,7 +6646,7 @@ function createSuiteCollector(name, factory = () => {
|
|
|
6621
6646
|
if (task2.mode === "run" && !handler) {
|
|
6622
6647
|
task2.mode = "todo";
|
|
6623
6648
|
}
|
|
6624
|
-
if (options.concurrent
|
|
6649
|
+
if (options.concurrent ?? (!options.sequential && runner.config.sequence.concurrent)) {
|
|
6625
6650
|
task2.concurrent = true;
|
|
6626
6651
|
}
|
|
6627
6652
|
task2.shuffle = suiteOptions?.shuffle;
|
|
@@ -7366,9 +7391,15 @@ function manageArtifactAttachment(attachment) {
|
|
|
7366
7391
|
if (attachment.body && attachment.path) {
|
|
7367
7392
|
throw new TypeError(`Test attachment requires only one of "body" or "path" to be set. Both are specified.`);
|
|
7368
7393
|
}
|
|
7394
|
+
if (attachment.path && attachment.bodyEncoding) {
|
|
7395
|
+
throw new TypeError(`Test attachment with "path" should not have "bodyEncoding" specified.`);
|
|
7396
|
+
}
|
|
7369
7397
|
if (attachment.body instanceof Uint8Array) {
|
|
7370
7398
|
attachment.body = encodeUint8Array(attachment.body);
|
|
7371
7399
|
}
|
|
7400
|
+
if (attachment.body != null) {
|
|
7401
|
+
attachment.bodyEncoding ?? (attachment.bodyEncoding = "base64");
|
|
7402
|
+
}
|
|
7372
7403
|
}
|
|
7373
7404
|
|
|
7374
7405
|
// ../../node_modules/vitest/dist/chunks/utils.BX5Fg8C4.js
|
|
@@ -9468,29 +9499,29 @@ function stringDistanceCapped(strA, strB, cap) {
|
|
|
9468
9499
|
if (Math.abs(strA.length - strB.length) >= cap) {
|
|
9469
9500
|
return cap;
|
|
9470
9501
|
}
|
|
9471
|
-
let
|
|
9502
|
+
let memo2 = [];
|
|
9472
9503
|
for (let i2 = 0; i2 <= strA.length; i2++) {
|
|
9473
|
-
|
|
9474
|
-
|
|
9504
|
+
memo2[i2] = Array(strB.length + 1).fill(0);
|
|
9505
|
+
memo2[i2][0] = i2;
|
|
9475
9506
|
}
|
|
9476
9507
|
for (let j = 0; j < strB.length; j++) {
|
|
9477
|
-
|
|
9508
|
+
memo2[0][j] = j;
|
|
9478
9509
|
}
|
|
9479
9510
|
for (let i2 = 1; i2 <= strA.length; i2++) {
|
|
9480
9511
|
let ch = strA.charCodeAt(i2 - 1);
|
|
9481
9512
|
for (let j = 1; j <= strB.length; j++) {
|
|
9482
9513
|
if (Math.abs(i2 - j) >= cap) {
|
|
9483
|
-
|
|
9514
|
+
memo2[i2][j] = cap;
|
|
9484
9515
|
continue;
|
|
9485
9516
|
}
|
|
9486
|
-
|
|
9487
|
-
|
|
9488
|
-
|
|
9489
|
-
|
|
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)
|
|
9490
9521
|
);
|
|
9491
9522
|
}
|
|
9492
9523
|
}
|
|
9493
|
-
return
|
|
9524
|
+
return memo2[strA.length][strB.length];
|
|
9494
9525
|
}
|
|
9495
9526
|
__name(stringDistanceCapped, "stringDistanceCapped");
|
|
9496
9527
|
function addMethod(ctx, name, method) {
|
|
@@ -13633,7 +13664,6 @@ function getMatcherState(assertion, expect2) {
|
|
|
13633
13664
|
}
|
|
13634
13665
|
const matcherState = {
|
|
13635
13666
|
...getState(expect2),
|
|
13636
|
-
task,
|
|
13637
13667
|
currentTestName,
|
|
13638
13668
|
customTesters: getCustomEqualityTesters(),
|
|
13639
13669
|
isNot,
|
|
@@ -13642,8 +13672,10 @@ function getMatcherState(assertion, expect2) {
|
|
|
13642
13672
|
equals,
|
|
13643
13673
|
suppressedErrors: [],
|
|
13644
13674
|
soft: utils_exports.flag(assertion, "soft"),
|
|
13645
|
-
poll: utils_exports.flag(assertion, "poll")
|
|
13675
|
+
poll: utils_exports.flag(assertion, "poll"),
|
|
13676
|
+
assertion
|
|
13646
13677
|
};
|
|
13678
|
+
Object.assign(matcherState, { task });
|
|
13647
13679
|
return {
|
|
13648
13680
|
state: matcherState,
|
|
13649
13681
|
isNot,
|
|
@@ -13652,36 +13684,47 @@ function getMatcherState(assertion, expect2) {
|
|
|
13652
13684
|
};
|
|
13653
13685
|
}
|
|
13654
13686
|
var JestExtendError = class extends Error {
|
|
13655
|
-
constructor(message, actual, expected) {
|
|
13687
|
+
constructor(message, actual, expected, __vitest_error_context__) {
|
|
13656
13688
|
super(message);
|
|
13657
13689
|
this.actual = actual;
|
|
13658
13690
|
this.expected = expected;
|
|
13691
|
+
this.__vitest_error_context__ = __vitest_error_context__;
|
|
13659
13692
|
}
|
|
13660
13693
|
};
|
|
13661
13694
|
function JestExtendPlugin(c, expect2, matchers) {
|
|
13662
13695
|
return (_, utils) => {
|
|
13663
13696
|
Object.entries(matchers).forEach(([expectAssertionName, expectAssertion]) => {
|
|
13664
|
-
function
|
|
13697
|
+
function __VITEST_EXTEND_ASSERTION__(...args) {
|
|
13665
13698
|
const { state, isNot, obj, customMessage } = getMatcherState(this, expect2);
|
|
13666
13699
|
const result = expectAssertion.call(state, obj, ...args);
|
|
13667
13700
|
if (result && typeof result === "object" && typeof result.then === "function") {
|
|
13668
13701
|
const thenable = result;
|
|
13669
|
-
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 }) => {
|
|
13670
13703
|
if (pass2 && isNot || !pass2 && !isNot) {
|
|
13671
|
-
const errorMessage = customMessage
|
|
13672
|
-
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
|
+
});
|
|
13673
13709
|
}
|
|
13674
13710
|
});
|
|
13675
13711
|
}
|
|
13676
|
-
const { pass, message, actual, expected } = result;
|
|
13712
|
+
const { pass, message, actual, expected, meta } = result;
|
|
13677
13713
|
if (pass && isNot || !pass && !isNot) {
|
|
13678
|
-
const errorMessage = customMessage
|
|
13679
|
-
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
|
+
});
|
|
13680
13719
|
}
|
|
13681
13720
|
}
|
|
13682
|
-
const softWrapper = wrapAssertion(utils, expectAssertionName,
|
|
13721
|
+
const softWrapper = wrapAssertion(utils, expectAssertionName, __VITEST_EXTEND_ASSERTION__);
|
|
13683
13722
|
utils.addMethod(globalThis[JEST_MATCHERS_OBJECT].matchers, expectAssertionName, softWrapper);
|
|
13684
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
|
+
}
|
|
13685
13728
|
class CustomMatcher extends AsymmetricMatcher3 {
|
|
13686
13729
|
constructor(inverse = false, ...sample) {
|
|
13687
13730
|
super(sample, inverse);
|
|
@@ -13760,157 +13803,59 @@ function offsetToLineNumber(source, offset) {
|
|
|
13760
13803
|
return line + 1;
|
|
13761
13804
|
}
|
|
13762
13805
|
|
|
13763
|
-
// ../../node_modules
|
|
13764
|
-
|
|
13765
|
-
|
|
13766
|
-
|
|
13767
|
-
|
|
13768
|
-
|
|
13769
|
-
|
|
13770
|
-
|
|
13771
|
-
|
|
13772
|
-
|
|
13773
|
-
|
|
13774
|
-
|
|
13775
|
-
|
|
13776
|
-
|
|
13777
|
-
|
|
13778
|
-
|
|
13779
|
-
|
|
13780
|
-
|
|
13781
|
-
|
|
13782
|
-
|
|
13783
|
-
|
|
13784
|
-
|
|
13785
|
-
|
|
13786
|
-
|
|
13787
|
-
|
|
13788
|
-
|
|
13789
|
-
return false;
|
|
13790
|
-
}
|
|
13791
|
-
_code = _code.slice(startMatch.index);
|
|
13792
|
-
let callEnd = getCallLastIndex(_code);
|
|
13793
|
-
if (callEnd === null) {
|
|
13794
|
-
return false;
|
|
13795
|
-
}
|
|
13796
|
-
callEnd += index2 + startMatch.index;
|
|
13797
|
-
const shapeStart = index2 + startMatch.index + startMatch[0].length;
|
|
13798
|
-
const shapeEnd = getObjectShapeEndIndex(code, shapeStart);
|
|
13799
|
-
const snap = `, ${prepareSnapString(newSnap, code, index2)}`;
|
|
13800
|
-
if (shapeEnd === callEnd) {
|
|
13801
|
-
s.appendLeft(callEnd, snap);
|
|
13802
|
-
} else {
|
|
13803
|
-
s.overwrite(shapeEnd, callEnd, snap);
|
|
13804
|
-
}
|
|
13805
|
-
return true;
|
|
13806
|
-
}
|
|
13807
|
-
function getObjectShapeEndIndex(code, index2) {
|
|
13808
|
-
let startBraces = 1;
|
|
13809
|
-
let endBraces = 0;
|
|
13810
|
-
while (startBraces !== endBraces && index2 < code.length) {
|
|
13811
|
-
const s = code[index2++];
|
|
13812
|
-
if (s === "{") {
|
|
13813
|
-
startBraces++;
|
|
13814
|
-
} else if (s === "}") {
|
|
13815
|
-
endBraces++;
|
|
13816
|
-
}
|
|
13817
|
-
}
|
|
13818
|
-
return index2;
|
|
13819
|
-
}
|
|
13820
|
-
function prepareSnapString(snap, source, index2) {
|
|
13821
|
-
const lineNumber = offsetToLineNumber(source, index2);
|
|
13822
|
-
const line = source.split(lineSplitRE)[lineNumber - 1];
|
|
13823
|
-
const indent = line.match(/^\s*/)[0] || "";
|
|
13824
|
-
const indentNext = indent.includes(" ") ? `${indent} ` : `${indent} `;
|
|
13825
|
-
const lines = snap.trim().replace(/\\/g, "\\\\").split(/\n/g);
|
|
13826
|
-
const isOneline = lines.length <= 1;
|
|
13827
|
-
const quote = "`";
|
|
13828
|
-
if (isOneline) {
|
|
13829
|
-
return `${quote}${lines.join("\n").replace(/`/g, "\\`").replace(/\$\{/g, "\\${")}${quote}`;
|
|
13830
|
-
}
|
|
13831
|
-
return `${quote}
|
|
13832
|
-
${lines.map((i2) => i2 ? indentNext + i2 : "").join("\n").replace(/`/g, "\\`").replace(/\$\{/g, "\\${")}
|
|
13833
|
-
${indent}${quote}`;
|
|
13834
|
-
}
|
|
13835
|
-
var toMatchInlineName = "toMatchInlineSnapshot";
|
|
13836
|
-
var toThrowErrorMatchingInlineName = "toThrowErrorMatchingInlineSnapshot";
|
|
13837
|
-
function getCodeStartingAtIndex(code, index2) {
|
|
13838
|
-
const indexInline = index2 - toMatchInlineName.length;
|
|
13839
|
-
if (code.slice(indexInline, index2) === toMatchInlineName) {
|
|
13840
|
-
return {
|
|
13841
|
-
code: code.slice(indexInline),
|
|
13842
|
-
index: indexInline
|
|
13843
|
-
};
|
|
13844
|
-
}
|
|
13845
|
-
const indexThrowInline = index2 - toThrowErrorMatchingInlineName.length;
|
|
13846
|
-
if (code.slice(index2 - indexThrowInline, index2) === toThrowErrorMatchingInlineName) {
|
|
13847
|
-
return {
|
|
13848
|
-
code: code.slice(index2 - indexThrowInline),
|
|
13849
|
-
index: index2 - indexThrowInline
|
|
13850
|
-
};
|
|
13851
|
-
}
|
|
13852
|
-
return {
|
|
13853
|
-
code: code.slice(index2),
|
|
13854
|
-
index: index2
|
|
13855
|
-
};
|
|
13856
|
-
}
|
|
13857
|
-
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$]*(['"`)])/;
|
|
13858
|
-
function replaceInlineSnap(code, s, currentIndex, newSnap) {
|
|
13859
|
-
const { code: codeStartingAtIndex, index: index2 } = getCodeStartingAtIndex(code, currentIndex);
|
|
13860
|
-
const startMatch = startRegex.exec(codeStartingAtIndex);
|
|
13861
|
-
const firstKeywordMatch = /toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot/.exec(codeStartingAtIndex);
|
|
13862
|
-
if (!startMatch || startMatch.index !== firstKeywordMatch?.index) {
|
|
13863
|
-
return replaceObjectSnap(code, s, index2, newSnap);
|
|
13864
|
-
}
|
|
13865
|
-
const quote = startMatch[1];
|
|
13866
|
-
const startIndex = index2 + startMatch.index + startMatch[0].length;
|
|
13867
|
-
const snapString = prepareSnapString(newSnap, code, index2);
|
|
13868
|
-
if (quote === ")") {
|
|
13869
|
-
s.appendRight(startIndex - 1, snapString);
|
|
13870
|
-
return true;
|
|
13871
|
-
}
|
|
13872
|
-
const quoteEndRE = new RegExp(`(?:^|[^\\\\])${quote}`);
|
|
13873
|
-
const endMatch = quoteEndRE.exec(code.slice(startIndex));
|
|
13874
|
-
if (!endMatch) {
|
|
13875
|
-
return false;
|
|
13876
|
-
}
|
|
13877
|
-
const endIndex = startIndex + endMatch.index + endMatch[0].length;
|
|
13878
|
-
s.overwrite(startIndex - 1, endIndex, snapString);
|
|
13879
|
-
return true;
|
|
13880
|
-
}
|
|
13881
|
-
var INDENTATION_REGEX = /^([^\S\n]*)\S/m;
|
|
13882
|
-
function stripSnapshotIndentation(inlineSnapshot) {
|
|
13883
|
-
const match = inlineSnapshot.match(INDENTATION_REGEX);
|
|
13884
|
-
if (!match || !match[1]) {
|
|
13885
|
-
return inlineSnapshot;
|
|
13886
|
-
}
|
|
13887
|
-
const indentation = match[1];
|
|
13888
|
-
const lines = inlineSnapshot.split(/\n/g);
|
|
13889
|
-
if (lines.length <= 2) {
|
|
13890
|
-
return inlineSnapshot;
|
|
13891
|
-
}
|
|
13892
|
-
if (lines[0].trim() !== "" || lines.at(-1)?.trim() !== "") {
|
|
13893
|
-
return inlineSnapshot;
|
|
13894
|
-
}
|
|
13895
|
-
for (let i2 = 1; i2 < lines.length - 1; i2++) {
|
|
13896
|
-
if (lines[i2] !== "") {
|
|
13897
|
-
if (lines[i2].indexOf(indentation) !== 0) {
|
|
13898
|
-
return inlineSnapshot;
|
|
13899
|
-
}
|
|
13900
|
-
lines[i2] = lines[i2].substring(indentation.length);
|
|
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;
|
|
13901
13832
|
}
|
|
13833
|
+
Object.setPrototypeOf(date, _MockDate.prototype);
|
|
13834
|
+
return date;
|
|
13902
13835
|
}
|
|
13903
|
-
|
|
13904
|
-
|
|
13905
|
-
|
|
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();
|
|
13906
13852
|
}
|
|
13907
|
-
|
|
13908
|
-
|
|
13909
|
-
if (!snap.readonly) {
|
|
13910
|
-
await environment.saveSnapshotFile(snap.file, snap.snapshot);
|
|
13911
|
-
}
|
|
13912
|
-
}));
|
|
13853
|
+
function resetDate() {
|
|
13854
|
+
globalThis.Date = RealDate;
|
|
13913
13855
|
}
|
|
13856
|
+
var { get: get2 } = Reflect;
|
|
13857
|
+
|
|
13858
|
+
// ../../node_modules/@vitest/snapshot/dist/index.js
|
|
13914
13859
|
function getDefaultExportFromCjs3(x) {
|
|
13915
13860
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
13916
13861
|
}
|
|
@@ -14131,64 +14076,234 @@ var CounterMap = class extends DefaultMap {
|
|
|
14131
14076
|
return total;
|
|
14132
14077
|
}
|
|
14133
14078
|
};
|
|
14134
|
-
|
|
14135
|
-
|
|
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
|
+
};
|
|
14136
14088
|
}
|
|
14137
|
-
|
|
14138
|
-
|
|
14139
|
-
|
|
14140
|
-
|
|
14141
|
-
|
|
14142
|
-
|
|
14143
|
-
|
|
14144
|
-
|
|
14145
|
-
|
|
14146
|
-
|
|
14147
|
-
|
|
14148
|
-
|
|
14149
|
-
|
|
14150
|
-
|
|
14151
|
-
|
|
14152
|
-
|
|
14153
|
-
|
|
14154
|
-
|
|
14155
|
-
|
|
14156
|
-
|
|
14157
|
-
|
|
14158
|
-
|
|
14159
|
-
|
|
14160
|
-
|
|
14161
|
-
|
|
14162
|
-
|
|
14163
|
-
|
|
14164
|
-
|
|
14165
|
-
|
|
14166
|
-
|
|
14167
|
-
|
|
14168
|
-
|
|
14169
|
-
|
|
14170
|
-
|
|
14171
|
-
|
|
14172
|
-
|
|
14173
|
-
|
|
14174
|
-
|
|
14175
|
-
|
|
14176
|
-
|
|
14177
|
-
|
|
14178
|
-
|
|
14179
|
-
|
|
14180
|
-
|
|
14181
|
-
|
|
14182
|
-
|
|
14183
|
-
|
|
14184
|
-
|
|
14185
|
-
|
|
14186
|
-
|
|
14187
|
-
|
|
14188
|
-
|
|
14189
|
-
|
|
14190
|
-
|
|
14191
|
-
|
|
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
|
+
}
|
|
14248
|
+
function isSameStackPosition(x, y2) {
|
|
14249
|
+
return x.file === y2.file && x.column === y2.column && x.line === y2.line;
|
|
14250
|
+
}
|
|
14251
|
+
var SnapshotState = class _SnapshotState {
|
|
14252
|
+
constructor(testFilePath, snapshotPath, snapshotContent, options) {
|
|
14253
|
+
__publicField(this, "_counters", new CounterMap());
|
|
14254
|
+
__publicField(this, "_dirty");
|
|
14255
|
+
__publicField(this, "_updateSnapshot");
|
|
14256
|
+
__publicField(this, "_snapshotData");
|
|
14257
|
+
__publicField(this, "_initialData");
|
|
14258
|
+
__publicField(this, "_inlineSnapshots");
|
|
14259
|
+
__publicField(this, "_inlineSnapshotStacks");
|
|
14260
|
+
__publicField(this, "_testIdToKeys", new DefaultMap(() => []));
|
|
14261
|
+
__publicField(this, "_rawSnapshots");
|
|
14262
|
+
__publicField(this, "_uncheckedKeys");
|
|
14263
|
+
__publicField(this, "_snapshotFormat");
|
|
14264
|
+
__publicField(this, "_environment");
|
|
14265
|
+
__publicField(this, "_fileExists");
|
|
14266
|
+
__publicField(this, "expand");
|
|
14267
|
+
// getter/setter for jest-image-snapshot compat
|
|
14268
|
+
// https://github.com/vitest-dev/vitest/issues/7322
|
|
14269
|
+
__publicField(this, "_added", new CounterMap());
|
|
14270
|
+
__publicField(this, "_matched", new CounterMap());
|
|
14271
|
+
__publicField(this, "_unmatched", new CounterMap());
|
|
14272
|
+
__publicField(this, "_updated", new CounterMap());
|
|
14273
|
+
this.testFilePath = testFilePath;
|
|
14274
|
+
this.snapshotPath = snapshotPath;
|
|
14275
|
+
const { data, dirty } = getSnapshotData(snapshotContent, options);
|
|
14276
|
+
this._fileExists = snapshotContent != null;
|
|
14277
|
+
this._initialData = { ...data };
|
|
14278
|
+
this._snapshotData = { ...data };
|
|
14279
|
+
this._dirty = dirty;
|
|
14280
|
+
this._inlineSnapshots = [];
|
|
14281
|
+
this._inlineSnapshotStacks = [];
|
|
14282
|
+
this._rawSnapshots = [];
|
|
14283
|
+
this._uncheckedKeys = new Set(Object.keys(this._snapshotData));
|
|
14284
|
+
this.expand = options.expand || false;
|
|
14285
|
+
this._updateSnapshot = options.updateSnapshot;
|
|
14286
|
+
this._snapshotFormat = {
|
|
14287
|
+
printBasicPrototype: false,
|
|
14288
|
+
escapeString: false,
|
|
14289
|
+
maxOutputLength: 2 ** 27,
|
|
14290
|
+
...options.snapshotFormat
|
|
14291
|
+
};
|
|
14292
|
+
this._environment = options.snapshotEnvironment;
|
|
14293
|
+
}
|
|
14294
|
+
get added() {
|
|
14295
|
+
return this._added;
|
|
14296
|
+
}
|
|
14297
|
+
set added(value) {
|
|
14298
|
+
this._added._total = value;
|
|
14299
|
+
}
|
|
14300
|
+
get matched() {
|
|
14301
|
+
return this._matched;
|
|
14302
|
+
}
|
|
14303
|
+
set matched(value) {
|
|
14304
|
+
this._matched._total = value;
|
|
14305
|
+
}
|
|
14306
|
+
get unmatched() {
|
|
14192
14307
|
return this._unmatched;
|
|
14193
14308
|
}
|
|
14194
14309
|
set unmatched(value) {
|
|
@@ -14205,6 +14320,9 @@ var SnapshotState = class _SnapshotState {
|
|
|
14205
14320
|
const content = await options.snapshotEnvironment.readSnapshotFile(snapshotPath);
|
|
14206
14321
|
return new _SnapshotState(testFilePath, snapshotPath, content, options);
|
|
14207
14322
|
}
|
|
14323
|
+
get snapshotUpdateState() {
|
|
14324
|
+
return this._updateSnapshot;
|
|
14325
|
+
}
|
|
14208
14326
|
get environment() {
|
|
14209
14327
|
return this._environment;
|
|
14210
14328
|
}
|
|
@@ -14239,12 +14357,20 @@ var SnapshotState = class _SnapshotState {
|
|
|
14239
14357
|
if (promiseIndex !== -1) {
|
|
14240
14358
|
return stacks[promiseIndex + 3];
|
|
14241
14359
|
}
|
|
14360
|
+
const pollChainIndex = stacks.findIndex((i2) => i2.method.match(/__VITEST_POLL_CHAIN__/));
|
|
14361
|
+
if (pollChainIndex !== -1) {
|
|
14362
|
+
return stacks[pollChainIndex + 1];
|
|
14363
|
+
}
|
|
14242
14364
|
for (let i2 = 0; i2 < stacks.length; i2++) {
|
|
14243
14365
|
const match = stacks[i2].method.match(/__INLINE_SNAPSHOT_OFFSET_(\d+)__/);
|
|
14244
14366
|
if (match) {
|
|
14245
14367
|
return stacks[i2 + Number(match[1])] ?? null;
|
|
14246
14368
|
}
|
|
14247
14369
|
}
|
|
14370
|
+
const customMatcherIndex = stacks.findIndex((i2) => i2.method.includes("__VITEST_EXTEND_ASSERTION__"));
|
|
14371
|
+
if (customMatcherIndex !== -1) {
|
|
14372
|
+
return stacks[customMatcherIndex + 3] ?? null;
|
|
14373
|
+
}
|
|
14248
14374
|
const stackIndex = stacks.findIndex((i2) => i2.method.includes("__INLINE_SNAPSHOT__"));
|
|
14249
14375
|
return stackIndex !== -1 ? stacks[stackIndex + 2] : null;
|
|
14250
14376
|
}
|
|
@@ -14252,9 +14378,10 @@ var SnapshotState = class _SnapshotState {
|
|
|
14252
14378
|
this._dirty = true;
|
|
14253
14379
|
if (options.stack) {
|
|
14254
14380
|
this._inlineSnapshots.push({
|
|
14381
|
+
...options.stack,
|
|
14255
14382
|
snapshot: receivedSerialized,
|
|
14256
14383
|
testId: options.testId,
|
|
14257
|
-
|
|
14384
|
+
assertionName: options.assertionName
|
|
14258
14385
|
});
|
|
14259
14386
|
} else if (options.rawSnapshot) {
|
|
14260
14387
|
this._rawSnapshots.push({
|
|
@@ -14265,6 +14392,103 @@ var SnapshotState = class _SnapshotState {
|
|
|
14265
14392
|
this._snapshotData[key] = receivedSerialized;
|
|
14266
14393
|
}
|
|
14267
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
|
+
}
|
|
14268
14492
|
async save() {
|
|
14269
14493
|
const hasExternalSnapshots = Object.keys(this._snapshotData).length;
|
|
14270
14494
|
const hasInlineSnapshots = this._inlineSnapshots.length;
|
|
@@ -14308,13 +14532,24 @@ var SnapshotState = class _SnapshotState {
|
|
|
14308
14532
|
this._uncheckedKeys.clear();
|
|
14309
14533
|
}
|
|
14310
14534
|
}
|
|
14311
|
-
|
|
14312
|
-
this._counters.
|
|
14313
|
-
const
|
|
14314
|
-
|
|
14315
|
-
key
|
|
14316
|
-
|
|
14317
|
-
|
|
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;
|
|
14318
14553
|
if (!(isInline && this._snapshotData[key] !== void 0)) {
|
|
14319
14554
|
this._uncheckedKeys.delete(key);
|
|
14320
14555
|
}
|
|
@@ -14335,85 +14570,49 @@ var SnapshotState = class _SnapshotState {
|
|
|
14335
14570
|
if (pass && !isInline && !rawSnapshot) {
|
|
14336
14571
|
this._snapshotData[key] = receivedSerialized;
|
|
14337
14572
|
}
|
|
14338
|
-
|
|
14339
|
-
|
|
14340
|
-
|
|
14341
|
-
|
|
14342
|
-
|
|
14343
|
-
|
|
14344
|
-
|
|
14345
|
-
|
|
14346
|
-
|
|
14347
|
-
|
|
14348
|
-
|
|
14349
|
-
|
|
14350
|
-
|
|
14351
|
-
|
|
14352
|
-
|
|
14353
|
-
|
|
14354
|
-
|
|
14355
|
-
|
|
14356
|
-
|
|
14357
|
-
|
|
14358
|
-
|
|
14359
|
-
|
|
14360
|
-
|
|
14361
|
-
|
|
14362
|
-
|
|
14363
|
-
|
|
14364
|
-
|
|
14365
|
-
|
|
14366
|
-
|
|
14367
|
-
|
|
14368
|
-
|
|
14369
|
-
|
|
14370
|
-
|
|
14371
|
-
|
|
14372
|
-
|
|
14373
|
-
|
|
14374
|
-
|
|
14375
|
-
|
|
14376
|
-
|
|
14377
|
-
|
|
14378
|
-
|
|
14379
|
-
|
|
14380
|
-
|
|
14381
|
-
} else {
|
|
14382
|
-
this._addSnapshot(key, receivedSerialized, {
|
|
14383
|
-
stack,
|
|
14384
|
-
testId,
|
|
14385
|
-
rawSnapshot
|
|
14386
|
-
});
|
|
14387
|
-
this.added.increment(testId);
|
|
14388
|
-
}
|
|
14389
|
-
return {
|
|
14390
|
-
actual: "",
|
|
14391
|
-
count,
|
|
14392
|
-
expected: "",
|
|
14393
|
-
key,
|
|
14394
|
-
pass: true
|
|
14395
|
-
};
|
|
14396
|
-
} else {
|
|
14397
|
-
if (!pass) {
|
|
14398
|
-
this.unmatched.increment(testId);
|
|
14399
|
-
return {
|
|
14400
|
-
actual: rawSnapshot ? receivedSerialized : removeExtraLineBreaks(receivedSerialized),
|
|
14401
|
-
count,
|
|
14402
|
-
expected: expectedTrimmed !== void 0 ? rawSnapshot ? expectedTrimmed : removeExtraLineBreaks(expectedTrimmed) : void 0,
|
|
14403
|
-
key,
|
|
14404
|
-
pass: false
|
|
14405
|
-
};
|
|
14406
|
-
} else {
|
|
14407
|
-
this.matched.increment(testId);
|
|
14408
|
-
return {
|
|
14409
|
-
actual: "",
|
|
14410
|
-
count,
|
|
14411
|
-
expected: "",
|
|
14412
|
-
key,
|
|
14413
|
-
pass: true
|
|
14414
|
-
};
|
|
14415
|
-
}
|
|
14416
|
-
}
|
|
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
|
+
});
|
|
14417
14616
|
}
|
|
14418
14617
|
async pack() {
|
|
14419
14618
|
const snapshot = {
|
|
@@ -14491,30 +14690,43 @@ var SnapshotClient = class {
|
|
|
14491
14690
|
}
|
|
14492
14691
|
return state;
|
|
14493
14692
|
}
|
|
14494
|
-
|
|
14495
|
-
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;
|
|
14496
14695
|
let { received } = options;
|
|
14497
14696
|
if (!filepath) {
|
|
14498
14697
|
throw new Error("Snapshot cannot be used outside of test");
|
|
14499
14698
|
}
|
|
14500
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
|
+
});
|
|
14501
14707
|
if (typeof properties === "object") {
|
|
14502
14708
|
if (typeof received !== "object" || !received) {
|
|
14709
|
+
expectedSnapshot.markAsChecked();
|
|
14503
14710
|
throw new Error("Received value must be an object when the matcher has properties");
|
|
14504
14711
|
}
|
|
14712
|
+
let propertiesPass;
|
|
14505
14713
|
try {
|
|
14506
|
-
|
|
14507
|
-
if (!pass2) {
|
|
14508
|
-
throw createMismatchError("Snapshot properties mismatched", snapshotState.expand, received, properties);
|
|
14509
|
-
} else {
|
|
14510
|
-
received = deepMergeSnapshot(received, properties);
|
|
14511
|
-
}
|
|
14714
|
+
propertiesPass = this.options.isEqual?.(received, properties) ?? false;
|
|
14512
14715
|
} catch (err) {
|
|
14513
|
-
|
|
14716
|
+
expectedSnapshot.markAsChecked();
|
|
14514
14717
|
throw err;
|
|
14515
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);
|
|
14516
14729
|
}
|
|
14517
|
-
const testName2 = [name, ...message ? [message] : []].join(" > ");
|
|
14518
14730
|
const { actual, expected, key, pass } = snapshotState.match({
|
|
14519
14731
|
testId,
|
|
14520
14732
|
testName: testName2,
|
|
@@ -14522,11 +14734,104 @@ var SnapshotClient = class {
|
|
|
14522
14734
|
isInline,
|
|
14523
14735
|
error,
|
|
14524
14736
|
inlineSnapshot,
|
|
14525
|
-
rawSnapshot
|
|
14737
|
+
rawSnapshot,
|
|
14738
|
+
assertionName
|
|
14526
14739
|
});
|
|
14527
|
-
|
|
14528
|
-
|
|
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);
|
|
14752
|
+
}
|
|
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");
|
|
14529
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
|
+
};
|
|
14530
14835
|
}
|
|
14531
14836
|
async assertRaw(options) {
|
|
14532
14837
|
if (!options.rawSnapshot) {
|
|
@@ -14548,363 +14853,60 @@ var SnapshotClient = class {
|
|
|
14548
14853
|
this.snapshotStateMap.clear();
|
|
14549
14854
|
}
|
|
14550
14855
|
};
|
|
14551
|
-
|
|
14552
|
-
|
|
14553
|
-
|
|
14554
|
-
|
|
14555
|
-
|
|
14556
|
-
|
|
14557
|
-
|
|
14558
|
-
|
|
14559
|
-
constructor(y2, m, d2, h, M, s, ms) {
|
|
14560
|
-
super();
|
|
14561
|
-
let date;
|
|
14562
|
-
switch (arguments.length) {
|
|
14563
|
-
case 0:
|
|
14564
|
-
if (now2 !== null) date = new RealDate(now2.valueOf());
|
|
14565
|
-
else date = new RealDate();
|
|
14566
|
-
break;
|
|
14567
|
-
case 1:
|
|
14568
|
-
date = new RealDate(y2);
|
|
14569
|
-
break;
|
|
14570
|
-
default:
|
|
14571
|
-
d2 = typeof d2 === "undefined" ? 1 : d2;
|
|
14572
|
-
h = h || 0;
|
|
14573
|
-
M = M || 0;
|
|
14574
|
-
s = s || 0;
|
|
14575
|
-
ms = ms || 0;
|
|
14576
|
-
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) {
|
|
14577
14864
|
break;
|
|
14578
|
-
|
|
14579
|
-
|
|
14580
|
-
|
|
14581
|
-
|
|
14582
|
-
|
|
14583
|
-
|
|
14584
|
-
|
|
14585
|
-
return new MockDate().valueOf();
|
|
14586
|
-
};
|
|
14587
|
-
MockDate.parse = function(dateString) {
|
|
14588
|
-
return RealDate.parse(dateString);
|
|
14589
|
-
};
|
|
14590
|
-
MockDate.toString = function() {
|
|
14591
|
-
return RealDate.toString();
|
|
14592
|
-
};
|
|
14593
|
-
function mockDate(date) {
|
|
14594
|
-
const dateObj = new RealDate(date.valueOf());
|
|
14595
|
-
if (Number.isNaN(dateObj.getTime())) throw new TypeError(`mockdate: The time set is an invalid date: ${date}`);
|
|
14596
|
-
globalThis.Date = MockDate;
|
|
14597
|
-
now2 = dateObj.valueOf();
|
|
14598
|
-
}
|
|
14599
|
-
function resetDate() {
|
|
14600
|
-
globalThis.Date = RealDate;
|
|
14601
|
-
}
|
|
14602
|
-
var { get: get2 } = Reflect;
|
|
14603
|
-
|
|
14604
|
-
// ../../node_modules/vitest/dist/chunks/test.CBQUpOM3.js
|
|
14605
|
-
var unsupported = [
|
|
14606
|
-
"matchSnapshot",
|
|
14607
|
-
"toMatchSnapshot",
|
|
14608
|
-
"toMatchInlineSnapshot",
|
|
14609
|
-
"toThrowErrorMatchingSnapshot",
|
|
14610
|
-
"toThrowErrorMatchingInlineSnapshot",
|
|
14611
|
-
"throws",
|
|
14612
|
-
"Throw",
|
|
14613
|
-
"throw",
|
|
14614
|
-
"toThrow",
|
|
14615
|
-
"toThrowError"
|
|
14616
|
-
];
|
|
14617
|
-
function throwWithCause(error, source) {
|
|
14618
|
-
if (error.cause == null) error.cause = /* @__PURE__ */ new Error("Matcher did not succeed in time.");
|
|
14619
|
-
throw copyStackTrace$1(error, source);
|
|
14620
|
-
}
|
|
14621
|
-
function createExpectPoll(expect2) {
|
|
14622
|
-
return function poll(fn2, options = {}) {
|
|
14623
|
-
const defaults = getWorkerState().config.expect?.poll ?? {};
|
|
14624
|
-
const { interval = defaults.interval ?? 50, timeout = defaults.timeout ?? 1e3, message } = options;
|
|
14625
|
-
const assertion = expect2(null, message).withContext({ poll: true });
|
|
14626
|
-
fn2 = fn2.bind(assertion);
|
|
14627
|
-
const test5 = chai_exports.util.flag(assertion, "vitest-test");
|
|
14628
|
-
if (!test5) throw new Error("expect.poll() must be called inside a test");
|
|
14629
|
-
const proxy = new Proxy(assertion, { get(target, key, receiver) {
|
|
14630
|
-
const assertionFunction = Reflect.get(target, key, receiver);
|
|
14631
|
-
if (typeof assertionFunction !== "function") return assertionFunction instanceof chai_exports.Assertion ? proxy : assertionFunction;
|
|
14632
|
-
if (key === "assert") return assertionFunction;
|
|
14633
|
-
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.`);
|
|
14634
|
-
return function(...args) {
|
|
14635
|
-
const STACK_TRACE_ERROR = /* @__PURE__ */ new Error("STACK_TRACE_ERROR");
|
|
14636
|
-
const promise = async () => {
|
|
14637
|
-
const { setTimeout: setTimeout3, clearTimeout: clearTimeout3 } = getSafeTimers();
|
|
14638
|
-
let executionPhase = "fn";
|
|
14639
|
-
let hasTimedOut = false;
|
|
14640
|
-
const timerId = setTimeout3(() => {
|
|
14641
|
-
hasTimedOut = true;
|
|
14642
|
-
}, timeout);
|
|
14643
|
-
chai_exports.util.flag(assertion, "_name", key);
|
|
14644
|
-
const onSettled = chai_exports.util.flag(assertion, "_poll.onSettled");
|
|
14645
|
-
try {
|
|
14646
|
-
while (true) {
|
|
14647
|
-
const isLastAttempt = hasTimedOut;
|
|
14648
|
-
if (isLastAttempt) chai_exports.util.flag(assertion, "_isLastPollAttempt", true);
|
|
14649
|
-
try {
|
|
14650
|
-
executionPhase = "fn";
|
|
14651
|
-
const obj = await fn2();
|
|
14652
|
-
chai_exports.util.flag(assertion, "object", obj);
|
|
14653
|
-
executionPhase = "assertion";
|
|
14654
|
-
const output = await assertionFunction.call(assertion, ...args);
|
|
14655
|
-
await onSettled?.({
|
|
14656
|
-
assertion,
|
|
14657
|
-
status: "pass"
|
|
14658
|
-
});
|
|
14659
|
-
return output;
|
|
14660
|
-
} catch (err) {
|
|
14661
|
-
if (isLastAttempt || executionPhase === "assertion" && chai_exports.util.flag(assertion, "_poll.assert_once")) {
|
|
14662
|
-
await onSettled?.({
|
|
14663
|
-
assertion,
|
|
14664
|
-
status: "fail"
|
|
14665
|
-
});
|
|
14666
|
-
throwWithCause(err, STACK_TRACE_ERROR);
|
|
14667
|
-
}
|
|
14668
|
-
await delay(interval, setTimeout3);
|
|
14669
|
-
}
|
|
14670
|
-
}
|
|
14671
|
-
} finally {
|
|
14672
|
-
clearTimeout3(timerId);
|
|
14673
|
-
}
|
|
14674
|
-
};
|
|
14675
|
-
let awaited = false;
|
|
14676
|
-
test5.onFinished ?? (test5.onFinished = []);
|
|
14677
|
-
test5.onFinished.push(() => {
|
|
14678
|
-
if (!awaited) {
|
|
14679
|
-
const negated = chai_exports.util.flag(assertion, "negate") ? "not." : "";
|
|
14680
|
-
const assertionString = `expect.${chai_exports.util.flag(assertion, "_poll.element") ? "element(locator)" : "poll(assertion)"}.${negated}${String(key)}()`;
|
|
14681
|
-
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:
|
|
14682
|
-
|
|
14683
|
-
await ${assertionString}
|
|
14684
|
-
`), STACK_TRACE_ERROR);
|
|
14685
|
-
}
|
|
14686
|
-
});
|
|
14687
|
-
let resultPromise;
|
|
14688
|
-
return {
|
|
14689
|
-
then(onFulfilled, onRejected) {
|
|
14690
|
-
awaited = true;
|
|
14691
|
-
return (resultPromise || (resultPromise = promise())).then(onFulfilled, onRejected);
|
|
14692
|
-
},
|
|
14693
|
-
catch(onRejected) {
|
|
14694
|
-
awaited = true;
|
|
14695
|
-
return (resultPromise || (resultPromise = promise())).catch(onRejected);
|
|
14696
|
-
},
|
|
14697
|
-
finally(onFinally) {
|
|
14698
|
-
awaited = true;
|
|
14699
|
-
return (resultPromise || (resultPromise = promise())).finally(onFinally);
|
|
14700
|
-
},
|
|
14701
|
-
[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
|
|
14702
14872
|
};
|
|
14703
|
-
|
|
14704
|
-
|
|
14705
|
-
|
|
14706
|
-
|
|
14707
|
-
|
|
14708
|
-
|
|
14709
|
-
|
|
14710
|
-
|
|
14711
|
-
|
|
14712
|
-
|
|
14713
|
-
|
|
14714
|
-
|
|
14715
|
-
|
|
14716
|
-
|
|
14717
|
-
|
|
14718
|
-
}
|
|
14719
|
-
function getError(expected, promise) {
|
|
14720
|
-
if (typeof expected !== "function") {
|
|
14721
|
-
if (!promise) throw new Error(`expected must be a function, received ${typeof expected}`);
|
|
14722
|
-
return expected;
|
|
14723
|
-
}
|
|
14724
|
-
try {
|
|
14725
|
-
expected();
|
|
14726
|
-
} catch (e) {
|
|
14727
|
-
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
|
+
}
|
|
14728
14889
|
}
|
|
14729
|
-
throw new Error("snapshot function didn't throw");
|
|
14730
|
-
}
|
|
14731
|
-
function getTestNames(test5) {
|
|
14732
14890
|
return {
|
|
14733
|
-
|
|
14734
|
-
|
|
14735
|
-
testId: test5.id
|
|
14891
|
+
...lastStable,
|
|
14892
|
+
lastPollError
|
|
14736
14893
|
};
|
|
14737
14894
|
}
|
|
14738
|
-
|
|
14739
|
-
|
|
14740
|
-
|
|
14741
|
-
|
|
14742
|
-
|
|
14743
|
-
|
|
14744
|
-
|
|
14745
|
-
utils.flag(this, "_name", key);
|
|
14746
|
-
if (utils.flag(this, "negate")) throw new Error(`${key} cannot be used with "not"`);
|
|
14747
|
-
const expected = utils.flag(this, "object");
|
|
14748
|
-
const test5 = getTest(key, this);
|
|
14749
|
-
if (typeof properties === "string" && typeof message === "undefined") {
|
|
14750
|
-
message = properties;
|
|
14751
|
-
properties = void 0;
|
|
14752
|
-
}
|
|
14753
|
-
const errorMessage = utils.flag(this, "message");
|
|
14754
|
-
getSnapshotClient().assert({
|
|
14755
|
-
received: expected,
|
|
14756
|
-
message,
|
|
14757
|
-
isInline: false,
|
|
14758
|
-
properties,
|
|
14759
|
-
errorMessage,
|
|
14760
|
-
...getTestNames(test5)
|
|
14761
|
-
});
|
|
14762
|
-
}));
|
|
14763
|
-
utils.addMethod(chai.Assertion.prototype, "toMatchFileSnapshot", function(file, message) {
|
|
14764
|
-
utils.flag(this, "_name", "toMatchFileSnapshot");
|
|
14765
|
-
if (utils.flag(this, "negate")) throw new Error('toMatchFileSnapshot cannot be used with "not"');
|
|
14766
|
-
const error = /* @__PURE__ */ new Error("resolves");
|
|
14767
|
-
const expected = utils.flag(this, "object");
|
|
14768
|
-
const test5 = getTest("toMatchFileSnapshot", this);
|
|
14769
|
-
const errorMessage = utils.flag(this, "message");
|
|
14770
|
-
return recordAsyncExpect(test5, getSnapshotClient().assertRaw({
|
|
14771
|
-
received: expected,
|
|
14772
|
-
message,
|
|
14773
|
-
isInline: false,
|
|
14774
|
-
rawSnapshot: { file },
|
|
14775
|
-
errorMessage,
|
|
14776
|
-
...getTestNames(test5)
|
|
14777
|
-
}), createAssertionMessage(utils, this, true), error, utils.flag(this, "soft"));
|
|
14778
|
-
});
|
|
14779
|
-
utils.addMethod(chai.Assertion.prototype, "toMatchInlineSnapshot", wrapAssertion(utils, "toMatchInlineSnapshot", function __INLINE_SNAPSHOT_OFFSET_3__(properties, inlineSnapshot, message) {
|
|
14780
|
-
utils.flag(this, "_name", "toMatchInlineSnapshot");
|
|
14781
|
-
if (utils.flag(this, "negate")) throw new Error('toMatchInlineSnapshot cannot be used with "not"');
|
|
14782
|
-
const test5 = getTest("toMatchInlineSnapshot", this);
|
|
14783
|
-
const expected = utils.flag(this, "object");
|
|
14784
|
-
const error = utils.flag(this, "error");
|
|
14785
|
-
if (typeof properties === "string") {
|
|
14786
|
-
message = inlineSnapshot;
|
|
14787
|
-
inlineSnapshot = properties;
|
|
14788
|
-
properties = void 0;
|
|
14789
|
-
}
|
|
14790
|
-
if (inlineSnapshot) inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
|
|
14791
|
-
const errorMessage = utils.flag(this, "message");
|
|
14792
|
-
getSnapshotClient().assert({
|
|
14793
|
-
received: expected,
|
|
14794
|
-
message,
|
|
14795
|
-
isInline: true,
|
|
14796
|
-
properties,
|
|
14797
|
-
inlineSnapshot,
|
|
14798
|
-
error,
|
|
14799
|
-
errorMessage,
|
|
14800
|
-
...getTestNames(test5)
|
|
14801
|
-
});
|
|
14802
|
-
}));
|
|
14803
|
-
utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingSnapshot", wrapAssertion(utils, "toThrowErrorMatchingSnapshot", function(properties, message) {
|
|
14804
|
-
utils.flag(this, "_name", "toThrowErrorMatchingSnapshot");
|
|
14805
|
-
if (utils.flag(this, "negate")) throw new Error('toThrowErrorMatchingSnapshot cannot be used with "not"');
|
|
14806
|
-
const expected = utils.flag(this, "object");
|
|
14807
|
-
const test5 = getTest("toThrowErrorMatchingSnapshot", this);
|
|
14808
|
-
const promise = utils.flag(this, "promise");
|
|
14809
|
-
const errorMessage = utils.flag(this, "message");
|
|
14810
|
-
getSnapshotClient().assert({
|
|
14811
|
-
received: getError(expected, promise),
|
|
14812
|
-
message,
|
|
14813
|
-
errorMessage,
|
|
14814
|
-
...getTestNames(test5)
|
|
14815
|
-
});
|
|
14816
|
-
}));
|
|
14817
|
-
utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingInlineSnapshot", wrapAssertion(utils, "toThrowErrorMatchingInlineSnapshot", function __INLINE_SNAPSHOT_OFFSET_3__(inlineSnapshot, message) {
|
|
14818
|
-
if (utils.flag(this, "negate")) throw new Error('toThrowErrorMatchingInlineSnapshot cannot be used with "not"');
|
|
14819
|
-
const test5 = getTest("toThrowErrorMatchingInlineSnapshot", this);
|
|
14820
|
-
const expected = utils.flag(this, "object");
|
|
14821
|
-
const error = utils.flag(this, "error");
|
|
14822
|
-
const promise = utils.flag(this, "promise");
|
|
14823
|
-
const errorMessage = utils.flag(this, "message");
|
|
14824
|
-
if (inlineSnapshot) inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
|
|
14825
|
-
getSnapshotClient().assert({
|
|
14826
|
-
received: getError(expected, promise),
|
|
14827
|
-
message,
|
|
14828
|
-
inlineSnapshot,
|
|
14829
|
-
isInline: true,
|
|
14830
|
-
error,
|
|
14831
|
-
errorMessage,
|
|
14832
|
-
...getTestNames(test5)
|
|
14833
|
-
});
|
|
14834
|
-
}));
|
|
14835
|
-
utils.addMethod(chai.expect, "addSnapshotSerializer", addSerializer);
|
|
14836
|
-
};
|
|
14837
|
-
chai_exports.use(JestExtend);
|
|
14838
|
-
chai_exports.use(JestChaiExpect);
|
|
14839
|
-
chai_exports.use(ChaiStyleAssertions);
|
|
14840
|
-
chai_exports.use(SnapshotPlugin);
|
|
14841
|
-
chai_exports.use(JestAsymmetricMatchers);
|
|
14842
|
-
function createExpect(test5) {
|
|
14843
|
-
const expect2 = ((value, message) => {
|
|
14844
|
-
const { assertionCalls } = getState(expect2);
|
|
14845
|
-
setState({ assertionCalls: assertionCalls + 1 }, expect2);
|
|
14846
|
-
const assert5 = chai_exports.expect(value, message);
|
|
14847
|
-
const _test2 = test5 || getCurrentTest();
|
|
14848
|
-
if (_test2)
|
|
14849
|
-
return assert5.withTest(_test2);
|
|
14850
|
-
else return assert5;
|
|
14851
|
-
});
|
|
14852
|
-
Object.assign(expect2, chai_exports.expect);
|
|
14853
|
-
Object.assign(expect2, globalThis[ASYMMETRIC_MATCHERS_OBJECT]);
|
|
14854
|
-
expect2.getState = () => getState(expect2);
|
|
14855
|
-
expect2.setState = (state) => setState(state, expect2);
|
|
14856
|
-
const globalState = getState(globalThis[GLOBAL_EXPECT]) || {};
|
|
14857
|
-
setState({
|
|
14858
|
-
...globalState,
|
|
14859
|
-
assertionCalls: 0,
|
|
14860
|
-
isExpectingAssertions: false,
|
|
14861
|
-
isExpectingAssertionsError: null,
|
|
14862
|
-
expectedAssertionsNumber: null,
|
|
14863
|
-
expectedAssertionsNumberErrorGen: null,
|
|
14864
|
-
get testPath() {
|
|
14865
|
-
return getWorkerState().filepath;
|
|
14866
|
-
},
|
|
14867
|
-
currentTestName: test5 ? test5.fullTestName ?? "" : globalState.currentTestName
|
|
14868
|
-
}, expect2);
|
|
14869
|
-
expect2.assert = chai_exports.assert;
|
|
14870
|
-
expect2.extend = (matchers) => chai_exports.expect.extend(expect2, matchers);
|
|
14871
|
-
expect2.addEqualityTesters = (customTesters) => addCustomEqualityTesters(customTesters);
|
|
14872
|
-
expect2.soft = (...args) => {
|
|
14873
|
-
return expect2(...args).withContext({ soft: true });
|
|
14874
|
-
};
|
|
14875
|
-
expect2.poll = createExpectPoll(expect2);
|
|
14876
|
-
expect2.unreachable = (message) => {
|
|
14877
|
-
chai_exports.assert.fail(`expected${message ? ` "${message}" ` : " "}not to be reached`);
|
|
14878
|
-
};
|
|
14879
|
-
function assertions(expected) {
|
|
14880
|
-
const errorGen = () => /* @__PURE__ */ new Error(`expected number of assertions to be ${expected}, but got ${expect2.getState().assertionCalls}`);
|
|
14881
|
-
if (Error.captureStackTrace) Error.captureStackTrace(errorGen(), assertions);
|
|
14882
|
-
expect2.setState({
|
|
14883
|
-
expectedAssertionsNumber: expected,
|
|
14884
|
-
expectedAssertionsNumberErrorGen: errorGen
|
|
14885
|
-
});
|
|
14886
|
-
}
|
|
14887
|
-
function hasAssertions() {
|
|
14888
|
-
const error = /* @__PURE__ */ new Error("expected any number of assertion, but got none");
|
|
14889
|
-
if (Error.captureStackTrace) Error.captureStackTrace(error, hasAssertions);
|
|
14890
|
-
expect2.setState({
|
|
14891
|
-
isExpectingAssertions: true,
|
|
14892
|
-
isExpectingAssertionsError: error
|
|
14893
|
-
});
|
|
14895
|
+
function raceWith(promise, other) {
|
|
14896
|
+
const left = promise.then((value) => ({
|
|
14897
|
+
ok: true,
|
|
14898
|
+
value
|
|
14899
|
+
}));
|
|
14900
|
+
if (!other) {
|
|
14901
|
+
return left;
|
|
14894
14902
|
}
|
|
14895
|
-
|
|
14896
|
-
|
|
14897
|
-
|
|
14898
|
-
|
|
14903
|
+
return Promise.race([left, other.then((value) => ({
|
|
14904
|
+
ok: false,
|
|
14905
|
+
value
|
|
14906
|
+
}))]);
|
|
14899
14907
|
}
|
|
14900
|
-
|
|
14901
|
-
|
|
14902
|
-
value: globalExpect,
|
|
14903
|
-
writable: true,
|
|
14904
|
-
configurable: true
|
|
14905
|
-
});
|
|
14906
|
-
var assert4 = chai_exports.assert;
|
|
14907
|
-
var should2 = chai_exports.should;
|
|
14908
|
+
|
|
14909
|
+
// ../../node_modules/vitest/dist/chunks/test.DNmyFkvJ.js
|
|
14908
14910
|
var fakeTimersSrc = {};
|
|
14909
14911
|
var global2;
|
|
14910
14912
|
var hasRequiredGlobal;
|
|
@@ -16926,7 +16928,7 @@ var FakeTimers = class {
|
|
|
16926
16928
|
return this._fakingTime;
|
|
16927
16929
|
}
|
|
16928
16930
|
};
|
|
16929
|
-
function copyStackTrace(target, source) {
|
|
16931
|
+
function copyStackTrace$1(target, source) {
|
|
16930
16932
|
if (source.stack !== void 0) target.stack = source.stack.replace(source.message, target.message);
|
|
16931
16933
|
return target;
|
|
16932
16934
|
}
|
|
@@ -16947,7 +16949,7 @@ function waitFor(callback, options = {}) {
|
|
|
16947
16949
|
const handleTimeout = () => {
|
|
16948
16950
|
if (intervalId) clearInterval2(intervalId);
|
|
16949
16951
|
let error = lastError;
|
|
16950
|
-
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);
|
|
16951
16953
|
reject(error);
|
|
16952
16954
|
};
|
|
16953
16955
|
const checkCallback = () => {
|
|
@@ -16988,7 +16990,7 @@ function waitUntil(callback, options = {}) {
|
|
|
16988
16990
|
let intervalId;
|
|
16989
16991
|
const onReject = (error) => {
|
|
16990
16992
|
if (intervalId) clearInterval2(intervalId);
|
|
16991
|
-
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);
|
|
16992
16994
|
reject(error);
|
|
16993
16995
|
};
|
|
16994
16996
|
const onResolve = (result) => {
|
|
@@ -17125,7 +17127,7 @@ function createVitest() {
|
|
|
17125
17127
|
waitUntil,
|
|
17126
17128
|
defineHelper: (fn2) => {
|
|
17127
17129
|
return function __VITEST_HELPER__(...args) {
|
|
17128
|
-
const result = fn2(
|
|
17130
|
+
const result = fn2.apply(this, args);
|
|
17129
17131
|
if (result && typeof result === "object" && typeof result.then === "function") return (async function __VITEST_HELPER__2() {
|
|
17130
17132
|
return await result;
|
|
17131
17133
|
})();
|
|
@@ -17254,6 +17256,358 @@ function getImporter(name) {
|
|
|
17254
17256
|
return stack.includes(` at Object.${name}`) || stack.includes(`${name}@`) || stack.includes(` at ${name} (`);
|
|
17255
17257
|
}) + 1])?.file || "";
|
|
17256
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;
|
|
17257
17611
|
|
|
17258
17612
|
// ../../node_modules/vite/dist/node/module-runner.js
|
|
17259
17613
|
var SOURCEMAPPING_URL = "sourceMa";
|