elit 3.3.3 → 3.3.4

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 (143) hide show
  1. package/dist/build.d.mts +1 -1
  2. package/dist/build.js +1 -0
  3. package/dist/build.js.map +1 -0
  4. package/dist/build.mjs +1 -0
  5. package/dist/build.mjs.map +1 -0
  6. package/dist/chokidar.js +1 -0
  7. package/dist/chokidar.js.map +1 -0
  8. package/dist/chokidar.mjs +1 -0
  9. package/dist/chokidar.mjs.map +1 -0
  10. package/dist/cli.js +4687 -34
  11. package/dist/config.d.mts +3 -1
  12. package/dist/config.d.ts +3 -1
  13. package/dist/config.d.ts.map +1 -1
  14. package/dist/config.js +1 -0
  15. package/dist/config.js.map +1 -0
  16. package/dist/config.mjs +1 -0
  17. package/dist/config.mjs.map +1 -0
  18. package/dist/coverage.d.mts +85 -0
  19. package/dist/coverage.d.ts +76 -0
  20. package/dist/coverage.d.ts.map +1 -0
  21. package/dist/coverage.js +1549 -0
  22. package/dist/coverage.js.map +1 -0
  23. package/dist/coverage.mjs +1520 -0
  24. package/dist/coverage.mjs.map +1 -0
  25. package/dist/database.d.mts +31 -6
  26. package/dist/database.d.ts +31 -6
  27. package/dist/database.d.ts.map +1 -1
  28. package/dist/database.js +60 -33
  29. package/dist/database.js.map +1 -0
  30. package/dist/database.mjs +60 -33
  31. package/dist/database.mjs.map +1 -0
  32. package/dist/dom.js +1 -0
  33. package/dist/dom.js.map +1 -0
  34. package/dist/dom.mjs +1 -0
  35. package/dist/dom.mjs.map +1 -0
  36. package/dist/el.js +1 -0
  37. package/dist/el.js.map +1 -0
  38. package/dist/el.mjs +1 -0
  39. package/dist/el.mjs.map +1 -0
  40. package/dist/fs.js +1 -0
  41. package/dist/fs.js.map +1 -0
  42. package/dist/fs.mjs +1 -0
  43. package/dist/fs.mjs.map +1 -0
  44. package/dist/hmr.js +1 -0
  45. package/dist/hmr.js.map +1 -0
  46. package/dist/hmr.mjs +1 -0
  47. package/dist/hmr.mjs.map +1 -0
  48. package/dist/http.js +1 -0
  49. package/dist/http.js.map +1 -0
  50. package/dist/http.mjs +1 -0
  51. package/dist/http.mjs.map +1 -0
  52. package/dist/https.d.mts +1 -1
  53. package/dist/https.js +1 -0
  54. package/dist/https.js.map +1 -0
  55. package/dist/https.mjs +1 -0
  56. package/dist/https.mjs.map +1 -0
  57. package/dist/index.d.mts +1 -1
  58. package/dist/index.js +1 -0
  59. package/dist/index.js.map +1 -0
  60. package/dist/index.mjs +1 -0
  61. package/dist/index.mjs.map +1 -0
  62. package/dist/mime-types.js +1 -0
  63. package/dist/mime-types.js.map +1 -0
  64. package/dist/mime-types.mjs +1 -0
  65. package/dist/mime-types.mjs.map +1 -0
  66. package/dist/path.js +1 -0
  67. package/dist/path.js.map +1 -0
  68. package/dist/path.mjs +1 -0
  69. package/dist/path.mjs.map +1 -0
  70. package/dist/router.js +1 -0
  71. package/dist/router.js.map +1 -0
  72. package/dist/router.mjs +1 -0
  73. package/dist/router.mjs.map +1 -0
  74. package/dist/runtime.js +1 -0
  75. package/dist/runtime.js.map +1 -0
  76. package/dist/runtime.mjs +1 -0
  77. package/dist/runtime.mjs.map +1 -0
  78. package/dist/{server-Cz3z-5ls.d.mts → server-BFTzgJpO.d.mts} +62 -1
  79. package/dist/{server-BG2CaVMh.d.ts → server-CIXtexNS.d.ts} +62 -1
  80. package/dist/server.d.mts +1 -1
  81. package/dist/server.d.ts +9 -0
  82. package/dist/server.d.ts.map +1 -1
  83. package/dist/server.js +12 -0
  84. package/dist/server.js.map +1 -0
  85. package/dist/server.mjs +12 -0
  86. package/dist/server.mjs.map +1 -0
  87. package/dist/state.d.mts +1 -1
  88. package/dist/state.js +1 -0
  89. package/dist/state.js.map +1 -0
  90. package/dist/state.mjs +1 -0
  91. package/dist/state.mjs.map +1 -0
  92. package/dist/style.js +1 -0
  93. package/dist/style.js.map +1 -0
  94. package/dist/style.mjs +1 -0
  95. package/dist/style.mjs.map +1 -0
  96. package/dist/test-globals.d.ts +184 -0
  97. package/dist/test-reporter.d.mts +77 -0
  98. package/dist/test-reporter.d.ts +73 -0
  99. package/dist/test-reporter.d.ts.map +1 -0
  100. package/dist/test-reporter.js +726 -0
  101. package/dist/test-reporter.js.map +1 -0
  102. package/dist/test-reporter.mjs +696 -0
  103. package/dist/test-reporter.mjs.map +1 -0
  104. package/dist/test-runtime.d.mts +122 -0
  105. package/dist/test-runtime.d.ts +120 -0
  106. package/dist/test-runtime.d.ts.map +1 -0
  107. package/dist/test-runtime.js +1292 -0
  108. package/dist/test-runtime.js.map +1 -0
  109. package/dist/test-runtime.mjs +1269 -0
  110. package/dist/test-runtime.mjs.map +1 -0
  111. package/dist/test.d.mts +39 -0
  112. package/dist/test.d.ts +38 -0
  113. package/dist/test.d.ts.map +1 -0
  114. package/dist/test.js +4966 -0
  115. package/dist/test.js.map +1 -0
  116. package/dist/test.mjs +4944 -0
  117. package/dist/test.mjs.map +1 -0
  118. package/dist/types.d.mts +62 -1
  119. package/dist/types.d.ts +52 -0
  120. package/dist/types.d.ts.map +1 -1
  121. package/dist/types.js +1 -0
  122. package/dist/types.js.map +1 -0
  123. package/dist/types.mjs +1 -0
  124. package/dist/types.mjs.map +1 -0
  125. package/dist/ws.js +1 -0
  126. package/dist/ws.js.map +1 -0
  127. package/dist/ws.mjs +1 -0
  128. package/dist/ws.mjs.map +1 -0
  129. package/dist/wss.js +1 -0
  130. package/dist/wss.js.map +1 -0
  131. package/dist/wss.mjs +1 -0
  132. package/dist/wss.mjs.map +1 -0
  133. package/package.json +37 -5
  134. package/src/cli.ts +165 -1
  135. package/src/config.ts +3 -1
  136. package/src/coverage.ts +1479 -0
  137. package/src/database.ts +71 -35
  138. package/src/server.ts +12 -0
  139. package/src/test-globals.d.ts +184 -0
  140. package/src/test-reporter.ts +609 -0
  141. package/src/test-runtime.ts +1359 -0
  142. package/src/test.ts +368 -0
  143. package/src/types.ts +59 -0
