@noma.to/qwik-testing-library 1.3.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/README.md +18 -5
  2. package/lib/index.qwik.cjs +0 -4
  3. package/lib/index.qwik.mjs +0 -4
  4. package/lib/lib/qwik-testing-library.qwik.cjs +18 -6
  5. package/lib/lib/qwik-testing-library.qwik.mjs +18 -6
  6. package/lib-types/lib/qwik-testing-library.d.ts +1 -2
  7. package/package.json +9 -9
  8. package/lib/lib/mock.qwik.cjs +0 -14
  9. package/lib/lib/mock.qwik.mjs +0 -14
  10. package/lib/lib/qwikloader.qwik.cjs +0 -252
  11. package/lib/lib/qwikloader.qwik.mjs +0 -252
  12. package/lib/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.0/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.qwik.cjs +0 -89
  13. package/lib/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.0/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.qwik.mjs +0 -89
  14. package/lib/node_modules/.pnpm/@vitest_expect@3.0.5/node_modules/@vitest/expect/dist/index.qwik.cjs +0 -2191
  15. package/lib/node_modules/.pnpm/@vitest_expect@3.0.5/node_modules/@vitest/expect/dist/index.qwik.mjs +0 -2191
  16. package/lib/node_modules/.pnpm/@vitest_pretty-format@3.0.5/node_modules/@vitest/pretty-format/dist/index.qwik.cjs +0 -1499
  17. package/lib/node_modules/.pnpm/@vitest_pretty-format@3.0.5/node_modules/@vitest/pretty-format/dist/index.qwik.mjs +0 -1499
  18. package/lib/node_modules/.pnpm/@vitest_runner@3.0.5/node_modules/@vitest/runner/dist/chunk-tasks.qwik.cjs +0 -44
  19. package/lib/node_modules/.pnpm/@vitest_runner@3.0.5/node_modules/@vitest/runner/dist/chunk-tasks.qwik.mjs +0 -44
  20. package/lib/node_modules/.pnpm/@vitest_runner@3.0.5/node_modules/@vitest/runner/dist/index.qwik.cjs +0 -757
  21. package/lib/node_modules/.pnpm/@vitest_runner@3.0.5/node_modules/@vitest/runner/dist/index.qwik.mjs +0 -757
  22. package/lib/node_modules/.pnpm/@vitest_snapshot@3.0.5/node_modules/@vitest/snapshot/dist/index.qwik.cjs +0 -2079
  23. package/lib/node_modules/.pnpm/@vitest_snapshot@3.0.5/node_modules/@vitest/snapshot/dist/index.qwik.mjs +0 -2079
  24. package/lib/node_modules/.pnpm/@vitest_spy@3.0.5/node_modules/@vitest/spy/dist/index.qwik.cjs +0 -165
  25. package/lib/node_modules/.pnpm/@vitest_spy@3.0.5/node_modules/@vitest/spy/dist/index.qwik.mjs +0 -165
  26. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.qwik.cjs +0 -162
  27. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.qwik.mjs +0 -162
  28. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/diff.qwik.cjs +0 -1755
  29. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/diff.qwik.mjs +0 -1755
  30. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/error.qwik.cjs +0 -137
  31. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/error.qwik.mjs +0 -137
  32. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/helpers.qwik.cjs +0 -150
  33. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/helpers.qwik.mjs +0 -150
  34. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/index.qwik.cjs +0 -474
  35. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/index.qwik.mjs +0 -474
  36. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/source-map.qwik.cjs +0 -216
  37. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/source-map.qwik.mjs +0 -216
  38. package/lib/node_modules/.pnpm/chai@5.1.2/node_modules/chai/chai.qwik.cjs +0 -3937
  39. package/lib/node_modules/.pnpm/chai@5.1.2/node_modules/chai/chai.qwik.mjs +0 -3937
  40. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/arguments.qwik.cjs +0 -9
  41. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/arguments.qwik.mjs +0 -10
  42. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/array.qwik.cjs +0 -16
  43. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/array.qwik.mjs +0 -17
  44. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/bigint.qwik.cjs +0 -9
  45. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/bigint.qwik.mjs +0 -10
  46. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/class.qwik.cjs +0 -16
  47. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/class.qwik.mjs +0 -17
  48. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/date.qwik.cjs +0 -12
  49. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/date.qwik.mjs +0 -13
  50. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/error.qwik.cjs +0 -36
  51. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/error.qwik.mjs +0 -37
  52. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/function.qwik.cjs +0 -11
  53. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/function.qwik.mjs +0 -12
  54. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/helpers.qwik.cjs +0 -160
  55. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/helpers.qwik.mjs +0 -160
  56. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/html.qwik.cjs +0 -36
  57. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/html.qwik.mjs +0 -36
  58. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/index.qwik.cjs +0 -130
  59. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/index.qwik.mjs +0 -130
  60. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/map.qwik.cjs +0 -23
  61. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/map.qwik.mjs +0 -24
  62. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/number.qwik.cjs +0 -19
  63. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/number.qwik.mjs +0 -20
  64. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/object.qwik.cjs +0 -24
  65. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/object.qwik.mjs +0 -25
  66. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/promise.qwik.cjs +0 -17
  67. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/promise.qwik.mjs +0 -18
  68. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/regexp.qwik.cjs +0 -9
  69. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/regexp.qwik.mjs +0 -10
  70. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/set.qwik.cjs +0 -16
  71. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/set.qwik.mjs +0 -17
  72. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/string.qwik.cjs +0 -23
  73. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/string.qwik.mjs +0 -24
  74. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/symbol.qwik.cjs +0 -8
  75. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/symbol.qwik.mjs +0 -9
  76. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/typedarray.qwik.cjs +0 -34
  77. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/typedarray.qwik.mjs +0 -35
  78. package/lib/node_modules/.pnpm/magic-string@0.30.17/node_modules/magic-string/dist/magic-string.es.qwik.cjs +0 -979
  79. package/lib/node_modules/.pnpm/magic-string@0.30.17/node_modules/magic-string/dist/magic-string.es.qwik.mjs +0 -979
  80. package/lib/node_modules/.pnpm/pathe@2.0.2/node_modules/pathe/dist/shared/pathe.UZ-hd4nF.qwik.cjs +0 -101
  81. package/lib/node_modules/.pnpm/pathe@2.0.2/node_modules/pathe/dist/shared/pathe.UZ-hd4nF.qwik.mjs +0 -101
  82. package/lib/node_modules/.pnpm/tinyrainbow@2.0.0/node_modules/tinyrainbow/dist/browser.qwik.cjs +0 -4
  83. package/lib/node_modules/.pnpm/tinyrainbow@2.0.0/node_modules/tinyrainbow/dist/browser.qwik.mjs +0 -5
  84. package/lib/node_modules/.pnpm/tinyrainbow@2.0.0/node_modules/tinyrainbow/dist/chunk-BVHSVHOK.qwik.cjs +0 -80
  85. package/lib/node_modules/.pnpm/tinyrainbow@2.0.0/node_modules/tinyrainbow/dist/chunk-BVHSVHOK.qwik.mjs +0 -80
  86. package/lib/node_modules/.pnpm/tinyspy@3.0.2/node_modules/tinyspy/dist/index.qwik.cjs +0 -104
  87. package/lib/node_modules/.pnpm/tinyspy@3.0.2/node_modules/tinyspy/dist/index.qwik.mjs +0 -104
  88. package/lib/node_modules/.pnpm/vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0/node_modules/vitest/dist/chunks/_commonjsHelpers.BFTU3MAI.qwik.cjs +0 -8
  89. package/lib/node_modules/.pnpm/vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0/node_modules/vitest/dist/chunks/_commonjsHelpers.BFTU3MAI.qwik.mjs +0 -8
  90. package/lib/node_modules/.pnpm/vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0/node_modules/vitest/dist/chunks/date.W2xKR2qe.qwik.cjs +0 -56
  91. package/lib/node_modules/.pnpm/vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0/node_modules/vitest/dist/chunks/date.W2xKR2qe.qwik.mjs +0 -56
  92. package/lib/node_modules/.pnpm/vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0/node_modules/vitest/dist/chunks/utils.C8RiOc4B.qwik.cjs +0 -66
  93. package/lib/node_modules/.pnpm/vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0/node_modules/vitest/dist/chunks/utils.C8RiOc4B.qwik.mjs +0 -66
  94. package/lib/node_modules/.pnpm/vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0/node_modules/vitest/dist/chunks/vi.CjhMlMwf.qwik.cjs +0 -2977
  95. package/lib/node_modules/.pnpm/vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0/node_modules/vitest/dist/chunks/vi.CjhMlMwf.qwik.mjs +0 -2977
  96. package/lib-types/lib/mock.d.ts +0 -34
  97. package/lib-types/lib/qwikloader.d.ts +0 -1
