@antdv-next/x-sdk 0.0.1 → 0.0.3
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/LICENSE +21 -0
- package/dist/_util/resolveMaybeRef.d.ts +2 -0
- package/dist/_util/resolveMaybeRef.js +7 -0
- package/dist/_util/types.js +0 -0
- package/dist/chat-providers/AbstractChatProvider.d.ts +2 -2
- package/dist/chat-providers/AbstractChatProvider.js +42 -0
- package/dist/chat-providers/DeepSeekChatProvider.d.ts +2 -2
- package/dist/chat-providers/DeepSeekChatProvider.js +59 -0
- package/dist/chat-providers/DefaultChatProvider.d.ts +2 -2
- package/dist/chat-providers/DefaultChatProvider.js +26 -0
- package/dist/chat-providers/OpenAIChatProvider.d.ts +2 -2
- package/dist/chat-providers/OpenAIChatProvider.js +49 -0
- package/dist/chat-providers/index.js +4 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +7 -3
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/expect/index.js +1467 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/pretty-format/index.js +884 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/runner/chunk-artifact.js +1513 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/snapshot/index.js +661 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/spy/index.js +384 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/utils/chunk-pathe.M-eThtNZ.js +80 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/utils/diff.js +1304 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/utils/display.js +556 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/utils/error.js +27 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/utils/helpers.js +179 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/utils/offset.js +25 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/utils/serialize.js +75 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/utils/source-map.js +371 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/utils/timers.js +35 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/chunks/_commonjsHelpers.D26ty3Ew.js +4 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/chunks/rpc.MzXet3jl.js +50 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/chunks/test.CBQUpOM3.js +2645 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/chunks/utils.BX5Fg8C4.js +42 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/vendor/chai.js +2872 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/vendor/magic-string.js +1009 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/vendor/tinyrainbow.js +84 -0
- package/dist/x-chat/__tests__/index.test.d.ts +1 -0
- package/dist/x-chat/__tests__/index.test.js +258 -0
- package/dist/x-chat/index.d.ts +14 -23
- package/dist/x-chat/index.js +85 -67
- package/dist/x-chat/store.d.ts +2 -0
- package/dist/{store-C1diHqNH.js → x-chat/store.js} +15 -9
- package/dist/x-conversations/__tests__/index.test.d.ts +1 -0
- package/dist/x-conversations/__tests__/index.test.js +36 -0
- package/dist/x-conversations/index.d.ts +4 -4
- package/dist/x-conversations/index.js +37 -1
- package/dist/{x-conversations-BrKWhj5r.js → x-conversations/store.js} +2 -31
- package/dist/x-request/__tests__/index.test.d.ts +1 -0
- package/dist/x-request/__tests__/index.test.js +90 -0
- package/dist/x-request/index.d.ts +36 -11
- package/dist/x-request/index.js +246 -1
- package/dist/x-request/x-fetch.js +18 -0
- package/dist/x-stream/__tests__/index.test.d.ts +1 -0
- package/dist/x-stream/__tests__/index.test.js +62 -0
- package/dist/x-stream/index.js +16 -5
- package/package.json +2 -1
- package/dist/chat-providers-5x9Va7p5.js +0 -167
- package/dist/x-request-BSFGaKND.js +0 -234
|
@@ -0,0 +1,661 @@
|
|
|
1
|
+
import { format, plugins } from "../pretty-format/index.js";
|
|
2
|
+
import { getCallLastIndex, isObject } from "../utils/helpers.js";
|
|
3
|
+
import { parseErrorStacktrace } from "../utils/source-map.js";
|
|
4
|
+
import { lineSplitRE, offsetToLineNumber, positionToOffset } from "../utils/offset.js";
|
|
5
|
+
//#region ../../node_modules/.pnpm/@voidzero-dev+vite-plus-test@0.1.14_@types+node@24.12.0_@voidzero-dev+vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/snapshot/index.js
|
|
6
|
+
async function saveInlineSnapshots(environment, snapshots) {
|
|
7
|
+
const MagicString = (await import("../../vendor/magic-string.js")).default;
|
|
8
|
+
const files = new Set(snapshots.map((i) => i.file));
|
|
9
|
+
await Promise.all(Array.from(files).map(async (file) => {
|
|
10
|
+
const snaps = snapshots.filter((i) => i.file === file);
|
|
11
|
+
const code = await environment.readSnapshotFile(file);
|
|
12
|
+
if (code == null) throw new Error(`cannot read ${file} when saving inline snapshot`);
|
|
13
|
+
const s = new MagicString(code);
|
|
14
|
+
for (const snap of snaps) replaceInlineSnap(code, s, positionToOffset(code, snap.line, snap.column), snap.snapshot);
|
|
15
|
+
const transformed = s.toString();
|
|
16
|
+
if (transformed !== code) await environment.saveSnapshotFile(file, transformed);
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
19
|
+
var startObjectRegex = /(?:toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot)\s*\(\s*(?:\/\*[\s\S]*\*\/\s*|\/\/.*(?:[\n\r\u2028\u2029]\s*|[\t\v\f \xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF]))*\{/;
|
|
20
|
+
function replaceObjectSnap(code, s, index, newSnap) {
|
|
21
|
+
let _code = code.slice(index);
|
|
22
|
+
const startMatch = startObjectRegex.exec(_code);
|
|
23
|
+
if (!startMatch) return false;
|
|
24
|
+
_code = _code.slice(startMatch.index);
|
|
25
|
+
let callEnd = getCallLastIndex(_code);
|
|
26
|
+
if (callEnd === null) return false;
|
|
27
|
+
callEnd += index + startMatch.index;
|
|
28
|
+
const shapeEnd = getObjectShapeEndIndex(code, index + startMatch.index + startMatch[0].length);
|
|
29
|
+
const snap = `, ${prepareSnapString(newSnap, code, index)}`;
|
|
30
|
+
if (shapeEnd === callEnd) s.appendLeft(callEnd, snap);
|
|
31
|
+
else s.overwrite(shapeEnd, callEnd, snap);
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
function getObjectShapeEndIndex(code, index) {
|
|
35
|
+
let startBraces = 1;
|
|
36
|
+
let endBraces = 0;
|
|
37
|
+
while (startBraces !== endBraces && index < code.length) {
|
|
38
|
+
const s = code[index++];
|
|
39
|
+
if (s === "{") startBraces++;
|
|
40
|
+
else if (s === "}") endBraces++;
|
|
41
|
+
}
|
|
42
|
+
return index;
|
|
43
|
+
}
|
|
44
|
+
function prepareSnapString(snap, source, index) {
|
|
45
|
+
const lineNumber = offsetToLineNumber(source, index);
|
|
46
|
+
const indent = source.split(lineSplitRE)[lineNumber - 1].match(/^\s*/)[0] || "";
|
|
47
|
+
const indentNext = indent.includes(" ") ? `${indent}\t` : `${indent} `;
|
|
48
|
+
const lines = snap.trim().replace(/\\/g, "\\\\").split(/\n/g);
|
|
49
|
+
const isOneline = lines.length <= 1;
|
|
50
|
+
const quote = "`";
|
|
51
|
+
if (isOneline) return `${quote}${lines.join("\n").replace(/`/g, "\\`").replace(/\$\{/g, "\\${")}${quote}`;
|
|
52
|
+
return `${quote}\n${lines.map((i) => i ? indentNext + i : "").join("\n").replace(/`/g, "\\`").replace(/\$\{/g, "\\${")}\n${indent}${quote}`;
|
|
53
|
+
}
|
|
54
|
+
var toMatchInlineName = "toMatchInlineSnapshot";
|
|
55
|
+
var toThrowErrorMatchingInlineName = "toThrowErrorMatchingInlineSnapshot";
|
|
56
|
+
function getCodeStartingAtIndex(code, index) {
|
|
57
|
+
const indexInline = index - 21;
|
|
58
|
+
if (code.slice(indexInline, index) === toMatchInlineName) return {
|
|
59
|
+
code: code.slice(indexInline),
|
|
60
|
+
index: indexInline
|
|
61
|
+
};
|
|
62
|
+
const indexThrowInline = index - 34;
|
|
63
|
+
if (code.slice(index - indexThrowInline, index) === toThrowErrorMatchingInlineName) return {
|
|
64
|
+
code: code.slice(index - indexThrowInline),
|
|
65
|
+
index: index - indexThrowInline
|
|
66
|
+
};
|
|
67
|
+
return {
|
|
68
|
+
code: code.slice(index),
|
|
69
|
+
index
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
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$]*(['"`)])/;
|
|
73
|
+
function replaceInlineSnap(code, s, currentIndex, newSnap) {
|
|
74
|
+
const { code: codeStartingAtIndex, index } = getCodeStartingAtIndex(code, currentIndex);
|
|
75
|
+
const startMatch = startRegex.exec(codeStartingAtIndex);
|
|
76
|
+
const firstKeywordMatch = /toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot/.exec(codeStartingAtIndex);
|
|
77
|
+
if (!startMatch || startMatch.index !== firstKeywordMatch?.index) return replaceObjectSnap(code, s, index, newSnap);
|
|
78
|
+
const quote = startMatch[1];
|
|
79
|
+
const startIndex = index + startMatch.index + startMatch[0].length;
|
|
80
|
+
const snapString = prepareSnapString(newSnap, code, index);
|
|
81
|
+
if (quote === ")") {
|
|
82
|
+
s.appendRight(startIndex - 1, snapString);
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
const endMatch = new RegExp(`(?:^|[^\\\\])${quote}`).exec(code.slice(startIndex));
|
|
86
|
+
if (!endMatch) return false;
|
|
87
|
+
const endIndex = startIndex + endMatch.index + endMatch[0].length;
|
|
88
|
+
s.overwrite(startIndex - 1, endIndex, snapString);
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
var INDENTATION_REGEX = /^([^\S\n]*)\S/m;
|
|
92
|
+
function stripSnapshotIndentation(inlineSnapshot) {
|
|
93
|
+
const match = inlineSnapshot.match(INDENTATION_REGEX);
|
|
94
|
+
if (!match || !match[1]) return inlineSnapshot;
|
|
95
|
+
const indentation = match[1];
|
|
96
|
+
const lines = inlineSnapshot.split(/\n/g);
|
|
97
|
+
if (lines.length <= 2) return inlineSnapshot;
|
|
98
|
+
if (lines[0].trim() !== "" || lines.at(-1)?.trim() !== "") return inlineSnapshot;
|
|
99
|
+
for (let i = 1; i < lines.length - 1; i++) if (lines[i] !== "") {
|
|
100
|
+
if (lines[i].indexOf(indentation) !== 0) return inlineSnapshot;
|
|
101
|
+
lines[i] = lines[i].substring(indentation.length);
|
|
102
|
+
}
|
|
103
|
+
lines[lines.length - 1] = "";
|
|
104
|
+
inlineSnapshot = lines.join("\n");
|
|
105
|
+
return inlineSnapshot;
|
|
106
|
+
}
|
|
107
|
+
async function saveRawSnapshots(environment, snapshots) {
|
|
108
|
+
await Promise.all(snapshots.map(async (snap) => {
|
|
109
|
+
if (!snap.readonly) await environment.saveSnapshotFile(snap.file, snap.snapshot);
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
function getDefaultExportFromCjs(x) {
|
|
113
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
114
|
+
}
|
|
115
|
+
var naturalCompare$1 = { exports: {} };
|
|
116
|
+
var hasRequiredNaturalCompare;
|
|
117
|
+
function requireNaturalCompare() {
|
|
118
|
+
if (hasRequiredNaturalCompare) return naturalCompare$1.exports;
|
|
119
|
+
hasRequiredNaturalCompare = 1;
|
|
120
|
+
/*
|
|
121
|
+
* @version 1.4.0
|
|
122
|
+
* @date 2015-10-26
|
|
123
|
+
* @stability 3 - Stable
|
|
124
|
+
* @author Lauri Rooden (https://github.com/litejs/natural-compare-lite)
|
|
125
|
+
* @license MIT License
|
|
126
|
+
*/
|
|
127
|
+
var naturalCompare = function(a, b) {
|
|
128
|
+
var i, codeA, codeB = 1, posA = 0, posB = 0, alphabet = String.alphabet;
|
|
129
|
+
function getCode(str, pos, code) {
|
|
130
|
+
if (code) {
|
|
131
|
+
for (i = pos; code = getCode(str, i), code < 76 && code > 65;) ++i;
|
|
132
|
+
return +str.slice(pos - 1, i);
|
|
133
|
+
}
|
|
134
|
+
code = alphabet && alphabet.indexOf(str.charAt(pos));
|
|
135
|
+
return code > -1 ? code + 76 : (code = str.charCodeAt(pos) || 0, code < 45 || code > 127) ? code : code < 46 ? 65 : code < 48 ? code - 1 : code < 58 ? code + 18 : code < 65 ? code - 11 : code < 91 ? code + 11 : code < 97 ? code - 37 : code < 123 ? code + 5 : code - 63;
|
|
136
|
+
}
|
|
137
|
+
if ((a += "") != (b += "")) for (; codeB;) {
|
|
138
|
+
codeA = getCode(a, posA++);
|
|
139
|
+
codeB = getCode(b, posB++);
|
|
140
|
+
if (codeA < 76 && codeB < 76 && codeA > 66 && codeB > 66) {
|
|
141
|
+
codeA = getCode(a, posA, posA);
|
|
142
|
+
codeB = getCode(b, posB, posA = i);
|
|
143
|
+
posB = i;
|
|
144
|
+
}
|
|
145
|
+
if (codeA != codeB) return codeA < codeB ? -1 : 1;
|
|
146
|
+
}
|
|
147
|
+
return 0;
|
|
148
|
+
};
|
|
149
|
+
try {
|
|
150
|
+
naturalCompare$1.exports = naturalCompare;
|
|
151
|
+
} catch (e) {
|
|
152
|
+
String.naturalCompare = naturalCompare;
|
|
153
|
+
}
|
|
154
|
+
return naturalCompare$1.exports;
|
|
155
|
+
}
|
|
156
|
+
var naturalCompare = /*@__PURE__*/ getDefaultExportFromCjs(requireNaturalCompare());
|
|
157
|
+
var serialize$1 = (val, config, indentation, depth, refs, printer) => {
|
|
158
|
+
const name = val.getMockName();
|
|
159
|
+
const nameString = name === "vi.fn()" ? "" : ` ${name}`;
|
|
160
|
+
let callsString = "";
|
|
161
|
+
if (val.mock.calls.length !== 0) {
|
|
162
|
+
const indentationNext = indentation + config.indent;
|
|
163
|
+
callsString = ` {${config.spacingOuter}${indentationNext}"calls": ${printer(val.mock.calls, config, indentationNext, depth, refs)}${config.min ? ", " : ","}${config.spacingOuter}${indentationNext}"results": ${printer(val.mock.results, config, indentationNext, depth, refs)}${config.min ? "" : ","}${config.spacingOuter}${indentation}}`;
|
|
164
|
+
}
|
|
165
|
+
return `[MockFunction${nameString}]${callsString}`;
|
|
166
|
+
};
|
|
167
|
+
var test = (val) => val && !!val._isMockFunction;
|
|
168
|
+
var plugin = {
|
|
169
|
+
serialize: serialize$1,
|
|
170
|
+
test
|
|
171
|
+
};
|
|
172
|
+
var { DOMCollection, DOMElement, Immutable, ReactElement, ReactTestComponent, AsymmetricMatcher } = plugins;
|
|
173
|
+
var PLUGINS = [
|
|
174
|
+
ReactTestComponent,
|
|
175
|
+
ReactElement,
|
|
176
|
+
DOMElement,
|
|
177
|
+
DOMCollection,
|
|
178
|
+
Immutable,
|
|
179
|
+
AsymmetricMatcher,
|
|
180
|
+
plugin
|
|
181
|
+
];
|
|
182
|
+
function addSerializer(plugin) {
|
|
183
|
+
PLUGINS = [plugin].concat(PLUGINS);
|
|
184
|
+
}
|
|
185
|
+
function getSerializers() {
|
|
186
|
+
return PLUGINS;
|
|
187
|
+
}
|
|
188
|
+
function testNameToKey(testName, count) {
|
|
189
|
+
return `${testName} ${count}`;
|
|
190
|
+
}
|
|
191
|
+
function keyToTestName(key) {
|
|
192
|
+
if (!/ \d+$/.test(key)) throw new Error("Snapshot keys must end with a number.");
|
|
193
|
+
return key.replace(/ \d+$/, "");
|
|
194
|
+
}
|
|
195
|
+
function getSnapshotData(content, options) {
|
|
196
|
+
const update = options.updateSnapshot;
|
|
197
|
+
const data = Object.create(null);
|
|
198
|
+
let snapshotContents = "";
|
|
199
|
+
let dirty = false;
|
|
200
|
+
if (content != null) try {
|
|
201
|
+
snapshotContents = content;
|
|
202
|
+
new Function("exports", snapshotContents)(data);
|
|
203
|
+
} catch {}
|
|
204
|
+
if ((update === "all" || update === "new") && snapshotContents) dirty = true;
|
|
205
|
+
return {
|
|
206
|
+
data,
|
|
207
|
+
dirty
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function addExtraLineBreaks(string) {
|
|
211
|
+
return string.includes("\n") ? `\n${string}\n` : string;
|
|
212
|
+
}
|
|
213
|
+
function removeExtraLineBreaks(string) {
|
|
214
|
+
return string.length > 2 && string[0] === "\n" && string.endsWith("\n") ? string.slice(1, -1) : string;
|
|
215
|
+
}
|
|
216
|
+
var escapeRegex = true;
|
|
217
|
+
var printFunctionName = false;
|
|
218
|
+
function serialize(val, indent = 2, formatOverrides = {}) {
|
|
219
|
+
return normalizeNewlines(format(val, {
|
|
220
|
+
escapeRegex,
|
|
221
|
+
indent,
|
|
222
|
+
plugins: getSerializers(),
|
|
223
|
+
printFunctionName,
|
|
224
|
+
...formatOverrides
|
|
225
|
+
}));
|
|
226
|
+
}
|
|
227
|
+
function escapeBacktickString(str) {
|
|
228
|
+
return str.replace(/`|\\|\$\{/g, "\\$&");
|
|
229
|
+
}
|
|
230
|
+
function printBacktickString(str) {
|
|
231
|
+
return `\`${escapeBacktickString(str)}\``;
|
|
232
|
+
}
|
|
233
|
+
function normalizeNewlines(string) {
|
|
234
|
+
return string.replace(/\r\n|\r/g, "\n");
|
|
235
|
+
}
|
|
236
|
+
async function saveSnapshotFile(environment, snapshotData, snapshotPath) {
|
|
237
|
+
const snapshots = Object.keys(snapshotData).sort(naturalCompare).map((key) => `exports[${printBacktickString(key)}] = ${printBacktickString(normalizeNewlines(snapshotData[key]))};`);
|
|
238
|
+
const content = `${environment.getHeader()}\n\n${snapshots.join("\n\n")}\n`;
|
|
239
|
+
const oldContent = await environment.readSnapshotFile(snapshotPath);
|
|
240
|
+
if (oldContent != null && oldContent === content) return;
|
|
241
|
+
await environment.saveSnapshotFile(snapshotPath, content);
|
|
242
|
+
}
|
|
243
|
+
function deepMergeArray(target = [], source = []) {
|
|
244
|
+
const mergedOutput = Array.from(target);
|
|
245
|
+
source.forEach((sourceElement, index) => {
|
|
246
|
+
const targetElement = mergedOutput[index];
|
|
247
|
+
if (Array.isArray(target[index])) mergedOutput[index] = deepMergeArray(target[index], sourceElement);
|
|
248
|
+
else if (isObject(targetElement)) mergedOutput[index] = deepMergeSnapshot(target[index], sourceElement);
|
|
249
|
+
else mergedOutput[index] = sourceElement;
|
|
250
|
+
});
|
|
251
|
+
return mergedOutput;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Deep merge, but considers asymmetric matchers. Unlike base util's deep merge,
|
|
255
|
+
* will merge any object-like instance.
|
|
256
|
+
* Compatible with Jest's snapshot matcher. Should not be used outside of snapshot.
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* ```ts
|
|
260
|
+
* toMatchSnapshot({
|
|
261
|
+
* name: expect.stringContaining('text')
|
|
262
|
+
* })
|
|
263
|
+
* ```
|
|
264
|
+
*/
|
|
265
|
+
function deepMergeSnapshot(target, source) {
|
|
266
|
+
if (isObject(target) && isObject(source)) {
|
|
267
|
+
const mergedOutput = { ...target };
|
|
268
|
+
Object.keys(source).forEach((key) => {
|
|
269
|
+
if (isObject(source[key]) && !source[key].$$typeof) if (!(key in target)) Object.assign(mergedOutput, { [key]: source[key] });
|
|
270
|
+
else mergedOutput[key] = deepMergeSnapshot(target[key], source[key]);
|
|
271
|
+
else if (Array.isArray(source[key])) mergedOutput[key] = deepMergeArray(target[key], source[key]);
|
|
272
|
+
else Object.assign(mergedOutput, { [key]: source[key] });
|
|
273
|
+
});
|
|
274
|
+
return mergedOutput;
|
|
275
|
+
} else if (Array.isArray(target) && Array.isArray(source)) return deepMergeArray(target, source);
|
|
276
|
+
return target;
|
|
277
|
+
}
|
|
278
|
+
var DefaultMap = class extends Map {
|
|
279
|
+
constructor(defaultFn, entries) {
|
|
280
|
+
super(entries);
|
|
281
|
+
this.defaultFn = defaultFn;
|
|
282
|
+
}
|
|
283
|
+
get(key) {
|
|
284
|
+
if (!this.has(key)) this.set(key, this.defaultFn(key));
|
|
285
|
+
return super.get(key);
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
var CounterMap = class extends DefaultMap {
|
|
289
|
+
constructor() {
|
|
290
|
+
super(() => 0);
|
|
291
|
+
}
|
|
292
|
+
_total;
|
|
293
|
+
valueOf() {
|
|
294
|
+
return this._total = this.total();
|
|
295
|
+
}
|
|
296
|
+
increment(key) {
|
|
297
|
+
if (typeof this._total !== "undefined") this._total++;
|
|
298
|
+
this.set(key, this.get(key) + 1);
|
|
299
|
+
}
|
|
300
|
+
total() {
|
|
301
|
+
if (typeof this._total !== "undefined") return this._total;
|
|
302
|
+
let total = 0;
|
|
303
|
+
for (const x of this.values()) total += x;
|
|
304
|
+
return total;
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
function isSameStackPosition(x, y) {
|
|
308
|
+
return x.file === y.file && x.column === y.column && x.line === y.line;
|
|
309
|
+
}
|
|
310
|
+
var SnapshotState = class SnapshotState {
|
|
311
|
+
_counters = new CounterMap();
|
|
312
|
+
_dirty;
|
|
313
|
+
_updateSnapshot;
|
|
314
|
+
_snapshotData;
|
|
315
|
+
_initialData;
|
|
316
|
+
_inlineSnapshots;
|
|
317
|
+
_inlineSnapshotStacks;
|
|
318
|
+
_testIdToKeys = new DefaultMap(() => []);
|
|
319
|
+
_rawSnapshots;
|
|
320
|
+
_uncheckedKeys;
|
|
321
|
+
_snapshotFormat;
|
|
322
|
+
_environment;
|
|
323
|
+
_fileExists;
|
|
324
|
+
expand;
|
|
325
|
+
_added = new CounterMap();
|
|
326
|
+
_matched = new CounterMap();
|
|
327
|
+
_unmatched = new CounterMap();
|
|
328
|
+
_updated = new CounterMap();
|
|
329
|
+
get added() {
|
|
330
|
+
return this._added;
|
|
331
|
+
}
|
|
332
|
+
set added(value) {
|
|
333
|
+
this._added._total = value;
|
|
334
|
+
}
|
|
335
|
+
get matched() {
|
|
336
|
+
return this._matched;
|
|
337
|
+
}
|
|
338
|
+
set matched(value) {
|
|
339
|
+
this._matched._total = value;
|
|
340
|
+
}
|
|
341
|
+
get unmatched() {
|
|
342
|
+
return this._unmatched;
|
|
343
|
+
}
|
|
344
|
+
set unmatched(value) {
|
|
345
|
+
this._unmatched._total = value;
|
|
346
|
+
}
|
|
347
|
+
get updated() {
|
|
348
|
+
return this._updated;
|
|
349
|
+
}
|
|
350
|
+
set updated(value) {
|
|
351
|
+
this._updated._total = value;
|
|
352
|
+
}
|
|
353
|
+
constructor(testFilePath, snapshotPath, snapshotContent, options) {
|
|
354
|
+
this.testFilePath = testFilePath;
|
|
355
|
+
this.snapshotPath = snapshotPath;
|
|
356
|
+
const { data, dirty } = getSnapshotData(snapshotContent, options);
|
|
357
|
+
this._fileExists = snapshotContent != null;
|
|
358
|
+
this._initialData = { ...data };
|
|
359
|
+
this._snapshotData = { ...data };
|
|
360
|
+
this._dirty = dirty;
|
|
361
|
+
this._inlineSnapshots = [];
|
|
362
|
+
this._inlineSnapshotStacks = [];
|
|
363
|
+
this._rawSnapshots = [];
|
|
364
|
+
this._uncheckedKeys = new Set(Object.keys(this._snapshotData));
|
|
365
|
+
this.expand = options.expand || false;
|
|
366
|
+
this._updateSnapshot = options.updateSnapshot;
|
|
367
|
+
this._snapshotFormat = {
|
|
368
|
+
printBasicPrototype: false,
|
|
369
|
+
escapeString: false,
|
|
370
|
+
...options.snapshotFormat
|
|
371
|
+
};
|
|
372
|
+
this._environment = options.snapshotEnvironment;
|
|
373
|
+
}
|
|
374
|
+
static async create(testFilePath, options) {
|
|
375
|
+
const snapshotPath = await options.snapshotEnvironment.resolvePath(testFilePath);
|
|
376
|
+
const content = await options.snapshotEnvironment.readSnapshotFile(snapshotPath);
|
|
377
|
+
return new SnapshotState(testFilePath, snapshotPath, content, options);
|
|
378
|
+
}
|
|
379
|
+
get environment() {
|
|
380
|
+
return this._environment;
|
|
381
|
+
}
|
|
382
|
+
markSnapshotsAsCheckedForTest(testName) {
|
|
383
|
+
this._uncheckedKeys.forEach((uncheckedKey) => {
|
|
384
|
+
if (/ \d+$| > /.test(uncheckedKey.slice(testName.length))) this._uncheckedKeys.delete(uncheckedKey);
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
clearTest(testId) {
|
|
388
|
+
this._inlineSnapshots = this._inlineSnapshots.filter((s) => s.testId !== testId);
|
|
389
|
+
this._inlineSnapshotStacks = this._inlineSnapshotStacks.filter((s) => s.testId !== testId);
|
|
390
|
+
for (const key of this._testIdToKeys.get(testId)) {
|
|
391
|
+
const name = keyToTestName(key);
|
|
392
|
+
const count = this._counters.get(name);
|
|
393
|
+
if (count > 0) {
|
|
394
|
+
if (key in this._snapshotData || key in this._initialData) this._snapshotData[key] = this._initialData[key];
|
|
395
|
+
this._counters.set(name, count - 1);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
this._testIdToKeys.delete(testId);
|
|
399
|
+
this.added.delete(testId);
|
|
400
|
+
this.updated.delete(testId);
|
|
401
|
+
this.matched.delete(testId);
|
|
402
|
+
this.unmatched.delete(testId);
|
|
403
|
+
}
|
|
404
|
+
_inferInlineSnapshotStack(stacks) {
|
|
405
|
+
const promiseIndex = stacks.findIndex((i) => i.method.match(/__VITEST_(RESOLVES|REJECTS)__/));
|
|
406
|
+
if (promiseIndex !== -1) return stacks[promiseIndex + 3];
|
|
407
|
+
for (let i = 0; i < stacks.length; i++) {
|
|
408
|
+
const match = stacks[i].method.match(/__INLINE_SNAPSHOT_OFFSET_(\d+)__/);
|
|
409
|
+
if (match) return stacks[i + Number(match[1])] ?? null;
|
|
410
|
+
}
|
|
411
|
+
const stackIndex = stacks.findIndex((i) => i.method.includes("__INLINE_SNAPSHOT__"));
|
|
412
|
+
return stackIndex !== -1 ? stacks[stackIndex + 2] : null;
|
|
413
|
+
}
|
|
414
|
+
_addSnapshot(key, receivedSerialized, options) {
|
|
415
|
+
this._dirty = true;
|
|
416
|
+
if (options.stack) this._inlineSnapshots.push({
|
|
417
|
+
snapshot: receivedSerialized,
|
|
418
|
+
testId: options.testId,
|
|
419
|
+
...options.stack
|
|
420
|
+
});
|
|
421
|
+
else if (options.rawSnapshot) this._rawSnapshots.push({
|
|
422
|
+
...options.rawSnapshot,
|
|
423
|
+
snapshot: receivedSerialized
|
|
424
|
+
});
|
|
425
|
+
else this._snapshotData[key] = receivedSerialized;
|
|
426
|
+
}
|
|
427
|
+
async save() {
|
|
428
|
+
const hasExternalSnapshots = Object.keys(this._snapshotData).length;
|
|
429
|
+
const hasInlineSnapshots = this._inlineSnapshots.length;
|
|
430
|
+
const hasRawSnapshots = this._rawSnapshots.length;
|
|
431
|
+
const isEmpty = !hasExternalSnapshots && !hasInlineSnapshots && !hasRawSnapshots;
|
|
432
|
+
const status = {
|
|
433
|
+
deleted: false,
|
|
434
|
+
saved: false
|
|
435
|
+
};
|
|
436
|
+
if ((this._dirty || this._uncheckedKeys.size) && !isEmpty) {
|
|
437
|
+
if (hasExternalSnapshots) {
|
|
438
|
+
await saveSnapshotFile(this._environment, this._snapshotData, this.snapshotPath);
|
|
439
|
+
this._fileExists = true;
|
|
440
|
+
}
|
|
441
|
+
if (hasInlineSnapshots) await saveInlineSnapshots(this._environment, this._inlineSnapshots);
|
|
442
|
+
if (hasRawSnapshots) await saveRawSnapshots(this._environment, this._rawSnapshots);
|
|
443
|
+
status.saved = true;
|
|
444
|
+
} else if (!hasExternalSnapshots && this._fileExists) {
|
|
445
|
+
if (this._updateSnapshot === "all") {
|
|
446
|
+
await this._environment.removeSnapshotFile(this.snapshotPath);
|
|
447
|
+
this._fileExists = false;
|
|
448
|
+
}
|
|
449
|
+
status.deleted = true;
|
|
450
|
+
}
|
|
451
|
+
return status;
|
|
452
|
+
}
|
|
453
|
+
getUncheckedCount() {
|
|
454
|
+
return this._uncheckedKeys.size || 0;
|
|
455
|
+
}
|
|
456
|
+
getUncheckedKeys() {
|
|
457
|
+
return Array.from(this._uncheckedKeys);
|
|
458
|
+
}
|
|
459
|
+
removeUncheckedKeys() {
|
|
460
|
+
if (this._updateSnapshot === "all" && this._uncheckedKeys.size) {
|
|
461
|
+
this._dirty = true;
|
|
462
|
+
this._uncheckedKeys.forEach((key) => delete this._snapshotData[key]);
|
|
463
|
+
this._uncheckedKeys.clear();
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
match({ testId, testName, received, key, inlineSnapshot, isInline, error, rawSnapshot }) {
|
|
467
|
+
this._counters.increment(testName);
|
|
468
|
+
const count = this._counters.get(testName);
|
|
469
|
+
if (!key) key = testNameToKey(testName, count);
|
|
470
|
+
this._testIdToKeys.get(testId).push(key);
|
|
471
|
+
if (!(isInline && this._snapshotData[key] !== void 0)) this._uncheckedKeys.delete(key);
|
|
472
|
+
let receivedSerialized = rawSnapshot && typeof received === "string" ? received : serialize(received, void 0, this._snapshotFormat);
|
|
473
|
+
if (!rawSnapshot) receivedSerialized = addExtraLineBreaks(receivedSerialized);
|
|
474
|
+
if (rawSnapshot) {
|
|
475
|
+
if (rawSnapshot.content && rawSnapshot.content.match(/\r\n/) && !receivedSerialized.match(/\r\n/)) rawSnapshot.content = normalizeNewlines(rawSnapshot.content);
|
|
476
|
+
}
|
|
477
|
+
const expected = isInline ? inlineSnapshot : rawSnapshot ? rawSnapshot.content : this._snapshotData[key];
|
|
478
|
+
const expectedTrimmed = rawSnapshot ? expected : expected?.trim();
|
|
479
|
+
const pass = expectedTrimmed === (rawSnapshot ? receivedSerialized : receivedSerialized.trim());
|
|
480
|
+
const hasSnapshot = expected !== void 0;
|
|
481
|
+
const snapshotIsPersisted = isInline || this._fileExists || rawSnapshot && rawSnapshot.content != null;
|
|
482
|
+
if (pass && !isInline && !rawSnapshot) this._snapshotData[key] = receivedSerialized;
|
|
483
|
+
let stack;
|
|
484
|
+
if (isInline) {
|
|
485
|
+
const stacks = parseErrorStacktrace(error || /* @__PURE__ */ new Error("snapshot"), { ignoreStackEntries: [] });
|
|
486
|
+
const _stack = this._inferInlineSnapshotStack(stacks);
|
|
487
|
+
if (!_stack) throw new Error(`@vitest/snapshot: Couldn't infer stack frame for inline snapshot.\n${JSON.stringify(stacks)}`);
|
|
488
|
+
stack = this.environment.processStackTrace?.(_stack) || _stack;
|
|
489
|
+
stack.column--;
|
|
490
|
+
const snapshotsWithSameStack = this._inlineSnapshotStacks.filter((s) => isSameStackPosition(s, stack));
|
|
491
|
+
if (snapshotsWithSameStack.length > 0) {
|
|
492
|
+
this._inlineSnapshots = this._inlineSnapshots.filter((s) => !isSameStackPosition(s, stack));
|
|
493
|
+
const differentSnapshot = snapshotsWithSameStack.find((s) => s.snapshot !== receivedSerialized);
|
|
494
|
+
if (differentSnapshot) throw Object.assign(/* @__PURE__ */ new Error("toMatchInlineSnapshot with different snapshots cannot be called at the same location"), {
|
|
495
|
+
actual: receivedSerialized,
|
|
496
|
+
expected: differentSnapshot.snapshot
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
this._inlineSnapshotStacks.push({
|
|
500
|
+
...stack,
|
|
501
|
+
testId,
|
|
502
|
+
snapshot: receivedSerialized
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
if (hasSnapshot && this._updateSnapshot === "all" || (!hasSnapshot || !snapshotIsPersisted) && (this._updateSnapshot === "new" || this._updateSnapshot === "all")) {
|
|
506
|
+
if (this._updateSnapshot === "all") if (!pass) {
|
|
507
|
+
if (hasSnapshot) this.updated.increment(testId);
|
|
508
|
+
else this.added.increment(testId);
|
|
509
|
+
this._addSnapshot(key, receivedSerialized, {
|
|
510
|
+
stack,
|
|
511
|
+
testId,
|
|
512
|
+
rawSnapshot
|
|
513
|
+
});
|
|
514
|
+
} else this.matched.increment(testId);
|
|
515
|
+
else {
|
|
516
|
+
this._addSnapshot(key, receivedSerialized, {
|
|
517
|
+
stack,
|
|
518
|
+
testId,
|
|
519
|
+
rawSnapshot
|
|
520
|
+
});
|
|
521
|
+
this.added.increment(testId);
|
|
522
|
+
}
|
|
523
|
+
return {
|
|
524
|
+
actual: "",
|
|
525
|
+
count,
|
|
526
|
+
expected: "",
|
|
527
|
+
key,
|
|
528
|
+
pass: true
|
|
529
|
+
};
|
|
530
|
+
} else if (!pass) {
|
|
531
|
+
this.unmatched.increment(testId);
|
|
532
|
+
return {
|
|
533
|
+
actual: rawSnapshot ? receivedSerialized : removeExtraLineBreaks(receivedSerialized),
|
|
534
|
+
count,
|
|
535
|
+
expected: expectedTrimmed !== void 0 ? rawSnapshot ? expectedTrimmed : removeExtraLineBreaks(expectedTrimmed) : void 0,
|
|
536
|
+
key,
|
|
537
|
+
pass: false
|
|
538
|
+
};
|
|
539
|
+
} else {
|
|
540
|
+
this.matched.increment(testId);
|
|
541
|
+
return {
|
|
542
|
+
actual: "",
|
|
543
|
+
count,
|
|
544
|
+
expected: "",
|
|
545
|
+
key,
|
|
546
|
+
pass: true
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
async pack() {
|
|
551
|
+
const snapshot = {
|
|
552
|
+
filepath: this.testFilePath,
|
|
553
|
+
added: 0,
|
|
554
|
+
fileDeleted: false,
|
|
555
|
+
matched: 0,
|
|
556
|
+
unchecked: 0,
|
|
557
|
+
uncheckedKeys: [],
|
|
558
|
+
unmatched: 0,
|
|
559
|
+
updated: 0
|
|
560
|
+
};
|
|
561
|
+
const uncheckedCount = this.getUncheckedCount();
|
|
562
|
+
const uncheckedKeys = this.getUncheckedKeys();
|
|
563
|
+
if (uncheckedCount) this.removeUncheckedKeys();
|
|
564
|
+
const status = await this.save();
|
|
565
|
+
snapshot.fileDeleted = status.deleted;
|
|
566
|
+
snapshot.added = this.added.total();
|
|
567
|
+
snapshot.matched = this.matched.total();
|
|
568
|
+
snapshot.unmatched = this.unmatched.total();
|
|
569
|
+
snapshot.updated = this.updated.total();
|
|
570
|
+
snapshot.unchecked = !status.deleted ? uncheckedCount : 0;
|
|
571
|
+
snapshot.uncheckedKeys = Array.from(uncheckedKeys);
|
|
572
|
+
return snapshot;
|
|
573
|
+
}
|
|
574
|
+
};
|
|
575
|
+
function createMismatchError(message, expand, actual, expected) {
|
|
576
|
+
const error = new Error(message);
|
|
577
|
+
Object.defineProperty(error, "actual", {
|
|
578
|
+
value: actual,
|
|
579
|
+
enumerable: true,
|
|
580
|
+
configurable: true,
|
|
581
|
+
writable: true
|
|
582
|
+
});
|
|
583
|
+
Object.defineProperty(error, "expected", {
|
|
584
|
+
value: expected,
|
|
585
|
+
enumerable: true,
|
|
586
|
+
configurable: true,
|
|
587
|
+
writable: true
|
|
588
|
+
});
|
|
589
|
+
Object.defineProperty(error, "diffOptions", { value: { expand } });
|
|
590
|
+
return error;
|
|
591
|
+
}
|
|
592
|
+
var SnapshotClient = class {
|
|
593
|
+
snapshotStateMap = /* @__PURE__ */ new Map();
|
|
594
|
+
constructor(options = {}) {
|
|
595
|
+
this.options = options;
|
|
596
|
+
}
|
|
597
|
+
async setup(filepath, options) {
|
|
598
|
+
if (this.snapshotStateMap.has(filepath)) return;
|
|
599
|
+
this.snapshotStateMap.set(filepath, await SnapshotState.create(filepath, options));
|
|
600
|
+
}
|
|
601
|
+
async finish(filepath) {
|
|
602
|
+
const result = await this.getSnapshotState(filepath).pack();
|
|
603
|
+
this.snapshotStateMap.delete(filepath);
|
|
604
|
+
return result;
|
|
605
|
+
}
|
|
606
|
+
skipTest(filepath, testName) {
|
|
607
|
+
this.getSnapshotState(filepath).markSnapshotsAsCheckedForTest(testName);
|
|
608
|
+
}
|
|
609
|
+
clearTest(filepath, testId) {
|
|
610
|
+
this.getSnapshotState(filepath).clearTest(testId);
|
|
611
|
+
}
|
|
612
|
+
getSnapshotState(filepath) {
|
|
613
|
+
const state = this.snapshotStateMap.get(filepath);
|
|
614
|
+
if (!state) throw new Error(`The snapshot state for '${filepath}' is not found. Did you call 'SnapshotClient.setup()'?`);
|
|
615
|
+
return state;
|
|
616
|
+
}
|
|
617
|
+
assert(options) {
|
|
618
|
+
const { filepath, name, testId = name, message, isInline = false, properties, inlineSnapshot, error, errorMessage, rawSnapshot } = options;
|
|
619
|
+
let { received } = options;
|
|
620
|
+
if (!filepath) throw new Error("Snapshot cannot be used outside of test");
|
|
621
|
+
const snapshotState = this.getSnapshotState(filepath);
|
|
622
|
+
if (typeof properties === "object") {
|
|
623
|
+
if (typeof received !== "object" || !received) throw new Error("Received value must be an object when the matcher has properties");
|
|
624
|
+
try {
|
|
625
|
+
if (!(this.options.isEqual?.(received, properties) ?? false)) throw createMismatchError("Snapshot properties mismatched", snapshotState.expand, received, properties);
|
|
626
|
+
else received = deepMergeSnapshot(received, properties);
|
|
627
|
+
} catch (err) {
|
|
628
|
+
err.message = errorMessage || "Snapshot mismatched";
|
|
629
|
+
throw err;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
const testName = [name, ...message ? [message] : []].join(" > ");
|
|
633
|
+
const { actual, expected, key, pass } = snapshotState.match({
|
|
634
|
+
testId,
|
|
635
|
+
testName,
|
|
636
|
+
received,
|
|
637
|
+
isInline,
|
|
638
|
+
error,
|
|
639
|
+
inlineSnapshot,
|
|
640
|
+
rawSnapshot
|
|
641
|
+
});
|
|
642
|
+
if (!pass) throw createMismatchError(`Snapshot \`${key || "unknown"}\` mismatched`, snapshotState.expand, rawSnapshot ? actual : actual?.trim(), rawSnapshot ? expected : expected?.trim());
|
|
643
|
+
}
|
|
644
|
+
async assertRaw(options) {
|
|
645
|
+
if (!options.rawSnapshot) throw new Error("Raw snapshot is required");
|
|
646
|
+
const { filepath, rawSnapshot } = options;
|
|
647
|
+
if (rawSnapshot.content == null) {
|
|
648
|
+
if (!filepath) throw new Error("Snapshot cannot be used outside of test");
|
|
649
|
+
const snapshotState = this.getSnapshotState(filepath);
|
|
650
|
+
options.filepath ||= filepath;
|
|
651
|
+
rawSnapshot.file = await snapshotState.environment.resolveRawPath(filepath, rawSnapshot.file);
|
|
652
|
+
rawSnapshot.content = await snapshotState.environment.readSnapshotFile(rawSnapshot.file) ?? void 0;
|
|
653
|
+
}
|
|
654
|
+
return this.assert(options);
|
|
655
|
+
}
|
|
656
|
+
clear() {
|
|
657
|
+
this.snapshotStateMap.clear();
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
//#endregion
|
|
661
|
+
export { SnapshotClient, SnapshotState, addSerializer, getSerializers, stripSnapshotIndentation };
|