@@ -0,0 +1,1269 @@
1
+ import {createRequire as __createRequire} from 'module';const require = __createRequire(import.meta.url);
2
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
+ }) : x)(function(x) {
5
+ if (typeof require !== "undefined") return require.apply(this, arguments);
6
+ throw Error('Dynamic require of "' + x + '" is not supported');
7
+ });
8
+
9
+ // src/test-runtime.ts
10
+ import { transformSync } from "esbuild";
11
+
12
+ // src/runtime.ts
13
+ var runtime = (() => {
14
+ if (typeof Deno !== "undefined") return "deno";
15
+ if (typeof Bun !== "undefined") return "bun";
16
+ return "node";
17
+ })();
18
+ var isNode = runtime === "node";
19
+ var isBun = runtime === "bun";
20
+ var isDeno = runtime === "deno";
21
+
22
+ // src/fs.ts
23
+ function parseOptions(options, defaultValue) {
24
+ return typeof options === "string" ? { encoding: options } : options || defaultValue;
25
+ }
26
+ function decodeContent(content, encoding) {
27
+ if (encoding) {
28
+ return new TextDecoder(encoding).decode(content);
29
+ }
30
+ return Buffer.from(content instanceof ArrayBuffer ? new Uint8Array(content) : content);
31
+ }
32
+ var fs;
33
+ var fsPromises;
34
+ if (isNode) {
35
+ fs = __require("fs");
36
+ fsPromises = __require("fs/promises");
37
+ }
38
+ async function readFile(path, options) {
39
+ const opts = parseOptions(options, {});
40
+ if (isNode) {
41
+ return fsPromises.readFile(path, opts);
42
+ } else if (isBun) {
43
+ const file = Bun.file(path);
44
+ const content = await file.arrayBuffer();
45
+ return decodeContent(content, opts.encoding);
46
+ } else if (isDeno) {
47
+ const content = await Deno.readFile(path);
48
+ return decodeContent(content, opts.encoding);
49
+ }
50
+ throw new Error("Unsupported runtime");
51
+ }
52
+ function readFileSync(path, options) {
53
+ const opts = parseOptions(options, {});
54
+ if (isNode) {
55
+ return fs.readFileSync(path, opts);
56
+ } else if (isBun) {
57
+ const file = Bun.file(path);
58
+ const content = file.arrayBuffer();
59
+ return decodeContent(content, opts.encoding);
60
+ } else if (isDeno) {
61
+ const content = Deno.readFileSync(path);
62
+ return decodeContent(content, opts.encoding);
63
+ }
64
+ throw new Error("Unsupported runtime");
65
+ }
66
+
67
+ // src/path.ts
68
+ function getSeparator(isWin) {
69
+ return isWin ? "\\" : "/";
70
+ }
71
+ function getCwd() {
72
+ if (isNode || isBun) {
73
+ return process.cwd();
74
+ } else if (isDeno) {
75
+ return Deno.cwd();
76
+ }
77
+ return "/";
78
+ }
79
+ function findLastSeparator(path) {
80
+ return Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
81
+ }
82
+ function createPathOps(isWin) {
83
+ return {
84
+ sep: getSeparator(isWin),
85
+ delimiter: isWin ? ";" : ":",
86
+ normalize: (path) => normalizePath(path, isWin),
87
+ join: (...paths) => joinPaths(paths, isWin),
88
+ resolve: (...paths) => resolvePaths(paths, isWin),
89
+ isAbsolute: (path) => isWin ? isAbsoluteWin(path) : isAbsolutePosix(path),
90
+ relative: (from, to) => relativePath(from, to, isWin),
91
+ dirname: (path) => getDirname(path, isWin),
92
+ basename: (path, ext) => getBasename(path, ext, isWin),
93
+ extname: (path) => getExtname(path),
94
+ parse: (path) => parsePath(path, isWin),
95
+ format: (pathObject) => formatPath(pathObject, isWin)
96
+ };
97
+ }
98
+ function isAbsolutePosix(path) {
99
+ return path.length > 0 && path[0] === "/";
100
+ }
101
+ function isAbsoluteWin(path) {
102
+ const len = path.length;
103
+ if (len === 0) return false;
104
+ const code = path.charCodeAt(0);
105
+ if (code === 47 || code === 92) {
106
+ return true;
107
+ }
108
+ if (code >= 65 && code <= 90 || code >= 97 && code <= 122) {
109
+ if (len > 2 && path.charCodeAt(1) === 58) {
110
+ const code2 = path.charCodeAt(2);
111
+ if (code2 === 47 || code2 === 92) {
112
+ return true;
113
+ }
114
+ }
115
+ }
116
+ return false;
117
+ }
118
+ var isWindows = (() => {
119
+ if (isNode) {
120
+ return process.platform === "win32";
121
+ } else if (isDeno) {
122
+ return Deno.build.os === "windows";
123
+ }
124
+ return typeof process !== "undefined" && process.platform === "win32";
125
+ })();
126
+ var posix = createPathOps(false);
127
+ var win32 = createPathOps(true);
128
+ function normalizePath(path, isWin) {
129
+ if (path.length === 0) return ".";
130
+ const separator = getSeparator(isWin);
131
+ const isAbsolute = isWin ? isAbsoluteWin(path) : isAbsolutePosix(path);
132
+ const trailingSeparator = path[path.length - 1] === separator || isWin && path[path.length - 1] === "/";
133
+ let normalized = path.replace(isWin ? /[\/\\]+/g : /\/+/g, separator);
134
+ const parts = normalized.split(separator);
135
+ const result = [];
136
+ for (let i = 0; i < parts.length; i++) {
137
+ const part = parts[i];
138
+ if (part === "" || part === ".") {
139
+ if (i === 0 && isAbsolute) result.push("");
140
+ continue;
141
+ }
142
+ if (part === "..") {
143
+ if (result.length > 0 && result[result.length - 1] !== "..") {
144
+ if (!(result.length === 1 && result[0] === "")) {
145
+ result.pop();
146
+ }
147
+ } else if (!isAbsolute) {
148
+ result.push("..");
149
+ }
150
+ } else {
151
+ result.push(part);
152
+ }
153
+ }
154
+ let final = result.join(separator);
155
+ if (final.length === 0) {
156
+ return isAbsolute ? separator : ".";
157
+ }
158
+ if (trailingSeparator && final[final.length - 1] !== separator) {
159
+ final += separator;
160
+ }
161
+ return final;
162
+ }
163
+ function joinPaths(paths, isWin) {
164
+ if (paths.length === 0) return ".";
165
+ const separator = getSeparator(isWin);
166
+ let joined = "";
167
+ for (let i = 0; i < paths.length; i++) {
168
+ const path = paths[i];
169
+ if (path && path.length > 0) {
170
+ if (joined.length === 0) {
171
+ joined = path;
172
+ } else {
173
+ joined += separator + path;
174
+ }
175
+ }
176
+ }
177
+ if (joined.length === 0) return ".";
178
+ return normalizePath(joined, isWin);
179
+ }
180
+ function resolvePaths(paths, isWin) {
181
+ const separator = getSeparator(isWin);
182
+ let resolved = "";
183
+ let isAbsolute = false;
184
+ for (let i = paths.length - 1; i >= 0 && !isAbsolute; i--) {
185
+ const path = paths[i];
186
+ if (path && path.length > 0) {
187
+ resolved = path + (resolved.length > 0 ? separator + resolved : "");
188
+ isAbsolute = isWin ? isAbsoluteWin(resolved) : isAbsolutePosix(resolved);
189
+ }
190
+ }
191
+ if (!isAbsolute) {
192
+ const cwd = getCwd();
193
+ resolved = cwd + (resolved.length > 0 ? separator + resolved : "");
194
+ }
195
+ return normalizePath(resolved, isWin);
196
+ }
197
+ function relativePath(from, to, isWin) {
198
+ from = resolvePaths([from], isWin);
199
+ to = resolvePaths([to], isWin);
200
+ if (from === to) return "";
201
+ const separator = getSeparator(isWin);
202
+ const fromParts = from.split(separator).filter((p) => p.length > 0);
203
+ const toParts = to.split(separator).filter((p) => p.length > 0);
204
+ let commonLength = 0;
205
+ const minLength = Math.min(fromParts.length, toParts.length);
206
+ for (let i = 0; i < minLength; i++) {
207
+ if (fromParts[i] === toParts[i]) {
208
+ commonLength++;
209
+ } else {
210
+ break;
211
+ }
212
+ }
213
+ const upCount = fromParts.length - commonLength;
214
+ const result = [];
215
+ for (let i = 0; i < upCount; i++) {
216
+ result.push("..");
217
+ }
218
+ for (let i = commonLength; i < toParts.length; i++) {
219
+ result.push(toParts[i]);
220
+ }
221
+ return result.join(separator) || ".";
222
+ }
223
+ function getDirname(path, isWin) {
224
+ if (path.length === 0) return ".";
225
+ const separator = getSeparator(isWin);
226
+ const normalized = normalizePath(path, isWin);
227
+ const lastSepIndex = normalized.lastIndexOf(separator);
228
+ if (lastSepIndex === -1) return ".";
229
+ if (lastSepIndex === 0) return separator;
230
+ return normalized.slice(0, lastSepIndex);
231
+ }
232
+ function getBasename(path, ext, isWin) {
233
+ if (path.length === 0) return "";
234
+ const lastSepIndex = isWin ? findLastSeparator(path) : path.lastIndexOf("/");
235
+ let base = lastSepIndex === -1 ? path : path.slice(lastSepIndex + 1);
236
+ if (ext && base.endsWith(ext)) {
237
+ base = base.slice(0, base.length - ext.length);
238
+ }
239
+ return base;
240
+ }
241
+ function getExtname(path) {
242
+ const lastDotIndex = path.lastIndexOf(".");
243
+ const lastSepIndex = findLastSeparator(path);
244
+ if (lastDotIndex === -1 || lastDotIndex < lastSepIndex || lastDotIndex === path.length - 1) {
245
+ return "";
246
+ }
247
+ return path.slice(lastDotIndex);
248
+ }
249
+ function parsePath(path, isWin) {
250
+ let root = "";
251
+ if (isWin) {
252
+ if (path.length >= 2 && path[1] === ":") {
253
+ root = path.slice(0, 2);
254
+ if (path.length > 2 && (path[2] === "\\" || path[2] === "/")) {
255
+ root += "\\";
256
+ }
257
+ } else if (path[0] === "\\" || path[0] === "/") {
258
+ root = "\\";
259
+ }
260
+ } else {
261
+ if (path[0] === "/") {
262
+ root = "/";
263
+ }
264
+ }
265
+ const dir = getDirname(path, isWin);
266
+ const base = getBasename(path, void 0, isWin);
267
+ const ext = getExtname(path);
268
+ const name = ext ? base.slice(0, base.length - ext.length) : base;
269
+ return { root, dir, base, ext, name };
270
+ }
271
+ function formatPath(pathObject, isWin) {
272
+ const separator = getSeparator(isWin);
273
+ const dir = pathObject.dir || pathObject.root || "";
274
+ const base = pathObject.base || (pathObject.name || "") + (pathObject.ext || "");
275
+ if (!dir) return base;
276
+ if (dir === pathObject.root) return dir + base;
277
+ return dir + separator + base;
278
+ }
279
+ function dirname(path) {
280
+ return getDirname(path, isWindows);
281
+ }
282
+
283
+ // src/test-runtime.ts
284
+ import { SourceMapConsumer } from "source-map";
285
+ function escapeRegex(str) {
286
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
287
+ }
288
+ var AssertionError = class extends Error {
289
+ constructor(message, filePath, lineNumber, columnNumber, codeSnippet) {
290
+ super(message);
291
+ this.filePath = filePath;
292
+ this.lineNumber = lineNumber;
293
+ this.columnNumber = columnNumber;
294
+ this.codeSnippet = codeSnippet;
295
+ this.name = "AssertionError";
296
+ }
297
+ };
298
+ var currentSuite = {
299
+ name: "root",
300
+ tests: [],
301
+ suites: [],
302
+ skip: false,
303
+ only: false
304
+ };
305
+ var testResults = [];
306
+ var hasOnly = false;
307
+ var coveredFiles = /* @__PURE__ */ new Set();
308
+ var describePattern = void 0;
309
+ var testPattern = void 0;
310
+ var currentTestFile = void 0;
311
+ var currentSourceMapConsumer = void 0;
312
+ var wrapperLineOffset = 0;
313
+ async function transpileFile(filePath) {
314
+ const source = await readFile(filePath, "utf-8");
315
+ const result = transformSync(source, {
316
+ loader: filePath.endsWith(".ts") || filePath.endsWith(".tsx") ? "ts" : "js",
317
+ format: "esm",
318
+ sourcemap: "inline",
319
+ target: "es2020",
320
+ tsconfigRaw: {
321
+ compilerOptions: {
322
+ jsx: "react",
323
+ jsxFactory: "h",
324
+ jsxFragmentFactory: "Fragment"
325
+ }
326
+ }
327
+ });
328
+ let sourceMap;
329
+ const sourceMapMatch = result.code.match(/\/\/# sourceMappingURL=data:application\/json;base64,(.+)/);
330
+ if (sourceMapMatch) {
331
+ const base64 = sourceMapMatch[1];
332
+ const json = Buffer.from(base64, "base64").toString("utf-8");
333
+ sourceMap = JSON.parse(json);
334
+ }
335
+ return { code: result.code, sourceMap };
336
+ }
337
+ function createTestFunction(defaultTimeout = 5e3) {
338
+ const testFn = function(name, fn, timeout) {
339
+ const test2 = {
340
+ name,
341
+ fn,
342
+ skip: currentSuite.skip,
343
+ only: false,
344
+ todo: false,
345
+ timeout: timeout ?? defaultTimeout,
346
+ suite: currentSuite
347
+ };
348
+ currentSuite.tests.push(test2);
349
+ };
350
+ testFn.skip = (name, fn, timeout) => {
351
+ const test2 = {
352
+ name,
353
+ fn,
354
+ skip: true,
355
+ only: false,
356
+ todo: false,
357
+ timeout: timeout ?? defaultTimeout,
358
+ suite: currentSuite
359
+ };
360
+ currentSuite.tests.push(test2);
361
+ };
362
+ testFn.only = (name, fn, timeout) => {
363
+ hasOnly = true;
364
+ const test2 = {
365
+ name,
366
+ fn,
367
+ skip: false,
368
+ only: true,
369
+ todo: false,
370
+ timeout: timeout ?? defaultTimeout,
371
+ suite: currentSuite
372
+ };
373
+ currentSuite.tests.push(test2);
374
+ };
375
+ testFn.todo = (name, fn, timeout) => {
376
+ const test2 = {
377
+ name,
378
+ fn,
379
+ skip: false,
380
+ only: false,
381
+ todo: true,
382
+ timeout: timeout ?? defaultTimeout,
383
+ suite: currentSuite
384
+ };
385
+ currentSuite.tests.push(test2);
386
+ };
387
+ return testFn;
388
+ }
389
+ function createDescribeFunction() {
390
+ const describeFn = function(name, fn) {
391
+ const parent = currentSuite;
392
+ const suite = {
393
+ name,
394
+ tests: [],
395
+ suites: [],
396
+ parent,
397
+ skip: parent.skip,
398
+ only: parent.only
399
+ };
400
+ parent.suites.push(suite);
401
+ currentSuite = suite;
402
+ fn();
403
+ currentSuite = parent;
404
+ };
405
+ describeFn.skip = (name, fn) => {
406
+ const parent = currentSuite;
407
+ const suite = {
408
+ name,
409
+ tests: [],
410
+ suites: [],
411
+ parent,
412
+ skip: true,
413
+ only: false
414
+ };
415
+ parent.suites.push(suite);
416
+ currentSuite = suite;
417
+ fn();
418
+ currentSuite = parent;
419
+ };
420
+ describeFn.only = (name, fn) => {
421
+ hasOnly = true;
422
+ const parent = currentSuite;
423
+ const suite = {
424
+ name,
425
+ tests: [],
426
+ suites: [],
427
+ parent,
428
+ skip: false,
429
+ only: true
430
+ };
431
+ parent.suites.push(suite);
432
+ currentSuite = suite;
433
+ fn();
434
+ currentSuite = parent;
435
+ };
436
+ return describeFn;
437
+ }
438
+ var Expect = class _Expect {
439
+ constructor(actual, isNot = false, isAsync = false) {
440
+ this.actual = actual;
441
+ this.isNot = isNot;
442
+ this.isAsync = isAsync;
443
+ this._not = null;
444
+ this._resolves = null;
445
+ this._rejects = null;
446
+ }
447
+ get not() {
448
+ if (!this._not) {
449
+ this._not = new _Expect(this.actual, !this.isNot, false);
450
+ }
451
+ return this._not;
452
+ }
453
+ get resolves() {
454
+ if (!this._resolves) {
455
+ this._resolves = new _Expect(this.actual, this.isNot, true);
456
+ }
457
+ return this._resolves;
458
+ }
459
+ get rejects() {
460
+ if (!this._rejects) {
461
+ this._rejects = new _Expect(this.actual, this.isNot, true);
462
+ }
463
+ return this._rejects;
464
+ }
465
+ assertCondition(condition, message, showExpectedReceived = true, expectedDisplay, callerStack) {
466
+ if (this.isNot) {
467
+ condition = !condition;
468
+ }
469
+ if (!condition) {
470
+ let errorMsg = message;
471
+ if (showExpectedReceived) {
472
+ const expectedValue = expectedDisplay ?? this.stringify(this.expected ?? "truthy");
473
+ errorMsg += `
474
+ Expected: ${expectedValue}
475
+ Received: ${this.stringify(this.actual)}`;
476
+ }
477
+ const stack = callerStack || new Error().stack;
478
+ let lineNumber = void 0;
479
+ let codeSnippet = void 0;
480
+ let assertionMethod = void 0;
481
+ if (stack) {
482
+ const assertionMatch = stack.match(/at _Expect\.(\w+)/);
483
+ if (assertionMatch) {
484
+ assertionMethod = assertionMatch[1];
485
+ }
486
+ }
487
+ if (stack) {
488
+ const lines = stack.split("\n");
489
+ const stackFrames = [];
490
+ for (const line of lines) {
491
+ const match = line.match(/<anonymous>:([0-9]+):([0-9]+)/);
492
+ if (match) {
493
+ stackFrames.push({
494
+ line: parseInt(match[1], 10),
495
+ column: parseInt(match[2], 10)
496
+ });
497
+ }
498
+ }
499
+ const targetFrame = stackFrames.length > 1 ? stackFrames[1] : stackFrames[0];
500
+ if (targetFrame && currentSourceMapConsumer) {
501
+ try {
502
+ const transpiledLine = targetFrame.line - wrapperLineOffset;
503
+ const originalPosition = currentSourceMapConsumer.originalPositionFor({
504
+ line: transpiledLine,
505
+ column: targetFrame.column
506
+ });
507
+ if (originalPosition.line !== null) {
508
+ lineNumber = originalPosition.line;
509
+ if (currentTestFile) {
510
+ try {
511
+ let sourceCode = readFileSync(currentTestFile, "utf-8");
512
+ if (Buffer.isBuffer(sourceCode)) {
513
+ sourceCode = sourceCode.toString("utf-8");
514
+ }
515
+ const sourceLines = sourceCode.split("\n");
516
+ let targetPattern = ".toBe(";
517
+ if (assertionMethod === "toEqual") targetPattern = ".toEqual(";
518
+ else if (assertionMethod === "toStrictEqual") targetPattern = ".toStrictEqual(";
519
+ else if (assertionMethod === "toMatch") targetPattern = ".toMatch(";
520
+ else if (assertionMethod === "toContain") targetPattern = ".toContain(";
521
+ else if (assertionMethod === "toHaveLength") targetPattern = ".toHaveLength(";
522
+ else if (assertionMethod === "toBeDefined") targetPattern = ".toBeDefined(";
523
+ else if (assertionMethod === "toBeNull") targetPattern = ".toBeNull(";
524
+ else if (assertionMethod === "toBeUndefined") targetPattern = ".toBeUndefined(";
525
+ else if (assertionMethod === "toBeTruthy") targetPattern = ".toBeTruthy(";
526
+ else if (assertionMethod === "toBeFalsy") targetPattern = ".toBeFalsy(";
527
+ else if (assertionMethod === "toThrow") targetPattern = ".toThrow(";
528
+ else if (assertionMethod === "toBeGreaterThan") targetPattern = ".toBeGreaterThan(";
529
+ else if (assertionMethod === "toBeGreaterThanOrEqual") targetPattern = ".toBeGreaterThanOrEqual(";
530
+ else if (assertionMethod === "toBeLessThan") targetPattern = ".toBeLessThan(";
531
+ else if (assertionMethod === "toBeLessThanOrEqual") targetPattern = ".toBeLessThanOrEqual(";
532
+ if (lineNumber > 0 && lineNumber <= sourceLines.length) {
533
+ const mappedLine = sourceLines[lineNumber - 1];
534
+ const hasMatchingAssertion = mappedLine.includes(targetPattern);
535
+ if (!hasMatchingAssertion) {
536
+ for (let i = 1; i <= 3; i++) {
537
+ const searchLine = lineNumber - i;
538
+ if (searchLine > 0 && searchLine <= sourceLines.length) {
539
+ const testLine = sourceLines[searchLine - 1];
540
+ if (testLine.includes(targetPattern)) {
541
+ lineNumber = searchLine;
542
+ break;
543
+ }
544
+ }
545
+ }
546
+ }
547
+ }
548
+ } catch (e) {
549
+ }
550
+ }
551
+ } else {
552
+ const posWithoutColumn = currentSourceMapConsumer.originalPositionFor({
553
+ line: transpiledLine,
554
+ column: 0
555
+ });
556
+ if (posWithoutColumn.line !== null) {
557
+ lineNumber = posWithoutColumn.line;
558
+ } else {
559
+ const lineMappings = [];
560
+ currentSourceMapConsumer.eachMapping((mapping) => {
561
+ if (mapping.originalLine !== null) {
562
+ const distance = Math.abs(mapping.generatedLine - transpiledLine);
563
+ lineMappings.push({
564
+ line: mapping.originalLine,
565
+ distance
566
+ });
567
+ }
568
+ });
569
+ if (lineMappings.length > 0) {
570
+ lineMappings.sort((a, b) => a.distance - b.distance);
571
+ lineNumber = lineMappings[0].line;
572
+ }
573
+ }
574
+ }
575
+ } catch (e) {
576
+ }
577
+ }
578
+ if (currentTestFile && lineNumber) {
579
+ try {
580
+ let sourceCode = readFileSync(currentTestFile, "utf-8");
581
+ if (Buffer.isBuffer(sourceCode)) {
582
+ sourceCode = sourceCode.toString("utf-8");
583
+ }
584
+ const sourceLines = sourceCode.split("\n");
585
+ if (lineNumber > 0 && lineNumber <= sourceLines.length) {
586
+ const codeLine = sourceLines[lineNumber - 1];
587
+ if (codeLine) {
588
+ codeSnippet = codeLine.trim();
589
+ }
590
+ }
591
+ } catch (e) {
592
+ }
593
+ }
594
+ }
595
+ throw new AssertionError(errorMsg, currentTestFile, lineNumber, void 0, codeSnippet);
596
+ }
597
+ }
598
+ stringify(value) {
599
+ if (value === void 0) return "undefined";
600
+ if (value === null) return "null";
601
+ if (typeof value === "string") return `"${value}"`;
602
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
603
+ if (typeof value === "function") return "Function";
604
+ if (Array.isArray(value)) return `[${value.map((v) => this.stringify(v)).join(", ")}]`;
605
+ if (typeof value === "object") {
606
+ const keys = Object.keys(value);
607
+ if (keys.length === 0) return "{}";
608
+ return `{ ${keys.slice(0, 3).map((k) => `${k}: ${this.stringify(value[k])}`).join(", ")}${keys.length > 3 ? "..." : ""} }`;
609
+ }
610
+ return String(value);
611
+ }
612
+ async handleAsyncAssertion(value, assertion) {
613
+ try {
614
+ const resolvedValue = await this.actual;
615
+ if (this.isNot) {
616
+ throw new Error(`Promise resolved when it should have rejected`);
617
+ }
618
+ assertion(resolvedValue);
619
+ return Promise.resolve(resolvedValue);
620
+ } catch (error) {
621
+ if (this.isNot) {
622
+ return Promise.resolve(void 0);
623
+ }
624
+ if (typeof value === "string") {
625
+ this.assertCondition(
626
+ error.message?.includes(value),
627
+ `Expected error message to include "${value}"`
628
+ );
629
+ } else if (value instanceof RegExp) {
630
+ this.assertCondition(
631
+ value.test(error.message),
632
+ `Expected error message to match ${value}`
633
+ );
634
+ }
635
+ return Promise.resolve(void 0);
636
+ }
637
+ }
638
+ toBe(value) {
639
+ const stack = new Error().stack;
640
+ if (this.isAsync) {
641
+ return this.handleAsyncAssertion(value, (actual) => {
642
+ this.expected = value;
643
+ this.assertCondition(actual === value, `Expected values to be strictly equal (using ===)`, false, void 0, stack);
644
+ if (typeof actual !== typeof value) {
645
+ throw new Error(`Types don't match: expected ${typeof value} but got ${typeof actual}`);
646
+ }
647
+ });
648
+ }
649
+ this.expected = value;
650
+ this.assertCondition(this.actual === value, `Expected values to be strictly equal (using ===)`, true, void 0, stack);
651
+ if (typeof this.actual !== typeof value) {
652
+ throw new Error(`Types don't match: expected ${typeof value} but got ${typeof this.actual}`);
653
+ }
654
+ }
655
+ toEqual(value) {
656
+ const stack = new Error().stack;
657
+ this.expected = value;
658
+ const isEqual = (a, b) => {
659
+ if (a === b) return true;
660
+ if (a == null || b == null) return a === b;
661
+ if (typeof a !== typeof b) return false;
662
+ if (typeof a !== "object") return a === b;
663
+ if (Array.isArray(a) !== Array.isArray(b)) return false;
664
+ if (Array.isArray(a)) {
665
+ if (a.length !== b.length) return false;
666
+ return a.every((item, i) => isEqual(item, b[i]));
667
+ }
668
+ const keysA = Object.keys(a);
669
+ const keysB = Object.keys(b);
670
+ if (keysA.length !== keysB.length) return false;
671
+ return keysA.every((key) => isEqual(a[key], b[key]));
672
+ };
673
+ this.assertCondition(isEqual(this.actual, value), "Expected values to be deeply equal", false, void 0, stack);
674
+ }
675
+ toBeTruthy() {
676
+ const stack = new Error().stack;
677
+ this.assertCondition(!!this.actual, `Expected value to be truthy`, false, void 0, stack);
678
+ }
679
+ toBeFalsy() {
680
+ const stack = new Error().stack;
681
+ this.assertCondition(!this.actual, `Expected value to be falsy`, false, void 0, stack);
682
+ }
683
+ toBeNull() {
684
+ const stack = new Error().stack;
685
+ this.assertCondition(this.actual === null, `Expected value to be null`, false, void 0, stack);
686
+ }
687
+ toBeUndefined() {
688
+ const stack = new Error().stack;
689
+ this.assertCondition(this.actual === void 0, `Expected value to be undefined`, false, void 0, stack);
690
+ }
691
+ toBeDefined() {
692
+ const stack = new Error().stack;
693
+ this.assertCondition(this.actual !== void 0, `Expected value to be defined`, false, void 0, stack);
694
+ }
695
+ toBeGreaterThan(value) {
696
+ const stack = new Error().stack;
697
+ this.expected = value;
698
+ this.assertCondition(
699
+ typeof this.actual === "number" && this.actual > value,
700
+ `Expected ${this.stringify(this.actual)} to be greater than ${value}`,
701
+ true,
702
+ String(value),
703
+ stack
704
+ );
705
+ }
706
+ toBeGreaterThanOrEqual(value) {
707
+ const stack = new Error().stack;
708
+ this.expected = value;
709
+ this.assertCondition(
710
+ typeof this.actual === "number" && this.actual >= value,
711
+ `Expected ${this.stringify(this.actual)} to be greater than or equal to ${value}`,
712
+ true,
713
+ `${value}`,
714
+ stack
715
+ );
716
+ }
717
+ toBeLessThan(value) {
718
+ const stack = new Error().stack;
719
+ this.expected = value;
720
+ this.assertCondition(
721
+ typeof this.actual === "number" && this.actual < value,
722
+ `Expected ${this.stringify(this.actual)} to be less than ${value}`,
723
+ true,
724
+ String(value),
725
+ stack
726
+ );
727
+ }
728
+ toBeLessThanOrEqual(value) {
729
+ const stack = new Error().stack;
730
+ this.expected = value;
731
+ this.assertCondition(
732
+ typeof this.actual === "number" && this.actual <= value,
733
+ `Expected ${this.stringify(this.actual)} to be less than or equal to ${value}`,
734
+ true,
735
+ `${value}`,
736
+ stack
737
+ );
738
+ }
739
+ toContain(value) {
740
+ const stack = new Error().stack;
741
+ this.expected = value;
742
+ if (typeof this.actual === "string") {
743
+ this.assertCondition(
744
+ this.actual.includes(value),
745
+ `Expected "${this.actual}" to contain "${value}"`,
746
+ false,
747
+ void 0,
748
+ stack
749
+ );
750
+ } else if (Array.isArray(this.actual)) {
751
+ this.assertCondition(
752
+ this.actual.some((item) => this.deepEqual(item, value)),
753
+ `Expected array to contain ${this.stringify(value)}`,
754
+ false,
755
+ void 0,
756
+ stack
757
+ );
758
+ } else {
759
+ throw new Error(`toContain expects string or array, got ${typeof this.actual}`);
760
+ }
761
+ }
762
+ toHaveLength(length) {
763
+ const stack = new Error().stack;
764
+ this.expected = length;
765
+ const actualLength = this.actual?.length;
766
+ this.assertCondition(
767
+ actualLength === length,
768
+ `Expected length to be ${length}, but got ${actualLength}`,
769
+ false,
770
+ void 0,
771
+ stack
772
+ );
773
+ }
774
+ toThrow(error) {
775
+ if (this.isAsync) {
776
+ return this.handleAsyncAssertion(error, () => {
777
+ });
778
+ }
779
+ let threw = false;
780
+ let thrownError = null;
781
+ try {
782
+ if (typeof this.actual === "function") {
783
+ this.actual();
784
+ }
785
+ } catch (e) {
786
+ threw = true;
787
+ thrownError = e;
788
+ }
789
+ this.assertCondition(threw, `Expected function to throw an error`);
790
+ if (error) {
791
+ if (typeof error === "string") {
792
+ this.assertCondition(
793
+ thrownError.message.includes(error),
794
+ `Expected error message to include "${error}"`
795
+ );
796
+ } else if (error instanceof RegExp) {
797
+ this.assertCondition(
798
+ error.test(thrownError.message),
799
+ `Expected error message to match ${error}`
800
+ );
801
+ }
802
+ }
803
+ }
804
+ toMatch(pattern) {
805
+ this.expected = pattern;
806
+ const str = String(this.actual);
807
+ if (pattern instanceof RegExp) {
808
+ this.assertCondition(
809
+ pattern.test(str),
810
+ `Expected "${str}" to match ${pattern}`
811
+ );
812
+ } else {
813
+ this.assertCondition(
814
+ str.includes(pattern),
815
+ `Expected "${str}" to contain "${pattern}"`
816
+ );
817
+ }
818
+ }
819
+ toBeInstanceOf(classType) {
820
+ this.expected = classType;
821
+ this.assertCondition(
822
+ this.actual instanceof classType,
823
+ `Expected value to be instance of ${classType.name}`
824
+ );
825
+ }
826
+ toHaveProperty(path, value) {
827
+ const keys = Array.isArray(path) ? path : path.split(".");
828
+ let obj = this.actual;
829
+ for (const key of keys) {
830
+ if (obj == null || !Object.hasOwnProperty.call(obj, key)) {
831
+ throw new Error(`Expected object to have property "${path}"`);
832
+ }
833
+ obj = obj[key];
834
+ }
835
+ if (value !== void 0) {
836
+ this.assertCondition(
837
+ this.deepEqual(obj, value),
838
+ `Expected property "${path}" to equal ${this.stringify(value)}`
839
+ );
840
+ }
841
+ }
842
+ // Mock function matchers
843
+ toBeCalled() {
844
+ this.assertCondition(
845
+ this.actual._isMock && this.actual._calls.length > 0,
846
+ `Expected mock function to have been called`
847
+ );
848
+ }
849
+ toBeCalledTimes(times) {
850
+ this.assertCondition(
851
+ this.actual._isMock && this.actual._calls.length === times,
852
+ `Expected mock to be called ${times} times, but was called ${this.actual._calls?.length || 0} times`
853
+ );
854
+ }
855
+ toBeCalledWith(...args) {
856
+ this.assertCondition(this.actual._isMock && this.actual._calls.some((call) => this.deepEqual(call, args)), `Expected mock to be called with ${this.stringify(args)}`);
857
+ }
858
+ lastReturnedWith(value) {
859
+ const lastResult = this.actual._results?.[this.actual._results.length - 1];
860
+ this.assertCondition(
861
+ lastResult && this.deepEqual(lastResult.value, value),
862
+ `Expected last call to return ${this.stringify(value)}`
863
+ );
864
+ }
865
+ deepEqual(a, b) {
866
+ return JSON.stringify(a) === JSON.stringify(b);
867
+ }
868
+ };
869
+ function expect(actual) {
870
+ return new Expect(actual);
871
+ }
872
+ function createMockFunction() {
873
+ const mock = function(...args) {
874
+ mock._calls.push(args);
875
+ try {
876
+ const result = mock._implementation ? mock._implementation(...args) : void 0;
877
+ mock._results.push({ type: "return", value: result });
878
+ return result;
879
+ } catch (error) {
880
+ mock._results.push({ type: "throw", value: error });
881
+ throw error;
882
+ }
883
+ };
884
+ mock._isMock = true;
885
+ mock._calls = [];
886
+ mock._results = [];
887
+ mock._implementation = null;
888
+ mock.mockImplementation = function(fn) {
889
+ mock._implementation = fn;
890
+ return mock;
891
+ };
892
+ mock.mockReturnValue = function(value) {
893
+ mock._implementation = (() => value);
894
+ return mock;
895
+ };
896
+ mock.mockResolvedValue = function(value) {
897
+ mock._implementation = (() => Promise.resolve(value));
898
+ return mock;
899
+ };
900
+ mock.mockRejectedValue = function(value) {
901
+ mock._implementation = (() => Promise.reject(value));
902
+ return mock;
903
+ };
904
+ mock.restore = function() {
905
+ mock._calls = [];
906
+ mock._results = [];
907
+ mock._implementation = null;
908
+ };
909
+ mock.clear = function() {
910
+ mock._calls = [];
911
+ mock._results = [];
912
+ };
913
+ return mock;
914
+ }
915
+ var vi = {
916
+ fn: () => createMockFunction(),
917
+ spyOn: (obj, method) => {
918
+ const original = obj[method];
919
+ const mock = createMockFunction();
920
+ mock.mockImplementation(original);
921
+ obj[method] = mock;
922
+ mock.restore = () => {
923
+ obj[method] = original;
924
+ };
925
+ return mock;
926
+ },
927
+ clearAllMocks: () => {
928
+ },
929
+ restoreAllMocks: () => {
930
+ }
931
+ };
932
+ var beforeAllHooks = [];
933
+ var afterAllHooks = [];
934
+ var beforeEachHooks = [];
935
+ var afterEachHooks = [];
936
+ var beforeAll = (fn) => beforeAllHooks.push(fn);
937
+ var afterAll = (fn) => afterAllHooks.push(fn);
938
+ var beforeEach = (fn) => beforeEachHooks.push(fn);
939
+ var afterEach = (fn) => afterEachHooks.push(fn);
940
+ async function runTests(options) {
941
+ const { files, timeout = 5e3, bail = false, describePattern: descPattern, testPattern: tPattern } = options;
942
+ describePattern = descPattern;
943
+ testPattern = tPattern;
944
+ testResults.length = 0;
945
+ hasOnly = false;
946
+ for (const file of files) {
947
+ currentTestFile = file;
948
+ try {
949
+ const source = await readFile(file, "utf-8");
950
+ const testFileDir = dirname(file);
951
+ const importRegex = /import\s+{\s*([^}]+)\s*}\s+from\s+['"]([^'"]+)['"]/g;
952
+ const imports = {};
953
+ let importIndex = 0;
954
+ let codeWithoutImports = source.replace(importRegex, (_, named, path) => {
955
+ const varName = `__import_${importIndex++}`;
956
+ const trimmedNamed = named.trim();
957
+ imports[varName] = { path, named: trimmedNamed };
958
+ return `// ${trimmedNamed} import injected later
959
+ `;
960
+ });
961
+ const result = transformSync(codeWithoutImports, {
962
+ loader: file.endsWith(".ts") || file.endsWith(".tsx") ? "ts" : "js",
963
+ format: "iife",
964
+ sourcemap: "inline",
965
+ target: "es2020",
966
+ tsconfigRaw: {
967
+ compilerOptions: {
968
+ jsx: "react",
969
+ jsxFactory: "h",
970
+ jsxFragmentFactory: "Fragment"
971
+ }
972
+ }
973
+ });
974
+ let code = result.code;
975
+ const sourceMapMatch = code.match(/\/\/# sourceMappingURL=data:application\/json;base64,(.+)/);
976
+ if (sourceMapMatch) {
977
+ const base64 = sourceMapMatch[1];
978
+ const json = Buffer.from(base64, "base64").toString("utf-8");
979
+ const sourceMap = JSON.parse(json);
980
+ currentSourceMapConsumer = await new SourceMapConsumer(sourceMap);
981
+ } else {
982
+ currentSourceMapConsumer = void 0;
983
+ }
984
+ const importedValues = {};
985
+ const importParamNames = [];
986
+ const importAssignments = [];
987
+ if (Object.keys(imports).length > 0) {
988
+ for (const [, { path, named }] of Object.entries(imports)) {
989
+ let resolvedPath = path;
990
+ if (path.startsWith(".")) {
991
+ const nodePath = __require("path");
992
+ resolvedPath = nodePath.resolve(testFileDir, path);
993
+ }
994
+ if (!resolvedPath.endsWith(".ts") && !resolvedPath.endsWith(".js") && !resolvedPath.endsWith(".mjs") && !resolvedPath.endsWith(".cjs")) {
995
+ resolvedPath += ".ts";
996
+ }
997
+ if (resolvedPath.endsWith(".ts")) {
998
+ try {
999
+ const importSource = await readFile(resolvedPath, "utf-8");
1000
+ const transpiled = transformSync(importSource, {
1001
+ loader: "ts",
1002
+ format: "cjs",
1003
+ target: "es2020",
1004
+ tsconfigRaw: {
1005
+ compilerOptions: {
1006
+ jsx: "react",
1007
+ jsxFactory: "h",
1008
+ jsxFragmentFactory: "Fragment"
1009
+ }
1010
+ }
1011
+ });
1012
+ const moduleExports = {};
1013
+ const moduleObj = { exports: moduleExports };
1014
+ const fn2 = new Function("module", "exports", "require", "__filename", "__dirname", transpiled.code);
1015
+ const requireFn = (id) => {
1016
+ if (id.startsWith("elit/") || id === "elit") {
1017
+ return __require(id);
1018
+ }
1019
+ if (id.startsWith(".")) {
1020
+ const nodePath = __require("path");
1021
+ const absPath = nodePath.resolve(dirname(resolvedPath), id);
1022
+ return __require(absPath);
1023
+ }
1024
+ return __require(id);
1025
+ };
1026
+ fn2(moduleObj, moduleExports, requireFn, resolvedPath, dirname(resolvedPath));
1027
+ if (!resolvedPath.includes(".test.") && !resolvedPath.includes(".spec.")) {
1028
+ coveredFiles.add(resolvedPath);
1029
+ }
1030
+ let exportedValue = moduleObj.exports[named];
1031
+ if (exportedValue === void 0 && moduleObj.exports.default) {
1032
+ exportedValue = moduleObj.exports.default[named];
1033
+ }
1034
+ if (exportedValue === void 0 && typeof moduleObj.exports === "object") {
1035
+ exportedValue = moduleObj.exports[named];
1036
+ }
1037
+ const paramKey = `__import_${Math.random().toString(36).substring(2, 11)}`;
1038
+ importedValues[paramKey] = exportedValue;
1039
+ importParamNames.push(paramKey);
1040
+ importAssignments.push(`const ${named} = ${paramKey};`);
1041
+ } catch (err) {
1042
+ const paramKey = `__import_${Math.random().toString(36).substring(2, 11)}`;
1043
+ importedValues[paramKey] = null;
1044
+ importParamNames.push(paramKey);
1045
+ importAssignments.push(`const ${named} = ${paramKey}; /* Error importing ${resolvedPath}: ${err} */`);
1046
+ }
1047
+ } else {
1048
+ const requiredModule = __require(resolvedPath);
1049
+ const exportedValue = requiredModule[named];
1050
+ const paramKey = `__import_${Math.random().toString(36).substring(2, 11)}`;
1051
+ importedValues[paramKey] = exportedValue;
1052
+ importParamNames.push(paramKey);
1053
+ importAssignments.push(`const ${named} = ${paramKey};`);
1054
+ }
1055
+ }
1056
+ }
1057
+ let preamble = "";
1058
+ if (Object.keys(imports).length > 0) {
1059
+ const iifeStartMatch = code.match(/^(\s*(?:var\s+\w+\s*=\s*)?\(\(\)\s*=>\s*\{\n)/);
1060
+ if (iifeStartMatch) {
1061
+ const iifePrefix = iifeStartMatch[1];
1062
+ const assignments = `${importAssignments.join("\n")}
1063
+ `;
1064
+ preamble = iifePrefix;
1065
+ code = iifePrefix + assignments + code.slice(iifeStartMatch[1].length);
1066
+ } else {
1067
+ preamble = importAssignments.join("\n") + "\n";
1068
+ code = preamble + code;
1069
+ }
1070
+ }
1071
+ wrapperLineOffset = preamble.split("\n").length;
1072
+ setupGlobals();
1073
+ const allParams = ["describe", "it", "test", "expect", "beforeAll", "afterAll", "beforeEach", "afterEach", "vi", "require", "module", "__filename", "__dirname", ...importParamNames];
1074
+ const allArgs = [describe, it, test, expect, beforeAll, afterAll, beforeEach, afterEach, vi, __require, module, file, testFileDir, ...importParamNames.map((p) => importedValues[p])];
1075
+ const fn = new Function(...allParams, code);
1076
+ await fn(...allArgs);
1077
+ await executeSuite(currentSuite, timeout, bail);
1078
+ if (currentSourceMapConsumer) {
1079
+ currentSourceMapConsumer.destroy();
1080
+ currentSourceMapConsumer = void 0;
1081
+ }
1082
+ currentSuite = {
1083
+ name: "root",
1084
+ tests: [],
1085
+ suites: [],
1086
+ skip: false,
1087
+ only: false
1088
+ };
1089
+ hasOnly = false;
1090
+ beforeAllHooks = [];
1091
+ afterAllHooks = [];
1092
+ beforeEachHooks = [];
1093
+ afterEachHooks = [];
1094
+ } catch (error) {
1095
+ if (currentSourceMapConsumer) {
1096
+ currentSourceMapConsumer.destroy();
1097
+ currentSourceMapConsumer = void 0;
1098
+ }
1099
+ console.error(`Error loading test file ${file}:`, error);
1100
+ }
1101
+ }
1102
+ const passed = testResults.filter((r) => r.status === "pass").length;
1103
+ const failed = testResults.filter((r) => r.status === "fail").length;
1104
+ const skipped = testResults.filter((r) => r.status === "skip").length;
1105
+ const todo = testResults.filter((r) => r.status === "todo").length;
1106
+ return { passed, failed, skipped, todo, results: testResults };
1107
+ }
1108
+ async function executeSuite(suite, timeout, bail, parentMatched = false) {
1109
+ let directMatch = false;
1110
+ if (describePattern) {
1111
+ const escapedPattern = escapeRegex(describePattern);
1112
+ const regex = new RegExp(escapedPattern, "i");
1113
+ directMatch = regex.test(suite.name);
1114
+ }
1115
+ function suiteOrDescendantMatches(s) {
1116
+ if (!describePattern) return true;
1117
+ const escapedPattern = escapeRegex(describePattern);
1118
+ const regex = new RegExp(escapedPattern, "i");
1119
+ if (regex.test(s.name)) return true;
1120
+ for (const child of s.suites) {
1121
+ if (suiteOrDescendantMatches(child)) return true;
1122
+ }
1123
+ return false;
1124
+ }
1125
+ const shouldRunSuite = !describePattern || directMatch || parentMatched || suiteOrDescendantMatches(suite);
1126
+ if (!shouldRunSuite) {
1127
+ return;
1128
+ }
1129
+ if (suite.suites.length > 0) {
1130
+ for (const childSuite of suite.suites) {
1131
+ await executeSuite(childSuite, timeout, bail, parentMatched || directMatch);
1132
+ }
1133
+ }
1134
+ const shouldRunTests = !describePattern || directMatch || parentMatched || suite.name === "";
1135
+ if (!shouldRunTests) {
1136
+ return;
1137
+ }
1138
+ for (const hook of beforeAllHooks) {
1139
+ await hook();
1140
+ }
1141
+ for (const test2 of suite.tests) {
1142
+ if (hasOnly && !test2.only && !suite.only) {
1143
+ continue;
1144
+ }
1145
+ let testMatches = true;
1146
+ if (testPattern) {
1147
+ const escapedPattern = escapeRegex(testPattern);
1148
+ const regex = new RegExp(escapedPattern, "i");
1149
+ testMatches = regex.test(test2.name);
1150
+ }
1151
+ if (!testMatches) {
1152
+ continue;
1153
+ }
1154
+ if (test2.skip || suite.skip) {
1155
+ testResults.push({
1156
+ name: test2.name,
1157
+ status: "skip",
1158
+ duration: 0,
1159
+ suite: suite.name,
1160
+ file: currentTestFile
1161
+ });
1162
+ continue;
1163
+ }
1164
+ if (test2.todo) {
1165
+ testResults.push({
1166
+ name: test2.name,
1167
+ status: "todo",
1168
+ duration: 0,
1169
+ suite: suite.name,
1170
+ file: currentTestFile
1171
+ });
1172
+ continue;
1173
+ }
1174
+ for (const hook of beforeEachHooks) {
1175
+ await hook();
1176
+ }
1177
+ const startTime = Date.now();
1178
+ try {
1179
+ await Promise.race([
1180
+ test2.fn(),
1181
+ new Promise(
1182
+ (_, reject) => setTimeout(() => reject(new Error(`Test timed out after ${test2.timeout}ms`)), test2.timeout)
1183
+ )
1184
+ ]);
1185
+ testResults.push({
1186
+ name: test2.name,
1187
+ status: "pass",
1188
+ duration: Date.now() - startTime,
1189
+ suite: suite.name,
1190
+ file: currentTestFile
1191
+ });
1192
+ } catch (error) {
1193
+ let lineNumber = void 0;
1194
+ let codeSnippet = void 0;
1195
+ if (error instanceof AssertionError) {
1196
+ lineNumber = error.lineNumber;
1197
+ codeSnippet = error.codeSnippet;
1198
+ }
1199
+ testResults.push({
1200
+ name: test2.name,
1201
+ status: "fail",
1202
+ duration: Date.now() - startTime,
1203
+ error,
1204
+ suite: suite.name,
1205
+ file: currentTestFile,
1206
+ lineNumber,
1207
+ codeSnippet
1208
+ });
1209
+ if (bail) {
1210
+ throw error;
1211
+ }
1212
+ }
1213
+ for (const hook of afterEachHooks) {
1214
+ await hook();
1215
+ }
1216
+ }
1217
+ for (const hook of afterAllHooks) {
1218
+ await hook();
1219
+ }
1220
+ }
1221
+ var globals = {
1222
+ describe: createDescribeFunction(),
1223
+ it: createTestFunction(5e3),
1224
+ test: createTestFunction(5e3),
1225
+ expect,
1226
+ beforeAll,
1227
+ afterAll,
1228
+ beforeEach,
1229
+ afterEach,
1230
+ vi
1231
+ };
1232
+ function setupGlobals() {
1233
+ global.describe = globals.describe;
1234
+ global.it = globals.it;
1235
+ global.test = globals.test;
1236
+ global.expect = globals.expect;
1237
+ global.beforeAll = globals.beforeAll;
1238
+ global.afterAll = globals.afterAll;
1239
+ global.beforeEach = globals.beforeEach;
1240
+ global.afterEach = globals.afterEach;
1241
+ global.vi = globals.vi;
1242
+ }
1243
+ function clearGlobals() {
1244
+ delete global.describe;
1245
+ delete global.it;
1246
+ delete global.test;
1247
+ delete global.expect;
1248
+ delete global.beforeAll;
1249
+ delete global.afterAll;
1250
+ delete global.beforeEach;
1251
+ delete global.afterEach;
1252
+ delete global.vi;
1253
+ }
1254
+ function getCoveredFiles() {
1255
+ return coveredFiles;
1256
+ }
1257
+ function resetCoveredFiles() {
1258
+ coveredFiles.clear();
1259
+ }
1260
+ export {
1261
+ clearGlobals,
1262
+ getCoveredFiles,
1263
+ globals,
1264
+ resetCoveredFiles,
1265
+ runTests,
1266
+ setupGlobals,
1267
+ transpileFile
1268
+ };
1269
+ //# sourceMappingURL=test-runtime.mjs.map