@@ -1,2079 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- import { format, plugins } from "../../../../../@vitest_pretty-format@3.0.5/node_modules/@vitest/pretty-format/dist/index.qwik.mjs";
5
- import { r as resolve$2 } from "../../../../../pathe@2.0.2/node_modules/pathe/dist/shared/pathe.UZ-hd4nF.qwik.mjs";
6
- const comma = ",".charCodeAt(0);
7
- const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
8
- const intToChar = new Uint8Array(64);
9
- const charToInt = new Uint8Array(128);
10
- for (let i = 0; i < chars.length; i++) {
11
- const c = chars.charCodeAt(i);
12
- intToChar[i] = c;
13
- charToInt[c] = i;
14
- }
15
- function decodeInteger(reader, relative) {
16
- let value = 0;
17
- let shift = 0;
18
- let integer = 0;
19
- do {
20
- const c = reader.next();
21
- integer = charToInt[c];
22
- value |= (integer & 31) << shift;
23
- shift += 5;
24
- } while (integer & 32);
25
- const shouldNegate = value & 1;
26
- value >>>= 1;
27
- if (shouldNegate) {
28
- value = -2147483648 | -value;
29
- }
30
- return relative + value;
31
- }
32
- function hasMoreVlq(reader, max) {
33
- if (reader.pos >= max)
34
- return false;
35
- return reader.peek() !== comma;
36
- }
37
- class StringReader {
38
- constructor(buffer) {
39
- this.pos = 0;
40
- this.buffer = buffer;
41
- }
42
- next() {
43
- return this.buffer.charCodeAt(this.pos++);
44
- }
45
- peek() {
46
- return this.buffer.charCodeAt(this.pos);
47
- }
48
- indexOf(char) {
49
- const { buffer, pos } = this;
50
- const idx = buffer.indexOf(char, pos);
51
- return idx === -1 ? buffer.length : idx;
52
- }
53
- }
54
- function decode(mappings) {
55
- const { length } = mappings;
56
- const reader = new StringReader(mappings);
57
- const decoded = [];
58
- let genColumn = 0;
59
- let sourcesIndex = 0;
60
- let sourceLine = 0;
61
- let sourceColumn = 0;
62
- let namesIndex = 0;
63
- do {
64
- const semi = reader.indexOf(";");
65
- const line = [];
66
- let sorted = true;
67
- let lastCol = 0;
68
- genColumn = 0;
69
- while (reader.pos < semi) {
70
- let seg;
71
- genColumn = decodeInteger(reader, genColumn);
72
- if (genColumn < lastCol)
73
- sorted = false;
74
- lastCol = genColumn;
75
- if (hasMoreVlq(reader, semi)) {
76
- sourcesIndex = decodeInteger(reader, sourcesIndex);
77
- sourceLine = decodeInteger(reader, sourceLine);
78
- sourceColumn = decodeInteger(reader, sourceColumn);
79
- if (hasMoreVlq(reader, semi)) {
80
- namesIndex = decodeInteger(reader, namesIndex);
81
- seg = [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex];
82
- } else {
83
- seg = [genColumn, sourcesIndex, sourceLine, sourceColumn];
84
- }
85
- } else {
86
- seg = [genColumn];
87
- }
88
- line.push(seg);
89
- reader.pos++;
90
- }
91
- if (!sorted)
92
- sort(line);
93
- decoded.push(line);
94
- reader.pos = semi + 1;
95
- } while (reader.pos <= length);
96
- return decoded;
97
- }
98
- function sort(line) {
99
- line.sort(sortComparator$1);
100
- }
101
- function sortComparator$1(a2, b) {
102
- return a2[0] - b[0];
103
- }
104
- const schemeRegex = /^[\w+.-]+:\/\//;
105
- const urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#]*)?(#.*)?/;
106
- const fileRegex = /^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;
107
- var UrlType;
108
- (function(UrlType2) {
109
- UrlType2[UrlType2["Empty"] = 1] = "Empty";
110
- UrlType2[UrlType2["Hash"] = 2] = "Hash";
111
- UrlType2[UrlType2["Query"] = 3] = "Query";
112
- UrlType2[UrlType2["RelativePath"] = 4] = "RelativePath";
113
- UrlType2[UrlType2["AbsolutePath"] = 5] = "AbsolutePath";
114
- UrlType2[UrlType2["SchemeRelative"] = 6] = "SchemeRelative";
115
- UrlType2[UrlType2["Absolute"] = 7] = "Absolute";
116
- })(UrlType || (UrlType = {}));
117
- function isAbsoluteUrl(input) {
118
- return schemeRegex.test(input);
119
- }
120
- function isSchemeRelativeUrl(input) {
121
- return input.startsWith("//");
122
- }
123
- function isAbsolutePath(input) {
124
- return input.startsWith("/");
125
- }
126
- function isFileUrl(input) {
127
- return input.startsWith("file:");
128
- }
129
- function isRelative(input) {
130
- return /^[.?#]/.test(input);
131
- }
132
- function parseAbsoluteUrl(input) {
133
- const match = urlRegex.exec(input);
134
- return makeUrl(match[1], match[2] || "", match[3], match[4] || "", match[5] || "/", match[6] || "", match[7] || "");
135
- }
136
- function parseFileUrl(input) {
137
- const match = fileRegex.exec(input);
138
- const path = match[2];
139
- return makeUrl("file:", "", match[1] || "", "", isAbsolutePath(path) ? path : "/" + path, match[3] || "", match[4] || "");
140
- }
141
- function makeUrl(scheme, user, host, port, path, query, hash) {
142
- return {
143
- scheme,
144
- user,
145
- host,
146
- port,
147
- path,
148
- query,
149
- hash,
150
- type: UrlType.Absolute
151
- };
152
- }
153
- function parseUrl(input) {
154
- if (isSchemeRelativeUrl(input)) {
155
- const url2 = parseAbsoluteUrl("http:" + input);
156
- url2.scheme = "";
157
- url2.type = UrlType.SchemeRelative;
158
- return url2;
159
- }
160
- if (isAbsolutePath(input)) {
161
- const url2 = parseAbsoluteUrl("http://foo.com" + input);
162
- url2.scheme = "";
163
- url2.host = "";
164
- url2.type = UrlType.AbsolutePath;
165
- return url2;
166
- }
167
- if (isFileUrl(input))
168
- return parseFileUrl(input);
169
- if (isAbsoluteUrl(input))
170
- return parseAbsoluteUrl(input);
171
- const url = parseAbsoluteUrl("http://foo.com/" + input);
172
- url.scheme = "";
173
- url.host = "";
174
- url.type = input ? input.startsWith("?") ? UrlType.Query : input.startsWith("#") ? UrlType.Hash : UrlType.RelativePath : UrlType.Empty;
175
- return url;
176
- }
177
- function stripPathFilename(path) {
178
- if (path.endsWith("/.."))
179
- return path;
180
- const index = path.lastIndexOf("/");
181
- return path.slice(0, index + 1);
182
- }
183
- function mergePaths(url, base) {
184
- normalizePath(base, base.type);
185
- if (url.path === "/") {
186
- url.path = base.path;
187
- } else {
188
- url.path = stripPathFilename(base.path) + url.path;
189
- }
190
- }
191
- function normalizePath(url, type) {
192
- const rel = type <= UrlType.RelativePath;
193
- const pieces = url.path.split("/");
194
- let pointer = 1;
195
- let positive = 0;
196
- let addTrailingSlash = false;
197
- for (let i = 1; i < pieces.length; i++) {
198
- const piece = pieces[i];
199
- if (!piece) {
200
- addTrailingSlash = true;
201
- continue;
202
- }
203
- addTrailingSlash = false;
204
- if (piece === ".")
205
- continue;
206
- if (piece === "..") {
207
- if (positive) {
208
- addTrailingSlash = true;
209
- positive--;
210
- pointer--;
211
- } else if (rel) {
212
- pieces[pointer++] = piece;
213
- }
214
- continue;
215
- }
216
- pieces[pointer++] = piece;
217
- positive++;
218
- }
219
- let path = "";
220
- for (let i = 1; i < pointer; i++) {
221
- path += "/" + pieces[i];
222
- }
223
- if (!path || addTrailingSlash && !path.endsWith("/..")) {
224
- path += "/";
225
- }
226
- url.path = path;
227
- }
228
- function resolve$1(input, base) {
229
- if (!input && !base)
230
- return "";
231
- const url = parseUrl(input);
232
- let inputType = url.type;
233
- if (base && inputType !== UrlType.Absolute) {
234
- const baseUrl = parseUrl(base);
235
- const baseType = baseUrl.type;
236
- switch (inputType) {
237
- case UrlType.Empty:
238
- url.hash = baseUrl.hash;
239
- // fall through
240
- case UrlType.Hash:
241
- url.query = baseUrl.query;
242
- // fall through
243
- case UrlType.Query:
244
- case UrlType.RelativePath:
245
- mergePaths(url, baseUrl);
246
- // fall through
247
- case UrlType.AbsolutePath:
248
- url.user = baseUrl.user;
249
- url.host = baseUrl.host;
250
- url.port = baseUrl.port;
251
- // fall through
252
- case UrlType.SchemeRelative:
253
- url.scheme = baseUrl.scheme;
254
- }
255
- if (baseType > inputType)
256
- inputType = baseType;
257
- }
258
- normalizePath(url, inputType);
259
- const queryHash = url.query + url.hash;
260
- switch (inputType) {
261
- // This is impossible, because of the empty checks at the start of the function.
262
- // case UrlType.Empty:
263
- case UrlType.Hash:
264
- case UrlType.Query:
265
- return queryHash;
266
- case UrlType.RelativePath: {
267
- const path = url.path.slice(1);
268
- if (!path)
269
- return queryHash || ".";
270
- if (isRelative(base || input) && !isRelative(path)) {
271
- return "./" + path + queryHash;
272
- }
273
- return path + queryHash;
274
- }
275
- case UrlType.AbsolutePath:
276
- return url.path + queryHash;
277
- default:
278
- return url.scheme + "//" + url.user + url.host + url.port + url.path + queryHash;
279
- }
280
- }
281
- function resolve(input, base) {
282
- if (base && !base.endsWith("/"))
283
- base += "/";
284
- return resolve$1(input, base);
285
- }
286
- function stripFilename(path) {
287
- if (!path)
288
- return "";
289
- const index = path.lastIndexOf("/");
290
- return path.slice(0, index + 1);
291
- }
292
- const COLUMN = 0;
293
- const SOURCES_INDEX = 1;
294
- const SOURCE_LINE = 2;
295
- const SOURCE_COLUMN = 3;
296
- const NAMES_INDEX = 4;
297
- function maybeSort(mappings, owned) {
298
- const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
299
- if (unsortedIndex === mappings.length)
300
- return mappings;
301
- if (!owned)
302
- mappings = mappings.slice();
303
- for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) {
304
- mappings[i] = sortSegments(mappings[i], owned);
305
- }
306
- return mappings;
307
- }
308
- function nextUnsortedSegmentLine(mappings, start) {
309
- for (let i = start; i < mappings.length; i++) {
310
- if (!isSorted(mappings[i]))
311
- return i;
312
- }
313
- return mappings.length;
314
- }
315
- function isSorted(line) {
316
- for (let j = 1; j < line.length; j++) {
317
- if (line[j][COLUMN] < line[j - 1][COLUMN]) {
318
- return false;
319
- }
320
- }
321
- return true;
322
- }
323
- function sortSegments(line, owned) {
324
- if (!owned)
325
- line = line.slice();
326
- return line.sort(sortComparator);
327
- }
328
- function sortComparator(a2, b) {
329
- return a2[COLUMN] - b[COLUMN];
330
- }
331
- let found = false;
332
- function binarySearch(haystack, needle, low, high) {
333
- while (low <= high) {
334
- const mid = low + (high - low >> 1);
335
- const cmp = haystack[mid][COLUMN] - needle;
336
- if (cmp === 0) {
337
- found = true;
338
- return mid;
339
- }
340
- if (cmp < 0) {
341
- low = mid + 1;
342
- } else {
343
- high = mid - 1;
344
- }
345
- }
346
- found = false;
347
- return low - 1;
348
- }
349
- function upperBound(haystack, needle, index) {
350
- for (let i = index + 1; i < haystack.length; index = i++) {
351
- if (haystack[i][COLUMN] !== needle)
352
- break;
353
- }
354
- return index;
355
- }
356
- function lowerBound(haystack, needle, index) {
357
- for (let i = index - 1; i >= 0; index = i--) {
358
- if (haystack[i][COLUMN] !== needle)
359
- break;
360
- }
361
- return index;
362
- }
363
- function memoizedState() {
364
- return {
365
- lastKey: -1,
366
- lastNeedle: -1,
367
- lastIndex: -1
368
- };
369
- }
370
- function memoizedBinarySearch(haystack, needle, state, key) {
371
- const { lastKey, lastNeedle, lastIndex } = state;
372
- let low = 0;
373
- let high = haystack.length - 1;
374
- if (key === lastKey) {
375
- if (needle === lastNeedle) {
376
- found = lastIndex !== -1 && haystack[lastIndex][COLUMN] === needle;
377
- return lastIndex;
378
- }
379
- if (needle >= lastNeedle) {
380
- low = lastIndex === -1 ? 0 : lastIndex;
381
- } else {
382
- high = lastIndex;
383
- }
384
- }
385
- state.lastKey = key;
386
- state.lastNeedle = needle;
387
- return state.lastIndex = binarySearch(haystack, needle, low, high);
388
- }
389
- const LINE_GTR_ZERO = "`line` must be greater than 0 (lines start at line 1)";
390
- const COL_GTR_EQ_ZERO = "`column` must be greater than or equal to 0 (columns start at column 0)";
391
- const LEAST_UPPER_BOUND = -1;
392
- const GREATEST_LOWER_BOUND = 1;
393
- class TraceMap {
394
- constructor(map, mapUrl) {
395
- const isString = typeof map === "string";
396
- if (!isString && map._decodedMemo)
397
- return map;
398
- const parsed = isString ? JSON.parse(map) : map;
399
- const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
400
- this.version = version;
401
- this.file = file;
402
- this.names = names || [];
403
- this.sourceRoot = sourceRoot;
404
- this.sources = sources;
405
- this.sourcesContent = sourcesContent;
406
- this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || void 0;
407
- const from = resolve(sourceRoot || "", stripFilename(mapUrl));
408
- this.resolvedSources = sources.map((s) => resolve(s || "", from));
409
- const { mappings } = parsed;
410
- if (typeof mappings === "string") {
411
- this._encoded = mappings;
412
- this._decoded = void 0;
413
- } else {
414
- this._encoded = void 0;
415
- this._decoded = maybeSort(mappings, isString);
416
- }
417
- this._decodedMemo = memoizedState();
418
- this._bySources = void 0;
419
- this._bySourceMemos = void 0;
420
- }
421
- }
422
- function cast(map) {
423
- return map;
424
- }
425
- function decodedMappings(map) {
426
- var _a;
427
- return (_a = cast(map))._decoded || (_a._decoded = decode(cast(map)._encoded));
428
- }
429
- function originalPositionFor(map, needle) {
430
- let { line, column, bias } = needle;
431
- line--;
432
- if (line < 0)
433
- throw new Error(LINE_GTR_ZERO);
434
- if (column < 0)
435
- throw new Error(COL_GTR_EQ_ZERO);
436
- const decoded = decodedMappings(map);
437
- if (line >= decoded.length)
438
- return OMapping(null, null, null, null);
439
- const segments = decoded[line];
440
- const index = traceSegmentInternal(segments, cast(map)._decodedMemo, line, column, bias || GREATEST_LOWER_BOUND);
441
- if (index === -1)
442
- return OMapping(null, null, null, null);
443
- const segment = segments[index];
444
- if (segment.length === 1)
445
- return OMapping(null, null, null, null);
446
- const { names, resolvedSources } = map;
447
- return OMapping(resolvedSources[segment[SOURCES_INDEX]], segment[SOURCE_LINE] + 1, segment[SOURCE_COLUMN], segment.length === 5 ? names[segment[NAMES_INDEX]] : null);
448
- }
449
- function OMapping(source, line, column, name) {
450
- return { source, line, column, name };
451
- }
452
- function traceSegmentInternal(segments, memo, line, column, bias) {
453
- let index = memoizedBinarySearch(segments, column, memo, line);
454
- if (found) {
455
- index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index);
456
- } else if (bias === LEAST_UPPER_BOUND)
457
- index++;
458
- if (index === -1 || index === segments.length)
459
- return -1;
460
- return index;
461
- }
462
- function notNullish(v) {
463
- return v != null;
464
- }
465
- function isPrimitive(value) {
466
- return value === null || typeof value !== "function" && typeof value !== "object";
467
- }
468
- function isObject(item) {
469
- return item != null && typeof item === "object" && !Array.isArray(item);
470
- }
471
- function getCallLastIndex(code) {
472
- let charIndex = -1;
473
- let inString = null;
474
- let startedBracers = 0;
475
- let endedBracers = 0;
476
- let beforeChar = null;
477
- while (charIndex <= code.length) {
478
- beforeChar = code[charIndex];
479
- charIndex++;
480
- const char = code[charIndex];
481
- const isCharString = char === '"' || char === "'" || char === "`";
482
- if (isCharString && beforeChar !== "\\") {
483
- if (inString === char) {
484
- inString = null;
485
- } else if (!inString) {
486
- inString = char;
487
- }
488
- }
489
- if (!inString) {
490
- if (char === "(") {
491
- startedBracers++;
492
- }
493
- if (char === ")") {
494
- endedBracers++;
495
- }
496
- }
497
- if (startedBracers && endedBracers && startedBracers === endedBracers) {
498
- return charIndex;
499
- }
500
- }
501
- return null;
502
- }
503
- const CHROME_IE_STACK_REGEXP = /^\s*at .*(?:\S:\d+|\(native\))/m;
504
- const SAFARI_NATIVE_CODE_REGEXP = /^(?:eval@)?(?:\[native code\])?$/;
505
- const stackIgnorePatterns = [
506
- "node:internal",
507
- /\/packages\/\w+\/dist\//,
508
- /\/@vitest\/\w+\/dist\//,
509
- "/vitest/dist/",
510
- "/vitest/src/",
511
- "/vite-node/dist/",
512
- "/vite-node/src/",
513
- "/node_modules/chai/",
514
- "/node_modules/tinypool/",
515
- "/node_modules/tinyspy/",
516
- // browser related deps
517
- "/deps/chunk-",
518
- "/deps/@vitest",
519
- "/deps/loupe",
520
- "/deps/chai",
521
- /node:\w+/,
522
- /__vitest_test__/,
523
- /__vitest_browser__/,
524
- /\/deps\/vitest_/
525
- ];
526
- function extractLocation(urlLike) {
527
- if (!urlLike.includes(":")) {
528
- return [urlLike];
529
- }
530
- const regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
531
- const parts = regExp.exec(urlLike.replace(/^\(|\)$/g, ""));
532
- if (!parts) {
533
- return [urlLike];
534
- }
535
- let url = parts[1];
536
- if (url.startsWith("async ")) {
537
- url = url.slice(6);
538
- }
539
- if (url.startsWith("http:") || url.startsWith("https:")) {
540
- const urlObj = new URL(url);
541
- url = urlObj.pathname;
542
- }
543
- if (url.startsWith("/@fs/")) {
544
- const isWindows = /^\/@fs\/[a-zA-Z]:\//.test(url);
545
- url = url.slice(isWindows ? 5 : 4);
546
- }
547
- return [url, parts[2] || void 0, parts[3] || void 0];
548
- }
549
- function parseSingleFFOrSafariStack(raw) {
550
- let line = raw.trim();
551
- if (SAFARI_NATIVE_CODE_REGEXP.test(line)) {
552
- return null;
553
- }
554
- if (line.includes(" > eval")) {
555
- line = line.replace(
556
- / line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g,
557
- ":$1"
558
- );
559
- }
560
- if (!line.includes("@") && !line.includes(":")) {
561
- return null;
562
- }
563
- const functionNameRegex = /((.*".+"[^@]*)?[^@]*)(@)/;
564
- const matches = line.match(functionNameRegex);
565
- const functionName = matches && matches[1] ? matches[1] : void 0;
566
- const [url, lineNumber, columnNumber] = extractLocation(
567
- line.replace(functionNameRegex, "")
568
- );
569
- if (!url || !lineNumber || !columnNumber) {
570
- return null;
571
- }
572
- return {
573
- file: url,
574
- method: functionName || "",
575
- line: Number.parseInt(lineNumber),
576
- column: Number.parseInt(columnNumber)
577
- };
578
- }
579
- function parseSingleV8Stack(raw) {
580
- let line = raw.trim();
581
- if (!CHROME_IE_STACK_REGEXP.test(line)) {
582
- return null;
583
- }
584
- if (line.includes("(eval ")) {
585
- line = line.replace(/eval code/g, "eval").replace(/(\(eval at [^()]*)|(,.*$)/g, "");
586
- }
587
- let sanitizedLine = line.replace(/^\s+/, "").replace(/\(eval code/g, "(").replace(/^.*?\s+/, "");
588
- const location = sanitizedLine.match(/ (\(.+\)$)/);
589
- sanitizedLine = location ? sanitizedLine.replace(location[0], "") : sanitizedLine;
590
- const [url, lineNumber, columnNumber] = extractLocation(
591
- location ? location[1] : sanitizedLine
592
- );
593
- let method = location && sanitizedLine || "";
594
- let file = url && ["eval", "<anonymous>"].includes(url) ? void 0 : url;
595
- if (!file || !lineNumber || !columnNumber) {
596
- return null;
597
- }
598
- if (method.startsWith("async ")) {
599
- method = method.slice(6);
600
- }
601
- if (file.startsWith("file://")) {
602
- file = file.slice(7);
603
- }
604
- file = file.startsWith("node:") || file.startsWith("internal:") ? file : resolve$2(file);
605
- if (method) {
606
- method = method.replace(/__vite_ssr_import_\d+__\./g, "");
607
- }
608
- return {
609
- method,
610
- file,
611
- line: Number.parseInt(lineNumber),
612
- column: Number.parseInt(columnNumber)
613
- };
614
- }
615
- function parseStacktrace(stack, options = {}) {
616
- const { ignoreStackEntries = stackIgnorePatterns } = options;
617
- let stacks = !CHROME_IE_STACK_REGEXP.test(stack) ? parseFFOrSafariStackTrace(stack) : parseV8Stacktrace(stack);
618
- if (ignoreStackEntries.length) {
619
- stacks = stacks.filter(
620
- (stack2) => !ignoreStackEntries.some((p2) => stack2.file.match(p2))
621
- );
622
- }
623
- return stacks.map((stack2) => {
624
- var _a;
625
- if (options.getFileName) {
626
- stack2.file = options.getFileName(stack2.file);
627
- }
628
- const map = (_a = options.getSourceMap) == null ? void 0 : _a.call(options, stack2.file);
629
- if (!map || typeof map !== "object" || !map.version) {
630
- return stack2;
631
- }
632
- const traceMap = new TraceMap(map);
633
- const { line, column } = originalPositionFor(traceMap, stack2);
634
- if (line != null && column != null) {
635
- return { ...stack2, line, column };
636
- }
637
- return stack2;
638
- });
639
- }
640
- function parseFFOrSafariStackTrace(stack) {
641
- return stack.split("\n").map((line) => parseSingleFFOrSafariStack(line)).filter(notNullish);
642
- }
643
- function parseV8Stacktrace(stack) {
644
- return stack.split("\n").map((line) => parseSingleV8Stack(line)).filter(notNullish);
645
- }
646
- function parseErrorStacktrace(e, options = {}) {
647
- if (!e || isPrimitive(e)) {
648
- return [];
649
- }
650
- if (e.stacks) {
651
- return e.stacks;
652
- }
653
- const stackStr = e.stack || e.stackStr || "";
654
- let stackFrames = parseStacktrace(stackStr, options);
655
- if (options.frameFilter) {
656
- stackFrames = stackFrames.filter(
657
- (f2) => options.frameFilter(e, f2) !== false
658
- );
659
- }
660
- e.stacks = stackFrames;
661
- return stackFrames;
662
- }
663
- let getPromiseValue = () => "Promise{…}";
664
- try {
665
- const { getPromiseDetails, kPending, kRejected } = process.binding("util");
666
- if (Array.isArray(getPromiseDetails(Promise.resolve()))) {
667
- getPromiseValue = (value, options) => {
668
- const [state, innerValue] = getPromiseDetails(value);
669
- if (state === kPending) {
670
- return "Promise{<pending>}";
671
- }
672
- return `Promise${state === kRejected ? "!" : ""}{${options.inspect(innerValue, options)}}`;
673
- };
674
- }
675
- } catch (notNode) {
676
- }
677
- let nodeInspect = false;
678
- try {
679
- const nodeUtil = require("util");
680
- nodeInspect = nodeUtil.inspect ? nodeUtil.inspect.custom : false;
681
- } catch (noNodeInspect) {
682
- nodeInspect = false;
683
- }
684
- function getDefaultExportFromCjs(x) {
685
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
686
- }
687
- var jsTokens_1;
688
- var hasRequiredJsTokens;
689
- function requireJsTokens() {
690
- if (hasRequiredJsTokens) return jsTokens_1;
691
- hasRequiredJsTokens = 1;
692
- var Identifier, JSXIdentifier, JSXPunctuator, JSXString, JSXText, KeywordsWithExpressionAfter, KeywordsWithNoLineTerminatorAfter, LineTerminatorSequence, MultiLineComment, Newline, NumericLiteral, Punctuator, RegularExpressionLiteral, SingleLineComment, StringLiteral, Template, TokensNotPrecedingObjectLiteral, TokensPrecedingExpression, WhiteSpace;
693
- RegularExpressionLiteral = /\/(?![*\/])(?:\[(?:(?![\]\\]).|\\.)*\]|(?![\/\\]).|\\.)*(\/[$_\u200C\u200D\p{ID_Continue}]*|\\)?/yu;
694
- Punctuator = /--|\+\+|=>|\.{3}|\??\.(?!\d)|(?:&&|\|\||\?\?|[+\-%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2}|\/(?![\/*]))=?|[?~,:;[\](){}]/y;
695
- Identifier = /(\x23?)(?=[$_\p{ID_Start}\\])(?:[$_\u200C\u200D\p{ID_Continue}]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+/yu;
696
- StringLiteral = /(['"])(?:(?!\1)[^\\\n\r]|\\(?:\r\n|[^]))*(\1)?/y;
697
- NumericLiteral = /(?:0[xX][\da-fA-F](?:_?[\da-fA-F])*|0[oO][0-7](?:_?[0-7])*|0[bB][01](?:_?[01])*)n?|0n|[1-9](?:_?\d)*n|(?:(?:0(?!\d)|0\d*[89]\d*|[1-9](?:_?\d)*)(?:\.(?:\d(?:_?\d)*)?)?|\.\d(?:_?\d)*)(?:[eE][+-]?\d(?:_?\d)*)?|0[0-7]+/y;
698
- Template = /[`}](?:[^`\\$]|\\[^]|\$(?!\{))*(`|\$\{)?/y;
699
- WhiteSpace = /[\t\v\f\ufeff\p{Zs}]+/yu;
700
- LineTerminatorSequence = /\r?\n|[\r\u2028\u2029]/y;
701
- MultiLineComment = /\/\*(?:[^*]|\*(?!\/))*(\*\/)?/y;
702
- SingleLineComment = /\/\/.*/y;
703
- JSXPunctuator = /[<>.:={}]|\/(?![\/*])/y;
704
- JSXIdentifier = /[$_\p{ID_Start}][$_\u200C\u200D\p{ID_Continue}-]*/yu;
705
- JSXString = /(['"])(?:(?!\1)[^])*(\1)?/y;
706
- JSXText = /[^<>{}]+/y;
707
- TokensPrecedingExpression = /^(?:[\/+-]|\.{3}|\?(?:InterpolationIn(?:JSX|Template)|NoLineTerminatorHere|NonExpressionParenEnd|UnaryIncDec))?$|[{}([,;<>=*%&|^!~?:]$/;
708
- TokensNotPrecedingObjectLiteral = /^(?:=>|[;\]){}]|else|\?(?:NoLineTerminatorHere|NonExpressionParenEnd))?$/;
709
- KeywordsWithExpressionAfter = /^(?:await|case|default|delete|do|else|instanceof|new|return|throw|typeof|void|yield)$/;
710
- KeywordsWithNoLineTerminatorAfter = /^(?:return|throw|yield)$/;
711
- Newline = RegExp(LineTerminatorSequence.source);
712
- jsTokens_1 = function* (input, { jsx = false } = {}) {
713
- var braces, firstCodePoint, isExpression, lastIndex, lastSignificantToken, length, match, mode, nextLastIndex, nextLastSignificantToken, parenNesting, postfixIncDec, punctuator, stack;
714
- ({ length } = input);
715
- lastIndex = 0;
716
- lastSignificantToken = "";
717
- stack = [
718
- { tag: "JS" }
719
- ];
720
- braces = [];
721
- parenNesting = 0;
722
- postfixIncDec = false;
723
- while (lastIndex < length) {
724
- mode = stack[stack.length - 1];
725
- switch (mode.tag) {
726
- case "JS":
727
- case "JSNonExpressionParen":
728
- case "InterpolationInTemplate":
729
- case "InterpolationInJSX":
730
- if (input[lastIndex] === "/" && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken))) {
731
- RegularExpressionLiteral.lastIndex = lastIndex;
732
- if (match = RegularExpressionLiteral.exec(input)) {
733
- lastIndex = RegularExpressionLiteral.lastIndex;
734
- lastSignificantToken = match[0];
735
- postfixIncDec = true;
736
- yield {
737
- type: "RegularExpressionLiteral",
738
- value: match[0],
739
- closed: match[1] !== void 0 && match[1] !== "\\"
740
- };
741
- continue;
742
- }
743
- }
744
- Punctuator.lastIndex = lastIndex;
745
- if (match = Punctuator.exec(input)) {
746
- punctuator = match[0];
747
- nextLastIndex = Punctuator.lastIndex;
748
- nextLastSignificantToken = punctuator;
749
- switch (punctuator) {
750
- case "(":
751
- if (lastSignificantToken === "?NonExpressionParenKeyword") {
752
- stack.push({
753
- tag: "JSNonExpressionParen",
754
- nesting: parenNesting
755
- });
756
- }
757
- parenNesting++;
758
- postfixIncDec = false;
759
- break;
760
- case ")":
761
- parenNesting--;
762
- postfixIncDec = true;
763
- if (mode.tag === "JSNonExpressionParen" && parenNesting === mode.nesting) {
764
- stack.pop();
765
- nextLastSignificantToken = "?NonExpressionParenEnd";
766
- postfixIncDec = false;
767
- }
768
- break;
769
- case "{":
770
- Punctuator.lastIndex = 0;
771
- isExpression = !TokensNotPrecedingObjectLiteral.test(lastSignificantToken) && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken));
772
- braces.push(isExpression);
773
- postfixIncDec = false;
774
- break;
775
- case "}":
776
- switch (mode.tag) {
777
- case "InterpolationInTemplate":
778
- if (braces.length === mode.nesting) {
779
- Template.lastIndex = lastIndex;
780
- match = Template.exec(input);
781
- lastIndex = Template.lastIndex;
782
- lastSignificantToken = match[0];
783
- if (match[1] === "${") {
784
- lastSignificantToken = "?InterpolationInTemplate";
785
- postfixIncDec = false;
786
- yield {
787
- type: "TemplateMiddle",
788
- value: match[0]
789
- };
790
- } else {
791
- stack.pop();
792
- postfixIncDec = true;
793
- yield {
794
- type: "TemplateTail",
795
- value: match[0],
796
- closed: match[1] === "`"
797
- };
798
- }
799
- continue;
800
- }
801
- break;
802
- case "InterpolationInJSX":
803
- if (braces.length === mode.nesting) {
804
- stack.pop();
805
- lastIndex += 1;
806
- lastSignificantToken = "}";
807
- yield {
808
- type: "JSXPunctuator",
809
- value: "}"
810
- };
811
- continue;
812
- }
813
- }
814
- postfixIncDec = braces.pop();
815
- nextLastSignificantToken = postfixIncDec ? "?ExpressionBraceEnd" : "}";
816
- break;
817
- case "]":
818
- postfixIncDec = true;
819
- break;
820
- case "++":
821
- case "--":
822
- nextLastSignificantToken = postfixIncDec ? "?PostfixIncDec" : "?UnaryIncDec";
823
- break;
824
- case "<":
825
- if (jsx && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken))) {
826
- stack.push({ tag: "JSXTag" });
827
- lastIndex += 1;
828
- lastSignificantToken = "<";
829
- yield {
830
- type: "JSXPunctuator",
831
- value: punctuator
832
- };
833
- continue;
834
- }
835
- postfixIncDec = false;
836
- break;
837
- default:
838
- postfixIncDec = false;
839
- }
840
- lastIndex = nextLastIndex;
841
- lastSignificantToken = nextLastSignificantToken;
842
- yield {
843
- type: "Punctuator",
844
- value: punctuator
845
- };
846
- continue;
847
- }
848
- Identifier.lastIndex = lastIndex;
849
- if (match = Identifier.exec(input)) {
850
- lastIndex = Identifier.lastIndex;
851
- nextLastSignificantToken = match[0];
852
- switch (match[0]) {
853
- case "for":
854
- case "if":
855
- case "while":
856
- case "with":
857
- if (lastSignificantToken !== "." && lastSignificantToken !== "?.") {
858
- nextLastSignificantToken = "?NonExpressionParenKeyword";
859
- }
860
- }
861
- lastSignificantToken = nextLastSignificantToken;
862
- postfixIncDec = !KeywordsWithExpressionAfter.test(match[0]);
863
- yield {
864
- type: match[1] === "#" ? "PrivateIdentifier" : "IdentifierName",
865
- value: match[0]
866
- };
867
- continue;
868
- }
869
- StringLiteral.lastIndex = lastIndex;
870
- if (match = StringLiteral.exec(input)) {
871
- lastIndex = StringLiteral.lastIndex;
872
- lastSignificantToken = match[0];
873
- postfixIncDec = true;
874
- yield {
875
- type: "StringLiteral",
876
- value: match[0],
877
- closed: match[2] !== void 0
878
- };
879
- continue;
880
- }
881
- NumericLiteral.lastIndex = lastIndex;
882
- if (match = NumericLiteral.exec(input)) {
883
- lastIndex = NumericLiteral.lastIndex;
884
- lastSignificantToken = match[0];
885
- postfixIncDec = true;
886
- yield {
887
- type: "NumericLiteral",
888
- value: match[0]
889
- };
890
- continue;
891
- }
892
- Template.lastIndex = lastIndex;
893
- if (match = Template.exec(input)) {
894
- lastIndex = Template.lastIndex;
895
- lastSignificantToken = match[0];
896
- if (match[1] === "${") {
897
- lastSignificantToken = "?InterpolationInTemplate";
898
- stack.push({
899
- tag: "InterpolationInTemplate",
900
- nesting: braces.length
901
- });
902
- postfixIncDec = false;
903
- yield {
904
- type: "TemplateHead",
905
- value: match[0]
906
- };
907
- } else {
908
- postfixIncDec = true;
909
- yield {
910
- type: "NoSubstitutionTemplate",
911
- value: match[0],
912
- closed: match[1] === "`"
913
- };
914
- }
915
- continue;
916
- }
917
- break;
918
- case "JSXTag":
919
- case "JSXTagEnd":
920
- JSXPunctuator.lastIndex = lastIndex;
921
- if (match = JSXPunctuator.exec(input)) {
922
- lastIndex = JSXPunctuator.lastIndex;
923
- nextLastSignificantToken = match[0];
924
- switch (match[0]) {
925
- case "<":
926
- stack.push({ tag: "JSXTag" });
927
- break;
928
- case ">":
929
- stack.pop();
930
- if (lastSignificantToken === "/" || mode.tag === "JSXTagEnd") {
931
- nextLastSignificantToken = "?JSX";
932
- postfixIncDec = true;
933
- } else {
934
- stack.push({ tag: "JSXChildren" });
935
- }
936
- break;
937
- case "{":
938
- stack.push({
939
- tag: "InterpolationInJSX",
940
- nesting: braces.length
941
- });
942
- nextLastSignificantToken = "?InterpolationInJSX";
943
- postfixIncDec = false;
944
- break;
945
- case "/":
946
- if (lastSignificantToken === "<") {
947
- stack.pop();
948
- if (stack[stack.length - 1].tag === "JSXChildren") {
949
- stack.pop();
950
- }
951
- stack.push({ tag: "JSXTagEnd" });
952
- }
953
- }
954
- lastSignificantToken = nextLastSignificantToken;
955
- yield {
956
- type: "JSXPunctuator",
957
- value: match[0]
958
- };
959
- continue;
960
- }
961
- JSXIdentifier.lastIndex = lastIndex;
962
- if (match = JSXIdentifier.exec(input)) {
963
- lastIndex = JSXIdentifier.lastIndex;
964
- lastSignificantToken = match[0];
965
- yield {
966
- type: "JSXIdentifier",
967
- value: match[0]
968
- };
969
- continue;
970
- }
971
- JSXString.lastIndex = lastIndex;
972
- if (match = JSXString.exec(input)) {
973
- lastIndex = JSXString.lastIndex;
974
- lastSignificantToken = match[0];
975
- yield {
976
- type: "JSXString",
977
- value: match[0],
978
- closed: match[2] !== void 0
979
- };
980
- continue;
981
- }
982
- break;
983
- case "JSXChildren":
984
- JSXText.lastIndex = lastIndex;
985
- if (match = JSXText.exec(input)) {
986
- lastIndex = JSXText.lastIndex;
987
- lastSignificantToken = match[0];
988
- yield {
989
- type: "JSXText",
990
- value: match[0]
991
- };
992
- continue;
993
- }
994
- switch (input[lastIndex]) {
995
- case "<":
996
- stack.push({ tag: "JSXTag" });
997
- lastIndex++;
998
- lastSignificantToken = "<";
999
- yield {
1000
- type: "JSXPunctuator",
1001
- value: "<"
1002
- };
1003
- continue;
1004
- case "{":
1005
- stack.push({
1006
- tag: "InterpolationInJSX",
1007
- nesting: braces.length
1008
- });
1009
- lastIndex++;
1010
- lastSignificantToken = "?InterpolationInJSX";
1011
- postfixIncDec = false;
1012
- yield {
1013
- type: "JSXPunctuator",
1014
- value: "{"
1015
- };
1016
- continue;
1017
- }
1018
- }
1019
- WhiteSpace.lastIndex = lastIndex;
1020
- if (match = WhiteSpace.exec(input)) {
1021
- lastIndex = WhiteSpace.lastIndex;
1022
- yield {
1023
- type: "WhiteSpace",
1024
- value: match[0]
1025
- };
1026
- continue;
1027
- }
1028
- LineTerminatorSequence.lastIndex = lastIndex;
1029
- if (match = LineTerminatorSequence.exec(input)) {
1030
- lastIndex = LineTerminatorSequence.lastIndex;
1031
- postfixIncDec = false;
1032
- if (KeywordsWithNoLineTerminatorAfter.test(lastSignificantToken)) {
1033
- lastSignificantToken = "?NoLineTerminatorHere";
1034
- }
1035
- yield {
1036
- type: "LineTerminatorSequence",
1037
- value: match[0]
1038
- };
1039
- continue;
1040
- }
1041
- MultiLineComment.lastIndex = lastIndex;
1042
- if (match = MultiLineComment.exec(input)) {
1043
- lastIndex = MultiLineComment.lastIndex;
1044
- if (Newline.test(match[0])) {
1045
- postfixIncDec = false;
1046
- if (KeywordsWithNoLineTerminatorAfter.test(lastSignificantToken)) {
1047
- lastSignificantToken = "?NoLineTerminatorHere";
1048
- }
1049
- }
1050
- yield {
1051
- type: "MultiLineComment",
1052
- value: match[0],
1053
- closed: match[1] !== void 0
1054
- };
1055
- continue;
1056
- }
1057
- SingleLineComment.lastIndex = lastIndex;
1058
- if (match = SingleLineComment.exec(input)) {
1059
- lastIndex = SingleLineComment.lastIndex;
1060
- postfixIncDec = false;
1061
- yield {
1062
- type: "SingleLineComment",
1063
- value: match[0]
1064
- };
1065
- continue;
1066
- }
1067
- firstCodePoint = String.fromCodePoint(input.codePointAt(lastIndex));
1068
- lastIndex += firstCodePoint.length;
1069
- lastSignificantToken = firstCodePoint;
1070
- postfixIncDec = false;
1071
- yield {
1072
- type: mode.tag.startsWith("JSX") ? "JSXInvalid" : "Invalid",
1073
- value: firstCodePoint
1074
- };
1075
- }
1076
- return void 0;
1077
- };
1078
- return jsTokens_1;
1079
- }
1080
- requireJsTokens();
1081
- var reservedWords = {
1082
- keyword: [
1083
- "break",
1084
- "case",
1085
- "catch",
1086
- "continue",
1087
- "debugger",
1088
- "default",
1089
- "do",
1090
- "else",
1091
- "finally",
1092
- "for",
1093
- "function",
1094
- "if",
1095
- "return",
1096
- "switch",
1097
- "throw",
1098
- "try",
1099
- "var",
1100
- "const",
1101
- "while",
1102
- "with",
1103
- "new",
1104
- "this",
1105
- "super",
1106
- "class",
1107
- "extends",
1108
- "export",
1109
- "import",
1110
- "null",
1111
- "true",
1112
- "false",
1113
- "in",
1114
- "instanceof",
1115
- "typeof",
1116
- "void",
1117
- "delete"
1118
- ],
1119
- strict: [
1120
- "implements",
1121
- "interface",
1122
- "let",
1123
- "package",
1124
- "private",
1125
- "protected",
1126
- "public",
1127
- "static",
1128
- "yield"
1129
- ]
1130
- };
1131
- new Set(reservedWords.keyword);
1132
- new Set(reservedWords.strict);
1133
- var f = {
1134
- reset: [0, 0],
1135
- bold: [1, 22, "\x1B[22m\x1B[1m"],
1136
- dim: [2, 22, "\x1B[22m\x1B[2m"],
1137
- italic: [3, 23],
1138
- underline: [4, 24],
1139
- inverse: [7, 27],
1140
- hidden: [8, 28],
1141
- strikethrough: [9, 29],
1142
- black: [30, 39],
1143
- red: [31, 39],
1144
- green: [32, 39],
1145
- yellow: [33, 39],
1146
- blue: [34, 39],
1147
- magenta: [35, 39],
1148
- cyan: [36, 39],
1149
- white: [37, 39],
1150
- gray: [90, 39],
1151
- bgBlack: [40, 49],
1152
- bgRed: [41, 49],
1153
- bgGreen: [42, 49],
1154
- bgYellow: [43, 49],
1155
- bgBlue: [44, 49],
1156
- bgMagenta: [45, 49],
1157
- bgCyan: [46, 49],
1158
- bgWhite: [47, 49],
1159
- blackBright: [90, 39],
1160
- redBright: [91, 39],
1161
- greenBright: [92, 39],
1162
- yellowBright: [93, 39],
1163
- blueBright: [94, 39],
1164
- magentaBright: [95, 39],
1165
- cyanBright: [96, 39],
1166
- whiteBright: [97, 39],
1167
- bgBlackBright: [100, 49],
1168
- bgRedBright: [101, 49],
1169
- bgGreenBright: [102, 49],
1170
- bgYellowBright: [103, 49],
1171
- bgBlueBright: [104, 49],
1172
- bgMagentaBright: [105, 49],
1173
- bgCyanBright: [106, 49],
1174
- bgWhiteBright: [107, 49]
1175
- }, h = Object.entries(f);
1176
- function a(n) {
1177
- return String(n);
1178
- }
1179
- a.open = "";
1180
- a.close = "";
1181
- function C(n = false) {
1182
- let e = typeof process != "undefined" ? process : void 0, i = (e == null ? void 0 : e.env) || {}, g = (e == null ? void 0 : e.argv) || [];
1183
- return !("NO_COLOR" in i || g.includes("--no-color")) && ("FORCE_COLOR" in i || g.includes("--color") || (e == null ? void 0 : e.platform) === "win32" || n && i.TERM !== "dumb" || "CI" in i) || typeof window != "undefined" && !!window.chrome;
1184
- }
1185
- function p(n = false) {
1186
- let e = C(n), i = (r, t, c, o) => {
1187
- let l = "", s = 0;
1188
- do
1189
- l += r.substring(s, o) + c, s = o + t.length, o = r.indexOf(t, s);
1190
- while (~o);
1191
- return l + r.substring(s);
1192
- }, g = (r, t, c = r) => {
1193
- let o = (l) => {
1194
- let s = String(l), b = s.indexOf(t, r.length);
1195
- return ~b ? r + i(s, t, c, b) + t : r + s + t;
1196
- };
1197
- return o.open = r, o.close = t, o;
1198
- }, u = {
1199
- isColorSupported: e
1200
- }, d = (r) => `\x1B[${r}m`;
1201
- for (let [r, t] of h)
1202
- u[r] = e ? g(
1203
- d(t[0]),
1204
- d(t[1]),
1205
- t[2]
1206
- ) : a;
1207
- return u;
1208
- }
1209
- p();
1210
- const lineSplitRE = /\r?\n/;
1211
- function positionToOffset(source, lineNumber, columnNumber) {
1212
- const lines = source.split(lineSplitRE);
1213
- const nl = /\r\n/.test(source) ? 2 : 1;
1214
- let start = 0;
1215
- if (lineNumber > lines.length) {
1216
- return source.length;
1217
- }
1218
- for (let i = 0; i < lineNumber - 1; i++) {
1219
- start += lines[i].length + nl;
1220
- }
1221
- return start + columnNumber;
1222
- }
1223
- function offsetToLineNumber(source, offset) {
1224
- if (offset > source.length) {
1225
- throw new Error(
1226
- `offset is longer than source length! offset ${offset} > length ${source.length}`
1227
- );
1228
- }
1229
- const lines = source.split(lineSplitRE);
1230
- const nl = /\r\n/.test(source) ? 2 : 1;
1231
- let counted = 0;
1232
- let line = 0;
1233
- for (; line < lines.length; line++) {
1234
- const lineLength = lines[line].length + nl;
1235
- if (counted + lineLength >= offset) {
1236
- break;
1237
- }
1238
- counted += lineLength;
1239
- }
1240
- return line + 1;
1241
- }
1242
- async function saveInlineSnapshots(environment, snapshots) {
1243
- const MagicString = (await import("../../../../../magic-string@0.30.17/node_modules/magic-string/dist/magic-string.es.qwik.mjs")).default;
1244
- const files = new Set(snapshots.map((i) => i.file));
1245
- await Promise.all(
1246
- Array.from(files).map(async (file) => {
1247
- const snaps = snapshots.filter((i) => i.file === file);
1248
- const code = await environment.readSnapshotFile(file);
1249
- const s = new MagicString(code);
1250
- for (const snap of snaps) {
1251
- const index = positionToOffset(code, snap.line, snap.column);
1252
- replaceInlineSnap(code, s, index, snap.snapshot);
1253
- }
1254
- const transformed = s.toString();
1255
- if (transformed !== code) {
1256
- await environment.saveSnapshotFile(file, transformed);
1257
- }
1258
- })
1259
- );
1260
- }
1261
- const startObjectRegex = /(?:toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot)\s*\(\s*(?:\/\*[\s\S]*\*\/\s*|\/\/.*(?:[\n\r\u2028\u2029]\s*|[\t\v\f \xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF]))*\{/;
1262
- function replaceObjectSnap(code, s, index, newSnap) {
1263
- let _code = code.slice(index);
1264
- const startMatch = startObjectRegex.exec(_code);
1265
- if (!startMatch) {
1266
- return false;
1267
- }
1268
- _code = _code.slice(startMatch.index);
1269
- let callEnd = getCallLastIndex(_code);
1270
- if (callEnd === null) {
1271
- return false;
1272
- }
1273
- callEnd += index + startMatch.index;
1274
- const shapeStart = index + startMatch.index + startMatch[0].length;
1275
- const shapeEnd = getObjectShapeEndIndex(code, shapeStart);
1276
- const snap = `, ${prepareSnapString(newSnap, code, index)}`;
1277
- if (shapeEnd === callEnd) {
1278
- s.appendLeft(callEnd, snap);
1279
- } else {
1280
- s.overwrite(shapeEnd, callEnd, snap);
1281
- }
1282
- return true;
1283
- }
1284
- function getObjectShapeEndIndex(code, index) {
1285
- let startBraces = 1;
1286
- let endBraces = 0;
1287
- while (startBraces !== endBraces && index < code.length) {
1288
- const s = code[index++];
1289
- if (s === "{") {
1290
- startBraces++;
1291
- } else if (s === "}") {
1292
- endBraces++;
1293
- }
1294
- }
1295
- return index;
1296
- }
1297
- function prepareSnapString(snap, source, index) {
1298
- const lineNumber = offsetToLineNumber(source, index);
1299
- const line = source.split(lineSplitRE)[lineNumber - 1];
1300
- const indent = line.match(/^\s*/)[0] || "";
1301
- const indentNext = indent.includes(" ") ? `${indent} ` : `${indent} `;
1302
- const lines = snap.trim().replace(/\\/g, "\\\\").split(/\n/g);
1303
- const isOneline = lines.length <= 1;
1304
- const quote = "`";
1305
- if (isOneline) {
1306
- return `${quote}${lines.join("\n").replace(/`/g, "\\`").replace(/\$\{/g, "\\${")}${quote}`;
1307
- }
1308
- return `${quote}
1309
- ${lines.map((i) => i ? indentNext + i : "").join("\n").replace(/`/g, "\\`").replace(/\$\{/g, "\\${")}
1310
- ${indent}${quote}`;
1311
- }
1312
- const toMatchInlineName = "toMatchInlineSnapshot";
1313
- const toThrowErrorMatchingInlineName = "toThrowErrorMatchingInlineSnapshot";
1314
- function getCodeStartingAtIndex(code, index) {
1315
- const indexInline = index - toMatchInlineName.length;
1316
- if (code.slice(indexInline, index) === toMatchInlineName) {
1317
- return {
1318
- code: code.slice(indexInline),
1319
- index: indexInline
1320
- };
1321
- }
1322
- const indexThrowInline = index - toThrowErrorMatchingInlineName.length;
1323
- if (code.slice(index - indexThrowInline, index) === toThrowErrorMatchingInlineName) {
1324
- return {
1325
- code: code.slice(index - indexThrowInline),
1326
- index: index - indexThrowInline
1327
- };
1328
- }
1329
- return {
1330
- code: code.slice(index),
1331
- index
1332
- };
1333
- }
1334
- const 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$]*(['"`)])/;
1335
- function replaceInlineSnap(code, s, currentIndex, newSnap) {
1336
- const { code: codeStartingAtIndex, index } = getCodeStartingAtIndex(code, currentIndex);
1337
- const startMatch = startRegex.exec(codeStartingAtIndex);
1338
- const firstKeywordMatch = /toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot/.exec(
1339
- codeStartingAtIndex
1340
- );
1341
- if (!startMatch || startMatch.index !== (firstKeywordMatch == null ? void 0 : firstKeywordMatch.index)) {
1342
- return replaceObjectSnap(code, s, index, newSnap);
1343
- }
1344
- const quote = startMatch[1];
1345
- const startIndex = index + startMatch.index + startMatch[0].length;
1346
- const snapString = prepareSnapString(newSnap, code, index);
1347
- if (quote === ")") {
1348
- s.appendRight(startIndex - 1, snapString);
1349
- return true;
1350
- }
1351
- const quoteEndRE = new RegExp(`(?:^|[^\\\\])${quote}`);
1352
- const endMatch = quoteEndRE.exec(code.slice(startIndex));
1353
- if (!endMatch) {
1354
- return false;
1355
- }
1356
- const endIndex = startIndex + endMatch.index + endMatch[0].length;
1357
- s.overwrite(startIndex - 1, endIndex, snapString);
1358
- return true;
1359
- }
1360
- const INDENTATION_REGEX = /^([^\S\n]*)\S/m;
1361
- function stripSnapshotIndentation(inlineSnapshot) {
1362
- const match = inlineSnapshot.match(INDENTATION_REGEX);
1363
- if (!match || !match[1]) {
1364
- return inlineSnapshot;
1365
- }
1366
- const indentation = match[1];
1367
- const lines = inlineSnapshot.split(/\n/g);
1368
- if (lines.length <= 2) {
1369
- return inlineSnapshot;
1370
- }
1371
- if (lines[0].trim() !== "" || lines[lines.length - 1].trim() !== "") {
1372
- return inlineSnapshot;
1373
- }
1374
- for (let i = 1; i < lines.length - 1; i++) {
1375
- if (lines[i] !== "") {
1376
- if (lines[i].indexOf(indentation) !== 0) {
1377
- return inlineSnapshot;
1378
- }
1379
- lines[i] = lines[i].substring(indentation.length);
1380
- }
1381
- }
1382
- lines[lines.length - 1] = "";
1383
- inlineSnapshot = lines.join("\n");
1384
- return inlineSnapshot;
1385
- }
1386
- async function saveRawSnapshots(environment, snapshots) {
1387
- await Promise.all(
1388
- snapshots.map(async (snap) => {
1389
- if (!snap.readonly) {
1390
- await environment.saveSnapshotFile(snap.file, snap.snapshot);
1391
- }
1392
- })
1393
- );
1394
- }
1395
- var naturalCompare$1 = { exports: {} };
1396
- var hasRequiredNaturalCompare;
1397
- function requireNaturalCompare() {
1398
- if (hasRequiredNaturalCompare) return naturalCompare$1.exports;
1399
- hasRequiredNaturalCompare = 1;
1400
- /*
1401
- * @version 1.4.0
1402
- * @date 2015-10-26
1403
- * @stability 3 - Stable
1404
- * @author Lauri Rooden (https://github.com/litejs/natural-compare-lite)
1405
- * @license MIT License
1406
- */
1407
- var naturalCompare2 = function(a2, b) {
1408
- var i, codeA, codeB = 1, posA = 0, posB = 0, alphabet = String.alphabet;
1409
- function getCode(str, pos, code) {
1410
- if (code) {
1411
- for (i = pos; code = getCode(str, i), code < 76 && code > 65; ) ++i;
1412
- return +str.slice(pos - 1, i);
1413
- }
1414
- code = alphabet && alphabet.indexOf(str.charAt(pos));
1415
- 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;
1416
- }
1417
- if ((a2 += "") != (b += "")) for (; codeB; ) {
1418
- codeA = getCode(a2, posA++);
1419
- codeB = getCode(b, posB++);
1420
- if (codeA < 76 && codeB < 76 && codeA > 66 && codeB > 66) {
1421
- codeA = getCode(a2, posA, posA);
1422
- codeB = getCode(b, posB, posA = i);
1423
- posB = i;
1424
- }
1425
- if (codeA != codeB) return codeA < codeB ? -1 : 1;
1426
- }
1427
- return 0;
1428
- };
1429
- try {
1430
- naturalCompare$1.exports = naturalCompare2;
1431
- } catch (e) {
1432
- String.naturalCompare = naturalCompare2;
1433
- }
1434
- return naturalCompare$1.exports;
1435
- }
1436
- var naturalCompareExports = requireNaturalCompare();
1437
- var naturalCompare = /* @__PURE__ */ getDefaultExportFromCjs(naturalCompareExports);
1438
- const serialize$1 = (val, config, indentation, depth, refs, printer) => {
1439
- const name = val.getMockName();
1440
- const nameString = name === "vi.fn()" ? "" : ` ${name}`;
1441
- let callsString = "";
1442
- if (val.mock.calls.length !== 0) {
1443
- const indentationNext = indentation + config.indent;
1444
- callsString = ` {${config.spacingOuter}${indentationNext}"calls": ${printer(
1445
- val.mock.calls,
1446
- config,
1447
- indentationNext,
1448
- depth,
1449
- refs
1450
- )}${config.min ? ", " : ","}${config.spacingOuter}${indentationNext}"results": ${printer(
1451
- val.mock.results,
1452
- config,
1453
- indentationNext,
1454
- depth,
1455
- refs
1456
- )}${config.min ? "" : ","}${config.spacingOuter}${indentation}}`;
1457
- }
1458
- return `[MockFunction${nameString}]${callsString}`;
1459
- };
1460
- const test = (val) => val && !!val._isMockFunction;
1461
- const plugin = { serialize: serialize$1, test };
1462
- const {
1463
- DOMCollection,
1464
- DOMElement,
1465
- Immutable,
1466
- ReactElement,
1467
- ReactTestComponent,
1468
- AsymmetricMatcher
1469
- } = plugins;
1470
- let PLUGINS = [
1471
- ReactTestComponent,
1472
- ReactElement,
1473
- DOMElement,
1474
- DOMCollection,
1475
- Immutable,
1476
- AsymmetricMatcher,
1477
- plugin
1478
- ];
1479
- function addSerializer(plugin2) {
1480
- PLUGINS = [plugin2].concat(PLUGINS);
1481
- }
1482
- function getSerializers() {
1483
- return PLUGINS;
1484
- }
1485
- function testNameToKey(testName, count) {
1486
- return `${testName} ${count}`;
1487
- }
1488
- function keyToTestName(key) {
1489
- if (!/ \d+$/.test(key)) {
1490
- throw new Error("Snapshot keys must end with a number.");
1491
- }
1492
- return key.replace(/ \d+$/, "");
1493
- }
1494
- function getSnapshotData(content, options) {
1495
- const update = options.updateSnapshot;
1496
- const data = /* @__PURE__ */ Object.create(null);
1497
- let snapshotContents = "";
1498
- let dirty = false;
1499
- if (content != null) {
1500
- try {
1501
- snapshotContents = content;
1502
- const populate = new Function("exports", snapshotContents);
1503
- populate(data);
1504
- } catch {
1505
- }
1506
- }
1507
- const isInvalid = snapshotContents;
1508
- if ((update === "all" || update === "new") && isInvalid) {
1509
- dirty = true;
1510
- }
1511
- return { data, dirty };
1512
- }
1513
- function addExtraLineBreaks(string) {
1514
- return string.includes("\n") ? `
1515
- ${string}
1516
- ` : string;
1517
- }
1518
- function removeExtraLineBreaks(string) {
1519
- return string.length > 2 && string.startsWith("\n") && string.endsWith("\n") ? string.slice(1, -1) : string;
1520
- }
1521
- const escapeRegex = true;
1522
- const printFunctionName = false;
1523
- function serialize(val, indent = 2, formatOverrides = {}) {
1524
- return normalizeNewlines(
1525
- format(val, {
1526
- escapeRegex,
1527
- indent,
1528
- plugins: getSerializers(),
1529
- printFunctionName,
1530
- ...formatOverrides
1531
- })
1532
- );
1533
- }
1534
- function escapeBacktickString(str) {
1535
- return str.replace(/`|\\|\$\{/g, "\\$&");
1536
- }
1537
- function printBacktickString(str) {
1538
- return `\`${escapeBacktickString(str)}\``;
1539
- }
1540
- function normalizeNewlines(string) {
1541
- return string.replace(/\r\n|\r/g, "\n");
1542
- }
1543
- async function saveSnapshotFile(environment, snapshotData, snapshotPath) {
1544
- const snapshots = Object.keys(snapshotData).sort(naturalCompare).map(
1545
- (key) => `exports[${printBacktickString(key)}] = ${printBacktickString(
1546
- normalizeNewlines(snapshotData[key])
1547
- )};`
1548
- );
1549
- const content = `${environment.getHeader()}
1550
-
1551
- ${snapshots.join("\n\n")}
1552
- `;
1553
- const oldContent = await environment.readSnapshotFile(snapshotPath);
1554
- const skipWriting = oldContent != null && oldContent === content;
1555
- if (skipWriting) {
1556
- return;
1557
- }
1558
- await environment.saveSnapshotFile(snapshotPath, content);
1559
- }
1560
- function prepareExpected(expected) {
1561
- function findStartIndent() {
1562
- var _a, _b;
1563
- const matchObject = /^( +)\}\s+$/m.exec(expected || "");
1564
- const objectIndent = (_a = matchObject == null ? void 0 : matchObject[1]) == null ? void 0 : _a.length;
1565
- if (objectIndent) {
1566
- return objectIndent;
1567
- }
1568
- const matchText = /^\n( +)"/.exec(expected || "");
1569
- return ((_b = matchText == null ? void 0 : matchText[1]) == null ? void 0 : _b.length) || 0;
1570
- }
1571
- const startIndent = findStartIndent();
1572
- let expectedTrimmed = expected == null ? void 0 : expected.trim();
1573
- if (startIndent) {
1574
- expectedTrimmed = expectedTrimmed == null ? void 0 : expectedTrimmed.replace(new RegExp(`^${" ".repeat(startIndent)}`, "gm"), "").replace(/ +\}$/, "}");
1575
- }
1576
- return expectedTrimmed;
1577
- }
1578
- function deepMergeArray(target = [], source = []) {
1579
- const mergedOutput = Array.from(target);
1580
- source.forEach((sourceElement, index) => {
1581
- const targetElement = mergedOutput[index];
1582
- if (Array.isArray(target[index])) {
1583
- mergedOutput[index] = deepMergeArray(target[index], sourceElement);
1584
- } else if (isObject(targetElement)) {
1585
- mergedOutput[index] = deepMergeSnapshot(target[index], sourceElement);
1586
- } else {
1587
- mergedOutput[index] = sourceElement;
1588
- }
1589
- });
1590
- return mergedOutput;
1591
- }
1592
- function deepMergeSnapshot(target, source) {
1593
- if (isObject(target) && isObject(source)) {
1594
- const mergedOutput = { ...target };
1595
- Object.keys(source).forEach((key) => {
1596
- if (isObject(source[key]) && !source[key].$$typeof) {
1597
- if (!(key in target)) {
1598
- Object.assign(mergedOutput, { [key]: source[key] });
1599
- } else {
1600
- mergedOutput[key] = deepMergeSnapshot(target[key], source[key]);
1601
- }
1602
- } else if (Array.isArray(source[key])) {
1603
- mergedOutput[key] = deepMergeArray(target[key], source[key]);
1604
- } else {
1605
- Object.assign(mergedOutput, { [key]: source[key] });
1606
- }
1607
- });
1608
- return mergedOutput;
1609
- } else if (Array.isArray(target) && Array.isArray(source)) {
1610
- return deepMergeArray(target, source);
1611
- }
1612
- return target;
1613
- }
1614
- class DefaultMap extends Map {
1615
- constructor(defaultFn, entries) {
1616
- super(entries);
1617
- this.defaultFn = defaultFn;
1618
- }
1619
- get(key) {
1620
- if (!this.has(key)) {
1621
- this.set(key, this.defaultFn(key));
1622
- }
1623
- return super.get(key);
1624
- }
1625
- }
1626
- class CounterMap extends DefaultMap {
1627
- constructor() {
1628
- super(() => 0);
1629
- }
1630
- increment(key) {
1631
- this.set(key, this.get(key) + 1);
1632
- }
1633
- total() {
1634
- let total = 0;
1635
- for (const x of this.values()) {
1636
- total += x;
1637
- }
1638
- return total;
1639
- }
1640
- }
1641
- class SnapshotState {
1642
- constructor(testFilePath, snapshotPath, snapshotContent, options) {
1643
- __publicField(this, "_counters", new CounterMap());
1644
- __publicField(this, "_dirty");
1645
- __publicField(this, "_updateSnapshot");
1646
- __publicField(this, "_snapshotData");
1647
- __publicField(this, "_initialData");
1648
- __publicField(this, "_inlineSnapshots");
1649
- __publicField(this, "_inlineSnapshotStacks");
1650
- __publicField(this, "_testIdToKeys", new DefaultMap(() => []));
1651
- __publicField(this, "_rawSnapshots");
1652
- __publicField(this, "_uncheckedKeys");
1653
- __publicField(this, "_snapshotFormat");
1654
- __publicField(this, "_environment");
1655
- __publicField(this, "_fileExists");
1656
- __publicField(this, "added", new CounterMap());
1657
- __publicField(this, "matched", new CounterMap());
1658
- __publicField(this, "unmatched", new CounterMap());
1659
- __publicField(this, "updated", new CounterMap());
1660
- __publicField(this, "expand");
1661
- this.testFilePath = testFilePath;
1662
- this.snapshotPath = snapshotPath;
1663
- const { data, dirty } = getSnapshotData(snapshotContent, options);
1664
- this._fileExists = snapshotContent != null;
1665
- this._initialData = { ...data };
1666
- this._snapshotData = { ...data };
1667
- this._dirty = dirty;
1668
- this._inlineSnapshots = [];
1669
- this._inlineSnapshotStacks = [];
1670
- this._rawSnapshots = [];
1671
- this._uncheckedKeys = new Set(Object.keys(this._snapshotData));
1672
- this.expand = options.expand || false;
1673
- this._updateSnapshot = options.updateSnapshot;
1674
- this._snapshotFormat = {
1675
- printBasicPrototype: false,
1676
- escapeString: false,
1677
- ...options.snapshotFormat
1678
- };
1679
- this._environment = options.snapshotEnvironment;
1680
- }
1681
- static async create(testFilePath, options) {
1682
- const snapshotPath = await options.snapshotEnvironment.resolvePath(
1683
- testFilePath
1684
- );
1685
- const content = await options.snapshotEnvironment.readSnapshotFile(
1686
- snapshotPath
1687
- );
1688
- return new SnapshotState(testFilePath, snapshotPath, content, options);
1689
- }
1690
- get environment() {
1691
- return this._environment;
1692
- }
1693
- markSnapshotsAsCheckedForTest(testName) {
1694
- this._uncheckedKeys.forEach((uncheckedKey) => {
1695
- if (/ \d+$| > /.test(uncheckedKey.slice(testName.length))) {
1696
- this._uncheckedKeys.delete(uncheckedKey);
1697
- }
1698
- });
1699
- }
1700
- clearTest(testId) {
1701
- this._inlineSnapshots = this._inlineSnapshots.filter((s) => s.testId !== testId);
1702
- this._inlineSnapshotStacks = this._inlineSnapshotStacks.filter((s) => s.testId !== testId);
1703
- for (const key of this._testIdToKeys.get(testId)) {
1704
- const name = keyToTestName(key);
1705
- const count = this._counters.get(name);
1706
- if (count > 0) {
1707
- if (key in this._snapshotData || key in this._initialData) {
1708
- this._snapshotData[key] = this._initialData[key];
1709
- }
1710
- this._counters.set(name, count - 1);
1711
- }
1712
- }
1713
- this._testIdToKeys.delete(testId);
1714
- this.added.delete(testId);
1715
- this.updated.delete(testId);
1716
- this.matched.delete(testId);
1717
- this.unmatched.delete(testId);
1718
- }
1719
- _inferInlineSnapshotStack(stacks) {
1720
- const promiseIndex = stacks.findIndex(
1721
- (i) => i.method.match(/__VITEST_(RESOLVES|REJECTS)__/)
1722
- );
1723
- if (promiseIndex !== -1) {
1724
- return stacks[promiseIndex + 3];
1725
- }
1726
- const stackIndex = stacks.findIndex(
1727
- (i) => i.method.includes("__INLINE_SNAPSHOT__")
1728
- );
1729
- return stackIndex !== -1 ? stacks[stackIndex + 2] : null;
1730
- }
1731
- _addSnapshot(key, receivedSerialized, options) {
1732
- this._dirty = true;
1733
- if (options.stack) {
1734
- this._inlineSnapshots.push({
1735
- snapshot: receivedSerialized,
1736
- testId: options.testId,
1737
- ...options.stack
1738
- });
1739
- } else if (options.rawSnapshot) {
1740
- this._rawSnapshots.push({
1741
- ...options.rawSnapshot,
1742
- snapshot: receivedSerialized
1743
- });
1744
- } else {
1745
- this._snapshotData[key] = receivedSerialized;
1746
- }
1747
- }
1748
- async save() {
1749
- const hasExternalSnapshots = Object.keys(this._snapshotData).length;
1750
- const hasInlineSnapshots = this._inlineSnapshots.length;
1751
- const hasRawSnapshots = this._rawSnapshots.length;
1752
- const isEmpty = !hasExternalSnapshots && !hasInlineSnapshots && !hasRawSnapshots;
1753
- const status = {
1754
- deleted: false,
1755
- saved: false
1756
- };
1757
- if ((this._dirty || this._uncheckedKeys.size) && !isEmpty) {
1758
- if (hasExternalSnapshots) {
1759
- await saveSnapshotFile(
1760
- this._environment,
1761
- this._snapshotData,
1762
- this.snapshotPath
1763
- );
1764
- this._fileExists = true;
1765
- }
1766
- if (hasInlineSnapshots) {
1767
- await saveInlineSnapshots(this._environment, this._inlineSnapshots);
1768
- }
1769
- if (hasRawSnapshots) {
1770
- await saveRawSnapshots(this._environment, this._rawSnapshots);
1771
- }
1772
- status.saved = true;
1773
- } else if (!hasExternalSnapshots && this._fileExists) {
1774
- if (this._updateSnapshot === "all") {
1775
- await this._environment.removeSnapshotFile(this.snapshotPath);
1776
- this._fileExists = false;
1777
- }
1778
- status.deleted = true;
1779
- }
1780
- return status;
1781
- }
1782
- getUncheckedCount() {
1783
- return this._uncheckedKeys.size || 0;
1784
- }
1785
- getUncheckedKeys() {
1786
- return Array.from(this._uncheckedKeys);
1787
- }
1788
- removeUncheckedKeys() {
1789
- if (this._updateSnapshot === "all" && this._uncheckedKeys.size) {
1790
- this._dirty = true;
1791
- this._uncheckedKeys.forEach((key) => delete this._snapshotData[key]);
1792
- this._uncheckedKeys.clear();
1793
- }
1794
- }
1795
- match({
1796
- testId,
1797
- testName,
1798
- received,
1799
- key,
1800
- inlineSnapshot,
1801
- isInline,
1802
- error,
1803
- rawSnapshot
1804
- }) {
1805
- var _a, _b;
1806
- this._counters.increment(testName);
1807
- const count = this._counters.get(testName);
1808
- if (!key) {
1809
- key = testNameToKey(testName, count);
1810
- }
1811
- this._testIdToKeys.get(testId).push(key);
1812
- if (!(isInline && this._snapshotData[key] !== void 0)) {
1813
- this._uncheckedKeys.delete(key);
1814
- }
1815
- let receivedSerialized = rawSnapshot && typeof received === "string" ? received : serialize(received, void 0, this._snapshotFormat);
1816
- if (!rawSnapshot) {
1817
- receivedSerialized = addExtraLineBreaks(receivedSerialized);
1818
- }
1819
- if (rawSnapshot) {
1820
- if (rawSnapshot.content && rawSnapshot.content.match(/\r\n/) && !receivedSerialized.match(/\r\n/)) {
1821
- rawSnapshot.content = normalizeNewlines(rawSnapshot.content);
1822
- }
1823
- }
1824
- const expected = isInline ? inlineSnapshot : rawSnapshot ? rawSnapshot.content : this._snapshotData[key];
1825
- const expectedTrimmed = rawSnapshot ? expected : prepareExpected(expected);
1826
- const pass = expectedTrimmed === (rawSnapshot ? receivedSerialized : prepareExpected(receivedSerialized));
1827
- const hasSnapshot = expected !== void 0;
1828
- const snapshotIsPersisted = isInline || this._fileExists || rawSnapshot && rawSnapshot.content != null;
1829
- if (pass && !isInline && !rawSnapshot) {
1830
- this._snapshotData[key] = receivedSerialized;
1831
- }
1832
- let stack;
1833
- if (isInline) {
1834
- const stacks = parseErrorStacktrace(
1835
- error || new Error("snapshot"),
1836
- { ignoreStackEntries: [] }
1837
- );
1838
- const _stack = this._inferInlineSnapshotStack(stacks);
1839
- if (!_stack) {
1840
- throw new Error(
1841
- `@vitest/snapshot: Couldn't infer stack frame for inline snapshot.
1842
- ${JSON.stringify(
1843
- stacks
1844
- )}`
1845
- );
1846
- }
1847
- stack = ((_b = (_a = this.environment).processStackTrace) == null ? void 0 : _b.call(_a, _stack)) || _stack;
1848
- stack.column--;
1849
- if (this._inlineSnapshotStacks.some((s) => s.file === stack.file && s.line === stack.line && s.column === stack.column)) {
1850
- this._inlineSnapshots = this._inlineSnapshots.filter((s) => !(s.file === stack.file && s.line === stack.line && s.column === stack.column));
1851
- throw new Error("toMatchInlineSnapshot cannot be called multiple times at the same location.");
1852
- }
1853
- this._inlineSnapshotStacks.push({ ...stack, testId });
1854
- }
1855
- if (hasSnapshot && this._updateSnapshot === "all" || (!hasSnapshot || !snapshotIsPersisted) && (this._updateSnapshot === "new" || this._updateSnapshot === "all")) {
1856
- if (this._updateSnapshot === "all") {
1857
- if (!pass) {
1858
- if (hasSnapshot) {
1859
- this.updated.increment(testId);
1860
- } else {
1861
- this.added.increment(testId);
1862
- }
1863
- this._addSnapshot(key, receivedSerialized, {
1864
- stack,
1865
- testId,
1866
- rawSnapshot
1867
- });
1868
- } else {
1869
- this.matched.increment(testId);
1870
- }
1871
- } else {
1872
- this._addSnapshot(key, receivedSerialized, {
1873
- stack,
1874
- testId,
1875
- rawSnapshot
1876
- });
1877
- this.added.increment(testId);
1878
- }
1879
- return {
1880
- actual: "",
1881
- count,
1882
- expected: "",
1883
- key,
1884
- pass: true
1885
- };
1886
- } else {
1887
- if (!pass) {
1888
- this.unmatched.increment(testId);
1889
- return {
1890
- actual: rawSnapshot ? receivedSerialized : removeExtraLineBreaks(receivedSerialized),
1891
- count,
1892
- expected: expectedTrimmed !== void 0 ? rawSnapshot ? expectedTrimmed : removeExtraLineBreaks(expectedTrimmed) : void 0,
1893
- key,
1894
- pass: false
1895
- };
1896
- } else {
1897
- this.matched.increment(testId);
1898
- return {
1899
- actual: "",
1900
- count,
1901
- expected: "",
1902
- key,
1903
- pass: true
1904
- };
1905
- }
1906
- }
1907
- }
1908
- async pack() {
1909
- const snapshot = {
1910
- filepath: this.testFilePath,
1911
- added: 0,
1912
- fileDeleted: false,
1913
- matched: 0,
1914
- unchecked: 0,
1915
- uncheckedKeys: [],
1916
- unmatched: 0,
1917
- updated: 0
1918
- };
1919
- const uncheckedCount = this.getUncheckedCount();
1920
- const uncheckedKeys = this.getUncheckedKeys();
1921
- if (uncheckedCount) {
1922
- this.removeUncheckedKeys();
1923
- }
1924
- const status = await this.save();
1925
- snapshot.fileDeleted = status.deleted;
1926
- snapshot.added = this.added.total();
1927
- snapshot.matched = this.matched.total();
1928
- snapshot.unmatched = this.unmatched.total();
1929
- snapshot.updated = this.updated.total();
1930
- snapshot.unchecked = !status.deleted ? uncheckedCount : 0;
1931
- snapshot.uncheckedKeys = Array.from(uncheckedKeys);
1932
- return snapshot;
1933
- }
1934
- }
1935
- function createMismatchError(message, expand, actual, expected) {
1936
- const error = new Error(message);
1937
- Object.defineProperty(error, "actual", {
1938
- value: actual,
1939
- enumerable: true,
1940
- configurable: true,
1941
- writable: true
1942
- });
1943
- Object.defineProperty(error, "expected", {
1944
- value: expected,
1945
- enumerable: true,
1946
- configurable: true,
1947
- writable: true
1948
- });
1949
- Object.defineProperty(error, "diffOptions", { value: { expand } });
1950
- return error;
1951
- }
1952
- class SnapshotClient {
1953
- constructor(options = {}) {
1954
- __publicField(this, "snapshotStateMap", /* @__PURE__ */ new Map());
1955
- this.options = options;
1956
- }
1957
- async setup(filepath, options) {
1958
- if (this.snapshotStateMap.has(filepath)) {
1959
- return;
1960
- }
1961
- this.snapshotStateMap.set(
1962
- filepath,
1963
- await SnapshotState.create(filepath, options)
1964
- );
1965
- }
1966
- async finish(filepath) {
1967
- const state = this.getSnapshotState(filepath);
1968
- const result = await state.pack();
1969
- this.snapshotStateMap.delete(filepath);
1970
- return result;
1971
- }
1972
- skipTest(filepath, testName) {
1973
- const state = this.getSnapshotState(filepath);
1974
- state.markSnapshotsAsCheckedForTest(testName);
1975
- }
1976
- clearTest(filepath, testId) {
1977
- const state = this.getSnapshotState(filepath);
1978
- state.clearTest(testId);
1979
- }
1980
- getSnapshotState(filepath) {
1981
- const state = this.snapshotStateMap.get(filepath);
1982
- if (!state) {
1983
- throw new Error(
1984
- `The snapshot state for '${filepath}' is not found. Did you call 'SnapshotClient.setup()'?`
1985
- );
1986
- }
1987
- return state;
1988
- }
1989
- assert(options) {
1990
- var _a, _b;
1991
- const {
1992
- filepath,
1993
- name,
1994
- testId = name,
1995
- message,
1996
- isInline = false,
1997
- properties,
1998
- inlineSnapshot,
1999
- error,
2000
- errorMessage,
2001
- rawSnapshot
2002
- } = options;
2003
- let { received } = options;
2004
- if (!filepath) {
2005
- throw new Error("Snapshot cannot be used outside of test");
2006
- }
2007
- const snapshotState = this.getSnapshotState(filepath);
2008
- if (typeof properties === "object") {
2009
- if (typeof received !== "object" || !received) {
2010
- throw new Error(
2011
- "Received value must be an object when the matcher has properties"
2012
- );
2013
- }
2014
- try {
2015
- const pass2 = ((_b = (_a = this.options).isEqual) == null ? void 0 : _b.call(_a, received, properties)) ?? false;
2016
- if (!pass2) {
2017
- throw createMismatchError(
2018
- "Snapshot properties mismatched",
2019
- snapshotState.expand,
2020
- received,
2021
- properties
2022
- );
2023
- } else {
2024
- received = deepMergeSnapshot(received, properties);
2025
- }
2026
- } catch (err) {
2027
- err.message = errorMessage || "Snapshot mismatched";
2028
- throw err;
2029
- }
2030
- }
2031
- const testName = [name, ...message ? [message] : []].join(" > ");
2032
- const { actual, expected, key, pass } = snapshotState.match({
2033
- testId,
2034
- testName,
2035
- received,
2036
- isInline,
2037
- error,
2038
- inlineSnapshot,
2039
- rawSnapshot
2040
- });
2041
- if (!pass) {
2042
- throw createMismatchError(
2043
- `Snapshot \`${key || "unknown"}\` mismatched`,
2044
- snapshotState.expand,
2045
- rawSnapshot ? actual : actual == null ? void 0 : actual.trim(),
2046
- rawSnapshot ? expected : expected == null ? void 0 : expected.trim()
2047
- );
2048
- }
2049
- }
2050
- async assertRaw(options) {
2051
- if (!options.rawSnapshot) {
2052
- throw new Error("Raw snapshot is required");
2053
- }
2054
- const { filepath, rawSnapshot } = options;
2055
- if (rawSnapshot.content == null) {
2056
- if (!filepath) {
2057
- throw new Error("Snapshot cannot be used outside of test");
2058
- }
2059
- const snapshotState = this.getSnapshotState(filepath);
2060
- options.filepath || (options.filepath = filepath);
2061
- rawSnapshot.file = await snapshotState.environment.resolveRawPath(
2062
- filepath,
2063
- rawSnapshot.file
2064
- );
2065
- rawSnapshot.content = await snapshotState.environment.readSnapshotFile(rawSnapshot.file) ?? void 0;
2066
- }
2067
- return this.assert(options);
2068
- }
2069
- clear() {
2070
- this.snapshotStateMap.clear();
2071
- }
2072
- }
2073
- export {
2074
- SnapshotClient,
2075
- SnapshotState,
2076
- addSerializer,
2077
- getSerializers,
2078
- stripSnapshotIndentation
2079
- };