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