elit 3.6.6 → 3.6.7

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 (153) hide show
  1. package/Cargo.lock +1 -1
  2. package/Cargo.toml +1 -1
  3. package/dist/build.cjs +421 -331
  4. package/dist/build.d.ts +1 -19
  5. package/dist/build.js +420 -330
  6. package/dist/build.mjs +420 -330
  7. package/dist/chokidar.cjs +219 -182
  8. package/dist/chokidar.d.ts +25 -10
  9. package/dist/chokidar.js +217 -182
  10. package/dist/chokidar.mjs +218 -183
  11. package/dist/cli.cjs +22439 -21563
  12. package/dist/cli.d.ts +19 -37
  13. package/dist/cli.mjs +24113 -23252
  14. package/dist/config.cjs +357 -350
  15. package/dist/config.d.ts +17 -245
  16. package/dist/config.js +520 -515
  17. package/dist/config.mjs +346 -341
  18. package/dist/contracts-BeW9k0yZ.d.ts +54 -0
  19. package/dist/contracts-D7KIS-TK.d.ts +36 -0
  20. package/dist/coverage.cjs +448 -485
  21. package/dist/coverage.d.ts +13 -62
  22. package/dist/coverage.js +447 -484
  23. package/dist/coverage.mjs +447 -484
  24. package/dist/database.cjs +819 -828
  25. package/dist/database.d.ts +8 -24
  26. package/dist/database.js +818 -829
  27. package/dist/database.mjs +818 -829
  28. package/dist/desktop-auto-render.cjs +1700 -1523
  29. package/dist/desktop-auto-render.d.ts +4 -12
  30. package/dist/desktop-auto-render.js +1695 -1518
  31. package/dist/desktop-auto-render.mjs +1696 -1519
  32. package/dist/desktop.cjs +3 -1
  33. package/dist/desktop.d.ts +4 -1
  34. package/dist/desktop.js +1 -1
  35. package/dist/desktop.mjs +1 -1
  36. package/dist/dev-build.cjs +830 -0
  37. package/dist/dev-build.d.ts +53 -0
  38. package/dist/dev-build.js +3318 -0
  39. package/dist/dev-build.mjs +797 -0
  40. package/dist/dom.cjs +717 -591
  41. package/dist/dom.d.ts +2 -17
  42. package/dist/dom.js +714 -588
  43. package/dist/dom.mjs +716 -590
  44. package/dist/el.cjs +62 -52
  45. package/dist/el.d.ts +5 -12
  46. package/dist/el.js +60 -52
  47. package/dist/el.mjs +60 -52
  48. package/dist/fs.cjs +72 -63
  49. package/dist/fs.d.ts +22 -19
  50. package/dist/fs.js +71 -62
  51. package/dist/fs.mjs +71 -62
  52. package/dist/hmr.cjs +40 -14
  53. package/dist/hmr.d.ts +11 -23
  54. package/dist/hmr.js +38 -14
  55. package/dist/hmr.mjs +38 -14
  56. package/dist/http.cjs +251 -99
  57. package/dist/http.d.ts +38 -104
  58. package/dist/http.js +249 -99
  59. package/dist/http.mjs +249 -99
  60. package/dist/https.cjs +524 -228
  61. package/dist/https.d.ts +44 -36
  62. package/dist/https.js +520 -226
  63. package/dist/https.mjs +522 -228
  64. package/dist/index.cjs +7502 -7691
  65. package/dist/index.d.ts +6 -3
  66. package/dist/index.js +7486 -7677
  67. package/dist/index.mjs +7497 -7687
  68. package/dist/mime-types.cjs +10 -4
  69. package/dist/mime-types.d.ts +8 -11
  70. package/dist/mime-types.js +9 -3
  71. package/dist/mime-types.mjs +9 -3
  72. package/dist/native.cjs +8616 -8870
  73. package/dist/native.d.ts +7 -10
  74. package/dist/native.js +8682 -8936
  75. package/dist/native.mjs +8615 -8869
  76. package/dist/path.cjs +83 -77
  77. package/dist/path.d.ts +29 -29
  78. package/dist/path.js +82 -76
  79. package/dist/path.mjs +82 -76
  80. package/dist/pm.cjs +3300 -0
  81. package/dist/pm.d.ts +256 -0
  82. package/dist/pm.js +5638 -0
  83. package/dist/pm.mjs +3196 -0
  84. package/dist/preview-build.cjs +712 -0
  85. package/dist/preview-build.d.ts +59 -0
  86. package/dist/preview-build.js +3194 -0
  87. package/dist/preview-build.mjs +676 -0
  88. package/dist/render-context.cjs +13 -2
  89. package/dist/render-context.d.ts +9 -34
  90. package/dist/render-context.js +11 -2
  91. package/dist/render-context.mjs +11 -2
  92. package/dist/router.cjs +787 -646
  93. package/dist/router.d.ts +8 -14
  94. package/dist/router.js +786 -645
  95. package/dist/router.mjs +786 -645
  96. package/dist/runtime.cjs +1 -1
  97. package/dist/runtime.js +1 -1
  98. package/dist/runtime.mjs +1 -1
  99. package/dist/server.cjs +3254 -2684
  100. package/dist/server.d.ts +47 -5
  101. package/dist/server.js +3427 -2859
  102. package/dist/server.mjs +3397 -2829
  103. package/dist/smtp-server.cjs +16 -3
  104. package/dist/smtp-server.d.ts +12 -26
  105. package/dist/smtp-server.js +18 -5
  106. package/dist/smtp-server.mjs +16 -3
  107. package/dist/state-DvEkDehk.d.ts +195 -0
  108. package/dist/state.cjs +768 -659
  109. package/dist/state.d.ts +11 -71
  110. package/dist/state.js +760 -651
  111. package/dist/state.mjs +767 -658
  112. package/dist/style.cjs +1011 -968
  113. package/dist/style.d.ts +13 -127
  114. package/dist/style.js +1009 -970
  115. package/dist/style.mjs +1011 -971
  116. package/dist/test-reporter.cjs +332 -316
  117. package/dist/test-reporter.d.ts +28 -33
  118. package/dist/test-reporter.js +328 -312
  119. package/dist/test-reporter.mjs +328 -312
  120. package/dist/test-runtime.cjs +927 -968
  121. package/dist/test-runtime.d.ts +24 -99
  122. package/dist/test-runtime.js +922 -965
  123. package/dist/test-runtime.mjs +922 -965
  124. package/dist/test.cjs +4428 -4273
  125. package/dist/test.d.ts +2 -8
  126. package/dist/test.js +4307 -4154
  127. package/dist/test.mjs +4419 -4267
  128. package/dist/types-BONVzPtp.d.ts +59 -0
  129. package/dist/types-BR4wMiVx.d.ts +32 -0
  130. package/dist/types-C4gKykuG.d.ts +23 -0
  131. package/dist/types-CIhpN1-K.d.ts +64 -0
  132. package/dist/types-Ckj8md_j.d.ts +84 -0
  133. package/dist/types-CpjQTAkX.d.ts +24 -0
  134. package/dist/types-D0LjrYjS.d.ts +14 -0
  135. package/dist/types-DAisuVr5.d.ts +75 -0
  136. package/dist/types-tJn88E1N.d.ts +242 -0
  137. package/dist/types.d.ts +50 -237
  138. package/dist/universal.cjs +1 -1
  139. package/dist/universal.d.ts +1 -7
  140. package/dist/universal.js +1 -1
  141. package/dist/universal.mjs +1 -1
  142. package/dist/websocket-XfyK23zD.d.ts +119 -0
  143. package/dist/ws.cjs +129 -108
  144. package/dist/ws.d.ts +21 -131
  145. package/dist/ws.js +128 -109
  146. package/dist/ws.mjs +128 -109
  147. package/dist/wss.cjs +757 -479
  148. package/dist/wss.d.ts +31 -28
  149. package/dist/wss.js +755 -479
  150. package/dist/wss.mjs +758 -482
  151. package/package.json +8 -1
  152. package/vendor/epaint-0.31.1/src/image.rs +418 -0
  153. package/dist/server-uMQvZAll.d.ts +0 -458
@@ -66,7 +66,7 @@
66
66
  initialize: () => initialize,
67
67
  stop: () => stop,
68
68
  transform: () => transform,
69
- transformSync: () => transformSync2,
69
+ transformSync: () => transformSync3,
70
70
  version: () => version
71
71
  });
72
72
  module.exports = __toCommonJS(node_exports);
@@ -2202,7 +2202,7 @@ More information: The file containing the code for esbuild's JavaScript API (${_
2202
2202
  }));
2203
2203
  return result;
2204
2204
  };
2205
- var transformSync2 = (input, options) => {
2205
+ var transformSync3 = (input, options) => {
2206
2206
  if (worker_threads && !isInternalWorkerThread) {
2207
2207
  if (!workerThreadService) workerThreadService = startWorkerThreadService(worker_threads);
2208
2208
  return workerThreadService.transformSync(input, options);
@@ -4649,10 +4649,53 @@ error: ${text}`);
4649
4649
  }
4650
4650
  });
4651
4651
 
4652
- // src/test-runtime.ts
4653
- var import_esbuild = __toESM(require_main());
4652
+ // src/test/runtime/state.ts
4653
+ function createRootSuite() {
4654
+ return {
4655
+ name: "root",
4656
+ tests: [],
4657
+ suites: [],
4658
+ skip: false,
4659
+ only: false
4660
+ };
4661
+ }
4662
+ var runtimeState = {
4663
+ currentSuite: createRootSuite(),
4664
+ testResults: [],
4665
+ hasOnly: false,
4666
+ coveredFiles: /* @__PURE__ */ new Set(),
4667
+ describePattern: void 0,
4668
+ testPattern: void 0,
4669
+ currentTestFile: void 0,
4670
+ currentSourceMapConsumer: void 0,
4671
+ wrapperLineOffset: 0,
4672
+ beforeAllHooks: [],
4673
+ afterAllHooks: [],
4674
+ beforeEachHooks: [],
4675
+ afterEachHooks: []
4676
+ };
4677
+ function resetSuiteState() {
4678
+ runtimeState.currentSuite = createRootSuite();
4679
+ runtimeState.hasOnly = false;
4680
+ }
4681
+ function resetHookState() {
4682
+ runtimeState.beforeAllHooks = [];
4683
+ runtimeState.afterAllHooks = [];
4684
+ runtimeState.beforeEachHooks = [];
4685
+ runtimeState.afterEachHooks = [];
4686
+ }
4687
+ function resetSourceMapState() {
4688
+ runtimeState.currentSourceMapConsumer = void 0;
4689
+ runtimeState.wrapperLineOffset = 0;
4690
+ }
4691
+ function getCoveredFiles() {
4692
+ return runtimeState.coveredFiles;
4693
+ }
4694
+ function resetCoveredFiles() {
4695
+ runtimeState.coveredFiles.clear();
4696
+ }
4654
4697
 
4655
- // src/runtime.ts
4698
+ // src/shares/runtime.ts
4656
4699
  var runtime = (() => {
4657
4700
  if (typeof Deno !== "undefined") return "deno";
4658
4701
  if (typeof Bun !== "undefined") return "bun";
@@ -4662,7 +4705,15 @@ error: ${text}`);
4662
4705
  var isBun = runtime === "bun";
4663
4706
  var isDeno = runtime === "deno";
4664
4707
 
4665
- // src/fs.ts
4708
+ // src/server/fs/node-modules.ts
4709
+ var fs;
4710
+ var fsPromises;
4711
+ if (isNode || isBun) {
4712
+ fs = __require("fs");
4713
+ fsPromises = __require("fs/promises");
4714
+ }
4715
+
4716
+ // src/server/fs/utils.ts
4666
4717
  function parseOptions(options, defaultValue) {
4667
4718
  return typeof options === "string" ? { encoding: options } : options || defaultValue;
4668
4719
  }
@@ -4672,12 +4723,37 @@ error: ${text}`);
4672
4723
  }
4673
4724
  return Buffer.from(content instanceof ArrayBuffer ? new Uint8Array(content) : content);
4674
4725
  }
4675
- var fs;
4676
- var fsPromises;
4677
- if (isNode || isBun) {
4678
- fs = __require("fs");
4679
- fsPromises = __require("fs/promises");
4726
+ function createStatsFromDenoFileInfo(info) {
4727
+ return {
4728
+ isFile: () => info.isFile,
4729
+ isDirectory: () => info.isDirectory,
4730
+ isBlockDevice: () => false,
4731
+ isCharacterDevice: () => false,
4732
+ isSymbolicLink: () => info.isSymlink || false,
4733
+ isFIFO: () => false,
4734
+ isSocket: () => false,
4735
+ dev: info.dev || 0,
4736
+ ino: info.ino || 0,
4737
+ mode: info.mode || 0,
4738
+ nlink: info.nlink || 1,
4739
+ uid: info.uid || 0,
4740
+ gid: info.gid || 0,
4741
+ rdev: 0,
4742
+ size: info.size,
4743
+ blksize: info.blksize || 4096,
4744
+ blocks: info.blocks || Math.ceil(info.size / 512),
4745
+ atimeMs: info.atime?.getTime() || Date.now(),
4746
+ mtimeMs: info.mtime?.getTime() || Date.now(),
4747
+ ctimeMs: info.birthtime?.getTime() || Date.now(),
4748
+ birthtimeMs: info.birthtime?.getTime() || Date.now(),
4749
+ atime: info.atime || /* @__PURE__ */ new Date(),
4750
+ mtime: info.mtime || /* @__PURE__ */ new Date(),
4751
+ ctime: info.birthtime || /* @__PURE__ */ new Date(),
4752
+ birthtime: info.birthtime || /* @__PURE__ */ new Date()
4753
+ };
4680
4754
  }
4755
+
4756
+ // src/server/fs/file-ops.ts
4681
4757
  async function readFile(path, options) {
4682
4758
  const opts = parseOptions(options, {});
4683
4759
  if (isNode || isBun) {
@@ -4715,421 +4791,460 @@ error: ${text}`);
4715
4791
  }
4716
4792
  throw new Error("Unsupported runtime");
4717
4793
  }
4718
- function createStatsFromDenoFileInfo(info) {
4719
- return {
4720
- isFile: () => info.isFile,
4721
- isDirectory: () => info.isDirectory,
4722
- isBlockDevice: () => false,
4723
- isCharacterDevice: () => false,
4724
- isSymbolicLink: () => info.isSymlink || false,
4725
- isFIFO: () => false,
4726
- isSocket: () => false,
4727
- dev: info.dev || 0,
4728
- ino: info.ino || 0,
4729
- mode: info.mode || 0,
4730
- nlink: info.nlink || 1,
4731
- uid: info.uid || 0,
4732
- gid: info.gid || 0,
4733
- rdev: 0,
4734
- size: info.size,
4735
- blksize: info.blksize || 4096,
4736
- blocks: info.blocks || Math.ceil(info.size / 512),
4737
- atimeMs: info.atime?.getTime() || Date.now(),
4738
- mtimeMs: info.mtime?.getTime() || Date.now(),
4739
- ctimeMs: info.birthtime?.getTime() || Date.now(),
4740
- birthtimeMs: info.birthtime?.getTime() || Date.now(),
4741
- atime: info.atime || /* @__PURE__ */ new Date(),
4742
- mtime: info.mtime || /* @__PURE__ */ new Date(),
4743
- ctime: info.birthtime || /* @__PURE__ */ new Date(),
4744
- birthtime: info.birthtime || /* @__PURE__ */ new Date()
4745
- };
4746
- }
4747
4794
 
4748
- // src/path.ts
4749
- function getSeparator(isWin) {
4750
- return isWin ? "\\" : "/";
4751
- }
4752
- function getCwd() {
4753
- if (isNode || isBun) {
4754
- return process.cwd();
4755
- } else if (isDeno) {
4756
- return Deno.cwd();
4757
- }
4758
- return "/";
4795
+ // src/test/runtime/assertion-context.ts
4796
+ function getAssertionMethod(stack) {
4797
+ const assertionMatch = stack.match(/at _?Expect\.(\w+)/);
4798
+ return assertionMatch ? assertionMatch[1] : void 0;
4759
4799
  }
4760
- function findLastSeparator(path) {
4761
- return Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
4762
- }
4763
- function createPathOps(isWin) {
4764
- return {
4765
- sep: getSeparator(isWin),
4766
- delimiter: isWin ? ";" : ":",
4767
- normalize: (path) => normalizePath(path, isWin),
4768
- join: (...paths) => joinPaths(paths, isWin),
4769
- resolve: (...paths) => resolvePaths(paths, isWin),
4770
- isAbsolute: (path) => isWin ? isAbsoluteWin(path) : isAbsolutePosix(path),
4771
- relative: (from, to) => relativePath(from, to, isWin),
4772
- dirname: (path) => getDirname(path, isWin),
4773
- basename: (path, ext) => getBasename(path, ext, isWin),
4774
- extname: (path) => getExtname(path),
4775
- parse: (path) => parsePath(path, isWin),
4776
- format: (pathObject) => formatPath(pathObject, isWin)
4777
- };
4800
+ function getTargetPattern(assertionMethod) {
4801
+ if (assertionMethod === "toEqual") return ".toEqual(";
4802
+ if (assertionMethod === "toStrictEqual") return ".toStrictEqual(";
4803
+ if (assertionMethod === "toMatch") return ".toMatch(";
4804
+ if (assertionMethod === "toContain") return ".toContain(";
4805
+ if (assertionMethod === "toHaveLength") return ".toHaveLength(";
4806
+ if (assertionMethod === "toBeDefined") return ".toBeDefined(";
4807
+ if (assertionMethod === "toBeNull") return ".toBeNull(";
4808
+ if (assertionMethod === "toBeUndefined") return ".toBeUndefined(";
4809
+ if (assertionMethod === "toBeTruthy") return ".toBeTruthy(";
4810
+ if (assertionMethod === "toBeFalsy") return ".toBeFalsy(";
4811
+ if (assertionMethod === "toThrow") return ".toThrow(";
4812
+ if (assertionMethod === "toBeGreaterThan") return ".toBeGreaterThan(";
4813
+ if (assertionMethod === "toBeGreaterThanOrEqual") return ".toBeGreaterThanOrEqual(";
4814
+ if (assertionMethod === "toBeLessThan") return ".toBeLessThan(";
4815
+ if (assertionMethod === "toBeLessThanOrEqual") return ".toBeLessThanOrEqual(";
4816
+ return ".toBe(";
4778
4817
  }
4779
- function isAbsolutePosix(path) {
4780
- return path.length > 0 && path[0] === "/";
4818
+ function readSourceLines(filePath) {
4819
+ try {
4820
+ let sourceCode = readFileSync(filePath, "utf-8");
4821
+ if (Buffer.isBuffer(sourceCode)) {
4822
+ sourceCode = sourceCode.toString("utf-8");
4823
+ }
4824
+ return sourceCode.split("\n");
4825
+ } catch {
4826
+ return void 0;
4827
+ }
4781
4828
  }
4782
- function isAbsoluteWin(path) {
4783
- const len = path.length;
4784
- if (len === 0) return false;
4785
- const code = path.charCodeAt(0);
4786
- if (code === 47 || code === 92) {
4787
- return true;
4829
+ function resolveMappedLine(lineNumber, sourceLines, assertionMethod) {
4830
+ const targetPattern = getTargetPattern(assertionMethod);
4831
+ if (lineNumber <= 0 || lineNumber > sourceLines.length) {
4832
+ return lineNumber;
4788
4833
  }
4789
- if (code >= 65 && code <= 90 || code >= 97 && code <= 122) {
4790
- if (len > 2 && path.charCodeAt(1) === 58) {
4791
- const code2 = path.charCodeAt(2);
4792
- if (code2 === 47 || code2 === 92) {
4793
- return true;
4794
- }
4834
+ if (sourceLines[lineNumber - 1].includes(targetPattern)) {
4835
+ return lineNumber;
4836
+ }
4837
+ for (let index = 1; index <= 3; index++) {
4838
+ const searchLine = lineNumber - index;
4839
+ if (searchLine > 0 && searchLine <= sourceLines.length && sourceLines[searchLine - 1].includes(targetPattern)) {
4840
+ return searchLine;
4795
4841
  }
4796
4842
  }
4797
- return false;
4843
+ return lineNumber;
4798
4844
  }
4799
- var isWindows = (() => {
4800
- if (isNode) {
4801
- return process.platform === "win32";
4802
- } else if (isDeno) {
4803
- return Deno.build.os === "windows";
4845
+ function resolveAssertionContext(stack) {
4846
+ if (!stack) {
4847
+ return {};
4804
4848
  }
4805
- return typeof process !== "undefined" && process.platform === "win32";
4806
- })();
4807
- var posix = createPathOps(false);
4808
- var win32 = createPathOps(true);
4809
- function normalizePath(path, isWin) {
4810
- if (path.length === 0) return ".";
4811
- const separator = getSeparator(isWin);
4812
- const isAbsolute = isWin ? isAbsoluteWin(path) : isAbsolutePosix(path);
4813
- const trailingSeparator = path[path.length - 1] === separator || isWin && path[path.length - 1] === "/";
4814
- let normalized = path.replace(isWin ? /[\/\\]+/g : /\/+/g, separator);
4815
- const parts = normalized.split(separator);
4816
- const result = [];
4817
- for (let i = 0; i < parts.length; i++) {
4818
- const part = parts[i];
4819
- if (part === "" || part === ".") {
4820
- if (i === 0 && isAbsolute) result.push("");
4821
- continue;
4849
+ const assertionMethod = getAssertionMethod(stack);
4850
+ const stackFrames = [];
4851
+ for (const line of stack.split("\n")) {
4852
+ const match = line.match(/<anonymous>:([0-9]+):([0-9]+)/);
4853
+ if (match) {
4854
+ stackFrames.push({
4855
+ line: parseInt(match[1], 10),
4856
+ column: parseInt(match[2], 10)
4857
+ });
4822
4858
  }
4823
- if (part === "..") {
4824
- if (result.length > 0 && result[result.length - 1] !== "..") {
4825
- if (!(result.length === 1 && result[0] === "")) {
4826
- result.pop();
4859
+ }
4860
+ const targetFrame = stackFrames.length > 1 ? stackFrames[1] : stackFrames[0];
4861
+ let lineNumber;
4862
+ if (targetFrame && runtimeState.currentSourceMapConsumer) {
4863
+ try {
4864
+ const transpiledLine = targetFrame.line - runtimeState.wrapperLineOffset;
4865
+ const originalPosition = runtimeState.currentSourceMapConsumer.originalPositionFor({
4866
+ line: transpiledLine,
4867
+ column: targetFrame.column
4868
+ });
4869
+ if (originalPosition.line !== null) {
4870
+ lineNumber = originalPosition.line;
4871
+ } else {
4872
+ const posWithoutColumn = runtimeState.currentSourceMapConsumer.originalPositionFor({
4873
+ line: transpiledLine,
4874
+ column: 0
4875
+ });
4876
+ if (posWithoutColumn.line !== null) {
4877
+ lineNumber = posWithoutColumn.line;
4878
+ } else {
4879
+ const lineMappings = [];
4880
+ runtimeState.currentSourceMapConsumer.eachMapping((mapping) => {
4881
+ if (mapping.originalLine !== null) {
4882
+ lineMappings.push({
4883
+ line: mapping.originalLine,
4884
+ distance: Math.abs(mapping.generatedLine - transpiledLine)
4885
+ });
4886
+ }
4887
+ });
4888
+ if (lineMappings.length > 0) {
4889
+ lineMappings.sort((left, right) => left.distance - right.distance);
4890
+ lineNumber = lineMappings[0].line;
4891
+ }
4827
4892
  }
4828
- } else if (!isAbsolute) {
4829
- result.push("..");
4830
4893
  }
4831
- } else {
4832
- result.push(part);
4894
+ } catch {
4833
4895
  }
4834
4896
  }
4835
- let final = result.join(separator);
4836
- if (final.length === 0) {
4837
- return isAbsolute ? separator : ".";
4897
+ if (!runtimeState.currentTestFile || !lineNumber) {
4898
+ return { lineNumber };
4838
4899
  }
4839
- if (trailingSeparator && final[final.length - 1] !== separator) {
4840
- final += separator;
4900
+ const sourceLines = readSourceLines(runtimeState.currentTestFile);
4901
+ if (!sourceLines) {
4902
+ return { lineNumber };
4841
4903
  }
4842
- return final;
4904
+ lineNumber = resolveMappedLine(lineNumber, sourceLines, assertionMethod);
4905
+ const codeLine = lineNumber > 0 && lineNumber <= sourceLines.length ? sourceLines[lineNumber - 1] : void 0;
4906
+ return {
4907
+ lineNumber,
4908
+ codeSnippet: codeLine ? codeLine.trim() : void 0
4909
+ };
4843
4910
  }
4844
- function joinPaths(paths, isWin) {
4845
- if (paths.length === 0) return ".";
4846
- const separator = getSeparator(isWin);
4847
- let joined = "";
4848
- for (let i = 0; i < paths.length; i++) {
4849
- const path = paths[i];
4850
- if (path && path.length > 0) {
4851
- if (joined.length === 0) {
4852
- joined = path;
4853
- } else {
4854
- joined += separator + path;
4855
- }
4856
- }
4911
+
4912
+ // src/test/runtime/expect.ts
4913
+ var AssertionError = class extends Error {
4914
+ constructor(message, filePath, lineNumber, columnNumber, codeSnippet) {
4915
+ super(message);
4916
+ this.filePath = filePath;
4917
+ this.lineNumber = lineNumber;
4918
+ this.columnNumber = columnNumber;
4919
+ this.codeSnippet = codeSnippet;
4920
+ this.name = "AssertionError";
4857
4921
  }
4858
- if (joined.length === 0) return ".";
4859
- return normalizePath(joined, isWin);
4860
- }
4861
- function resolvePaths(paths, isWin) {
4862
- const separator = getSeparator(isWin);
4863
- let resolved = "";
4864
- let isAbsolute = false;
4865
- for (let i = paths.length - 1; i >= 0 && !isAbsolute; i--) {
4866
- const path = paths[i];
4867
- if (path && path.length > 0) {
4868
- resolved = path + (resolved.length > 0 ? separator + resolved : "");
4869
- isAbsolute = isWin ? isAbsoluteWin(resolved) : isAbsolutePosix(resolved);
4870
- }
4922
+ };
4923
+ var Expect = class _Expect {
4924
+ constructor(actual, isNot = false, isAsync = false) {
4925
+ this.actual = actual;
4926
+ this.isNot = isNot;
4927
+ this.isAsync = isAsync;
4928
+ this._not = null;
4929
+ this._resolves = null;
4930
+ this._rejects = null;
4871
4931
  }
4872
- if (!isAbsolute) {
4873
- const cwd = getCwd();
4874
- resolved = cwd + (resolved.length > 0 ? separator + resolved : "");
4932
+ get not() {
4933
+ if (!this._not) {
4934
+ this._not = new _Expect(this.actual, !this.isNot, false);
4935
+ }
4936
+ return this._not;
4875
4937
  }
4876
- return normalizePath(resolved, isWin);
4877
- }
4878
- function relativePath(from, to, isWin) {
4879
- from = resolvePaths([from], isWin);
4880
- to = resolvePaths([to], isWin);
4881
- if (from === to) return "";
4882
- const separator = getSeparator(isWin);
4883
- const fromParts = from.split(separator).filter((p) => p.length > 0);
4884
- const toParts = to.split(separator).filter((p) => p.length > 0);
4885
- let commonLength = 0;
4886
- const minLength = Math.min(fromParts.length, toParts.length);
4887
- for (let i = 0; i < minLength; i++) {
4888
- if (fromParts[i] === toParts[i]) {
4889
- commonLength++;
4890
- } else {
4891
- break;
4938
+ get resolves() {
4939
+ if (!this._resolves) {
4940
+ this._resolves = new _Expect(this.actual, this.isNot, true);
4892
4941
  }
4942
+ return this._resolves;
4893
4943
  }
4894
- const upCount = fromParts.length - commonLength;
4895
- const result = [];
4896
- for (let i = 0; i < upCount; i++) {
4897
- result.push("..");
4944
+ get rejects() {
4945
+ if (!this._rejects) {
4946
+ this._rejects = new _Expect(this.actual, this.isNot, true);
4947
+ }
4948
+ return this._rejects;
4898
4949
  }
4899
- for (let i = commonLength; i < toParts.length; i++) {
4900
- result.push(toParts[i]);
4950
+ assertCondition(condition, message, showExpectedReceived = true, expectedDisplay, callerStack) {
4951
+ if (this.isNot) {
4952
+ condition = !condition;
4953
+ }
4954
+ if (!condition) {
4955
+ let errorMessage = message;
4956
+ if (showExpectedReceived) {
4957
+ const expectedValue = expectedDisplay ?? this.stringify(this.expected ?? "truthy");
4958
+ errorMessage += `
4959
+ Expected: ${expectedValue}
4960
+ Received: ${this.stringify(this.actual)}`;
4961
+ }
4962
+ const stack = callerStack || new Error().stack;
4963
+ const { lineNumber, codeSnippet } = resolveAssertionContext(stack);
4964
+ throw new AssertionError(errorMessage, runtimeState.currentTestFile, lineNumber, void 0, codeSnippet);
4965
+ }
4901
4966
  }
4902
- return result.join(separator) || ".";
4903
- }
4904
- function getDirname(path, isWin) {
4905
- if (path.length === 0) return ".";
4906
- const separator = getSeparator(isWin);
4907
- const normalized = normalizePath(path, isWin);
4908
- const lastSepIndex = normalized.lastIndexOf(separator);
4909
- if (lastSepIndex === -1) return ".";
4910
- if (lastSepIndex === 0) return separator;
4911
- return normalized.slice(0, lastSepIndex);
4912
- }
4913
- function getBasename(path, ext, isWin) {
4914
- if (path.length === 0) return "";
4915
- const lastSepIndex = isWin ? findLastSeparator(path) : path.lastIndexOf("/");
4916
- let base = lastSepIndex === -1 ? path : path.slice(lastSepIndex + 1);
4917
- if (ext && base.endsWith(ext)) {
4918
- base = base.slice(0, base.length - ext.length);
4919
- }
4920
- return base;
4921
- }
4922
- function getExtname(path) {
4923
- const lastDotIndex = path.lastIndexOf(".");
4924
- const lastSepIndex = findLastSeparator(path);
4925
- if (lastDotIndex === -1 || lastDotIndex < lastSepIndex || lastDotIndex === path.length - 1) {
4926
- return "";
4967
+ stringify(value) {
4968
+ if (value === void 0) return "undefined";
4969
+ if (value === null) return "null";
4970
+ if (typeof value === "string") return `"${value}"`;
4971
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
4972
+ if (typeof value === "function") return "Function";
4973
+ if (Array.isArray(value)) return `[${value.map((item) => this.stringify(item)).join(", ")}]`;
4974
+ if (typeof value === "object") {
4975
+ const keys = Object.keys(value);
4976
+ if (keys.length === 0) return "{}";
4977
+ return `{ ${keys.slice(0, 3).map((key) => `${key}: ${this.stringify(value[key])}`).join(", ")}${keys.length > 3 ? "..." : ""} }`;
4978
+ }
4979
+ return String(value);
4927
4980
  }
4928
- return path.slice(lastDotIndex);
4929
- }
4930
- function parsePath(path, isWin) {
4931
- let root = "";
4932
- if (isWin) {
4933
- if (path.length >= 2 && path[1] === ":") {
4934
- root = path.slice(0, 2);
4935
- if (path.length > 2 && (path[2] === "\\" || path[2] === "/")) {
4936
- root += "\\";
4981
+ async handleAsyncAssertion(value, assertion) {
4982
+ try {
4983
+ const resolvedValue = await this.actual;
4984
+ if (this.isNot) {
4985
+ throw new Error("Promise resolved when it should have rejected");
4937
4986
  }
4938
- } else if (path[0] === "\\" || path[0] === "/") {
4939
- root = "\\";
4987
+ assertion(resolvedValue);
4988
+ return Promise.resolve(resolvedValue);
4989
+ } catch (error) {
4990
+ if (this.isNot) {
4991
+ return Promise.resolve(void 0);
4992
+ }
4993
+ if (typeof value === "string") {
4994
+ this.assertCondition(
4995
+ error.message?.includes(value),
4996
+ `Expected error message to include "${value}"`
4997
+ );
4998
+ } else if (value instanceof RegExp) {
4999
+ this.assertCondition(
5000
+ value.test(error.message),
5001
+ `Expected error message to match ${value}`
5002
+ );
5003
+ }
5004
+ return Promise.resolve(void 0);
4940
5005
  }
4941
- } else {
4942
- if (path[0] === "/") {
4943
- root = "/";
5006
+ }
5007
+ toBe(value) {
5008
+ const stack = new Error().stack;
5009
+ if (this.isAsync) {
5010
+ return this.handleAsyncAssertion(value, (actual) => {
5011
+ this.expected = value;
5012
+ this.assertCondition(actual === value, "Expected values to be strictly equal (using ===)", false, void 0, stack);
5013
+ if (typeof actual !== typeof value) {
5014
+ throw new Error(`Types don't match: expected ${typeof value} but got ${typeof actual}`);
5015
+ }
5016
+ });
5017
+ }
5018
+ this.expected = value;
5019
+ this.assertCondition(this.actual === value, "Expected values to be strictly equal (using ===)", true, void 0, stack);
5020
+ if (typeof this.actual !== typeof value) {
5021
+ throw new Error(`Types don't match: expected ${typeof value} but got ${typeof this.actual}`);
4944
5022
  }
4945
5023
  }
4946
- const dir = getDirname(path, isWin);
4947
- const base = getBasename(path, void 0, isWin);
4948
- const ext = getExtname(path);
4949
- const name = ext ? base.slice(0, base.length - ext.length) : base;
4950
- return { root, dir, base, ext, name };
4951
- }
4952
- function formatPath(pathObject, isWin) {
4953
- const separator = getSeparator(isWin);
4954
- const dir = pathObject.dir || pathObject.root || "";
4955
- const base = pathObject.base || (pathObject.name || "") + (pathObject.ext || "");
4956
- if (!dir) return base;
4957
- if (dir === pathObject.root) return dir + base;
4958
- return dir + separator + base;
4959
- }
4960
- function dirname(path) {
4961
- return getDirname(path, isWindows);
4962
- }
4963
-
4964
- // src/test-runtime.ts
4965
- var import_source_map = __toESM(require_source_map());
4966
- function escapeRegex(str) {
4967
- return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4968
- }
4969
- var AssertionError = class extends Error {
4970
- constructor(message, filePath, lineNumber, columnNumber, codeSnippet) {
4971
- super(message);
4972
- this.filePath = filePath;
4973
- this.lineNumber = lineNumber;
4974
- this.columnNumber = columnNumber;
4975
- this.codeSnippet = codeSnippet;
4976
- this.name = "AssertionError";
5024
+ toEqual(value) {
5025
+ const stack = new Error().stack;
5026
+ this.expected = value;
5027
+ const isEqual = (left, right) => {
5028
+ if (left === right) return true;
5029
+ if (left == null || right == null) return left === right;
5030
+ if (typeof left !== typeof right) return false;
5031
+ if (typeof left !== "object") return left === right;
5032
+ if (Array.isArray(left) !== Array.isArray(right)) return false;
5033
+ if (Array.isArray(left)) {
5034
+ if (left.length !== right.length) return false;
5035
+ return left.every((item, index) => isEqual(item, right[index]));
5036
+ }
5037
+ const keysLeft = Object.keys(left);
5038
+ const keysRight = Object.keys(right);
5039
+ if (keysLeft.length !== keysRight.length) return false;
5040
+ return keysLeft.every((key) => isEqual(left[key], right[key]));
5041
+ };
5042
+ this.assertCondition(isEqual(this.actual, value), "Expected values to be deeply equal", false, void 0, stack);
4977
5043
  }
4978
- };
4979
- var currentSuite = {
4980
- name: "root",
4981
- tests: [],
4982
- suites: [],
4983
- skip: false,
4984
- only: false
4985
- };
4986
- var testResults = [];
4987
- var hasOnly = false;
4988
- var coveredFiles = /* @__PURE__ */ new Set();
4989
- var describePattern = void 0;
4990
- var testPattern = void 0;
4991
- var currentTestFile = void 0;
4992
- var currentSourceMapConsumer = void 0;
4993
- var wrapperLineOffset = 0;
4994
- var TEST_MODULE_EXTENSIONS = [".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs", ".json"];
4995
- function resolveTestLoader(filePath) {
4996
- return /\.(?:ts|tsx|mts|cts)$/i.test(filePath) ? "ts" : "js";
4997
- }
4998
- function createTestTransformOptions(filePath, format, sourcemap) {
4999
- return {
5000
- loader: resolveTestLoader(filePath),
5001
- format,
5002
- sourcemap,
5003
- sourcefile: filePath,
5004
- target: "es2020",
5005
- tsconfigRaw: {
5006
- compilerOptions: {
5007
- jsx: "react",
5008
- jsxFactory: "h",
5009
- jsxFragmentFactory: "Fragment"
5010
- }
5011
- }
5012
- };
5013
- }
5014
- function resolveExistingTestModulePath(basePath) {
5015
- const nodePath = __require("path");
5016
- if (existsSync(basePath) && statSync(basePath).isFile()) {
5017
- return basePath;
5044
+ toBeTruthy() {
5045
+ this.assertCondition(!!this.actual, "Expected value to be truthy", false, void 0, new Error().stack);
5018
5046
  }
5019
- for (const extension of TEST_MODULE_EXTENSIONS) {
5020
- const candidatePath = `${basePath}${extension}`;
5021
- if (existsSync(candidatePath) && statSync(candidatePath).isFile()) {
5022
- return candidatePath;
5047
+ toBeFalsy() {
5048
+ this.assertCondition(!this.actual, "Expected value to be falsy", false, void 0, new Error().stack);
5049
+ }
5050
+ toBeNull() {
5051
+ this.assertCondition(this.actual === null, "Expected value to be null", false, void 0, new Error().stack);
5052
+ }
5053
+ toBeUndefined() {
5054
+ this.assertCondition(this.actual === void 0, "Expected value to be undefined", false, void 0, new Error().stack);
5055
+ }
5056
+ toBeDefined() {
5057
+ this.assertCondition(this.actual !== void 0, "Expected value to be defined", false, void 0, new Error().stack);
5058
+ }
5059
+ toBeGreaterThan(value) {
5060
+ const stack = new Error().stack;
5061
+ this.expected = value;
5062
+ this.assertCondition(typeof this.actual === "number" && this.actual > value, `Expected ${this.stringify(this.actual)} to be greater than ${value}`, true, String(value), stack);
5063
+ }
5064
+ toBeGreaterThanOrEqual(value) {
5065
+ const stack = new Error().stack;
5066
+ this.expected = value;
5067
+ this.assertCondition(typeof this.actual === "number" && this.actual >= value, `Expected ${this.stringify(this.actual)} to be greater than or equal to ${value}`, true, `${value}`, stack);
5068
+ }
5069
+ toBeLessThan(value) {
5070
+ const stack = new Error().stack;
5071
+ this.expected = value;
5072
+ this.assertCondition(typeof this.actual === "number" && this.actual < value, `Expected ${this.stringify(this.actual)} to be less than ${value}`, true, String(value), stack);
5073
+ }
5074
+ toBeLessThanOrEqual(value) {
5075
+ const stack = new Error().stack;
5076
+ this.expected = value;
5077
+ this.assertCondition(typeof this.actual === "number" && this.actual <= value, `Expected ${this.stringify(this.actual)} to be less than or equal to ${value}`, true, `${value}`, stack);
5078
+ }
5079
+ toContain(value) {
5080
+ const stack = new Error().stack;
5081
+ this.expected = value;
5082
+ if (typeof this.actual === "string") {
5083
+ this.assertCondition(this.actual.includes(value), `Expected "${this.actual}" to contain "${value}"`, false, void 0, stack);
5084
+ } else if (Array.isArray(this.actual)) {
5085
+ this.assertCondition(this.actual.some((item) => this.deepEqual(item, value)), `Expected array to contain ${this.stringify(value)}`, false, void 0, stack);
5086
+ } else {
5087
+ throw new Error(`toContain expects string or array, got ${typeof this.actual}`);
5023
5088
  }
5024
5089
  }
5025
- if (existsSync(basePath) && statSync(basePath).isDirectory()) {
5026
- const packageJsonPath = nodePath.join(basePath, "package.json");
5027
- if (existsSync(packageJsonPath) && statSync(packageJsonPath).isFile()) {
5028
- try {
5029
- const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
5030
- for (const candidateEntry of [packageJson.main, packageJson.module]) {
5031
- if (typeof candidateEntry !== "string" || candidateEntry.trim().length === 0) {
5032
- continue;
5033
- }
5034
- try {
5035
- return resolveExistingTestModulePath(nodePath.resolve(basePath, candidateEntry));
5036
- } catch {
5037
- continue;
5038
- }
5039
- }
5040
- } catch {
5090
+ toHaveLength(length) {
5091
+ const stack = new Error().stack;
5092
+ this.expected = length;
5093
+ const actualLength = this.actual?.length;
5094
+ this.assertCondition(actualLength === length, `Expected length to be ${length}, but got ${actualLength}`, false, void 0, stack);
5095
+ }
5096
+ toThrow(error) {
5097
+ if (this.isAsync) {
5098
+ return this.handleAsyncAssertion(error, () => {
5099
+ });
5100
+ }
5101
+ let threw = false;
5102
+ let thrownError = null;
5103
+ try {
5104
+ if (typeof this.actual === "function") {
5105
+ this.actual();
5041
5106
  }
5107
+ } catch (caughtError) {
5108
+ threw = true;
5109
+ thrownError = caughtError;
5042
5110
  }
5043
- for (const extension of TEST_MODULE_EXTENSIONS) {
5044
- const candidatePath = nodePath.join(basePath, `index${extension}`);
5045
- if (existsSync(candidatePath) && statSync(candidatePath).isFile()) {
5046
- return candidatePath;
5111
+ this.assertCondition(threw, "Expected function to throw an error");
5112
+ if (error) {
5113
+ if (typeof error === "string") {
5114
+ this.assertCondition(thrownError.message.includes(error), `Expected error message to include "${error}"`);
5115
+ } else if (error instanceof RegExp) {
5116
+ this.assertCondition(error.test(thrownError.message), `Expected error message to match ${error}`);
5047
5117
  }
5048
5118
  }
5049
5119
  }
5050
- return basePath;
5051
- }
5052
- function resolveTestModulePath(fromFilePath, specifier) {
5053
- if (!specifier.startsWith(".") && !specifier.startsWith("/")) {
5054
- return specifier;
5055
- }
5056
- const nodePath = __require("path");
5057
- const basePath = specifier.startsWith(".") ? nodePath.resolve(dirname(fromFilePath), specifier) : specifier;
5058
- return resolveExistingTestModulePath(basePath);
5059
- }
5060
- function shouldTranspileTestModule(filePath) {
5061
- return /\.(?:ts|tsx|mts|cts|js|jsx|mjs|cjs)$/i.test(filePath);
5062
- }
5063
- function createTestModuleRequire(fromFilePath, moduleCache) {
5064
- return (specifier) => {
5065
- if (specifier.startsWith("elit/") || specifier === "elit") {
5066
- return __require(specifier);
5067
- }
5068
- const resolvedPath = resolveTestModulePath(fromFilePath, specifier);
5069
- if (resolvedPath === specifier) {
5070
- return __require(specifier);
5120
+ toMatch(pattern) {
5121
+ this.expected = pattern;
5122
+ const text = String(this.actual);
5123
+ if (pattern instanceof RegExp) {
5124
+ this.assertCondition(pattern.test(text), `Expected "${text}" to match ${pattern}`);
5125
+ } else {
5126
+ this.assertCondition(text.includes(pattern), `Expected "${text}" to contain "${pattern}"`);
5071
5127
  }
5072
- if (!existsSync(resolvedPath) || !statSync(resolvedPath).isFile()) {
5073
- return __require(resolvedPath);
5128
+ }
5129
+ toBeInstanceOf(classType) {
5130
+ this.expected = classType;
5131
+ this.assertCondition(this.actual instanceof classType, `Expected value to be instance of ${classType.name}`);
5132
+ }
5133
+ toHaveProperty(path, value) {
5134
+ const keys = Array.isArray(path) ? path : path.split(".");
5135
+ let object = this.actual;
5136
+ for (const key of keys) {
5137
+ if (object == null || !Object.hasOwnProperty.call(object, key)) {
5138
+ throw new Error(`Expected object to have property "${path}"`);
5139
+ }
5140
+ object = object[key];
5074
5141
  }
5075
- if (!shouldTranspileTestModule(resolvedPath)) {
5076
- return __require(resolvedPath);
5142
+ if (value !== void 0) {
5143
+ this.assertCondition(this.deepEqual(object, value), `Expected property "${path}" to equal ${this.stringify(value)}`);
5077
5144
  }
5078
- return loadTranspiledTestModule(resolvedPath, moduleCache);
5079
- };
5080
- }
5081
- function loadTranspiledTestModule(modulePath, moduleCache) {
5082
- const cached = moduleCache.get(modulePath);
5083
- if (cached) {
5084
- return cached.exports;
5085
5145
  }
5086
- const source = readFileSync(modulePath, "utf-8");
5087
- let transpiled;
5088
- try {
5089
- transpiled = (0, import_esbuild.transformSync)(source, createTestTransformOptions(modulePath, "cjs", false));
5090
- } catch (error) {
5091
- throw new Error(`Failed to transpile test dependency ${modulePath}: ${error instanceof Error ? error.message : String(error)}`);
5146
+ toBeCalled() {
5147
+ this.assertCondition(this.actual._isMock && this.actual._calls.length > 0, "Expected mock function to have been called");
5092
5148
  }
5093
- const moduleRecord = { exports: {} };
5094
- const moduleObj = { exports: moduleRecord.exports };
5095
- moduleCache.set(modulePath, moduleRecord);
5096
- try {
5097
- const fn = new Function("module", "exports", "require", "__filename", "__dirname", transpiled.code);
5098
- const requireFn = createTestModuleRequire(modulePath, moduleCache);
5099
- fn(moduleObj, moduleObj.exports, requireFn, modulePath, dirname(modulePath));
5100
- } catch (error) {
5101
- throw new Error(`Failed to execute test dependency ${modulePath}: ${error instanceof Error ? error.message : String(error)}`);
5149
+ toBeCalledTimes(times) {
5150
+ this.assertCondition(this.actual._isMock && this.actual._calls.length === times, `Expected mock to be called ${times} times, but was called ${this.actual._calls?.length || 0} times`);
5102
5151
  }
5103
- moduleRecord.exports = moduleObj.exports;
5104
- if (!modulePath.includes(".test.") && !modulePath.includes(".spec.")) {
5105
- coveredFiles.add(modulePath);
5152
+ toBeCalledWith(...args) {
5153
+ this.assertCondition(this.actual._isMock && this.actual._calls.some((call) => this.deepEqual(call, args)), `Expected mock to be called with ${this.stringify(args)}`);
5106
5154
  }
5107
- return moduleRecord.exports;
5108
- }
5109
- async function transpileFile(filePath) {
5110
- const source = await readFile(filePath, "utf-8");
5111
- const result = (0, import_esbuild.transformSync)(source, createTestTransformOptions(filePath, "esm", "inline"));
5112
- let sourceMap;
5113
- const sourceMapMatch = result.code.match(/\/\/# sourceMappingURL=data:application\/json;base64,(.+)/);
5114
- if (sourceMapMatch) {
5115
- const base64 = sourceMapMatch[1];
5116
- const json = Buffer.from(base64, "base64").toString("utf-8");
5117
- sourceMap = JSON.parse(json);
5155
+ lastReturnedWith(value) {
5156
+ const lastResult = this.actual._results?.[this.actual._results.length - 1];
5157
+ this.assertCondition(lastResult && this.deepEqual(lastResult.value, value), `Expected last call to return ${this.stringify(value)}`);
5158
+ }
5159
+ deepEqual(left, right) {
5160
+ return JSON.stringify(left) === JSON.stringify(right);
5118
5161
  }
5119
- return { code: result.code, sourceMap };
5162
+ };
5163
+ function expect(actual) {
5164
+ return new Expect(actual);
5165
+ }
5166
+
5167
+ // src/test/runtime/hooks.ts
5168
+ var beforeAll = (fn) => runtimeState.beforeAllHooks.push(fn);
5169
+ var afterAll = (fn) => runtimeState.afterAllHooks.push(fn);
5170
+ var beforeEach = (fn) => runtimeState.beforeEachHooks.push(fn);
5171
+ var afterEach = (fn) => runtimeState.afterEachHooks.push(fn);
5172
+
5173
+ // src/test/runtime/mocks.ts
5174
+ function createMockFunction() {
5175
+ const mock = function(...args) {
5176
+ mock._calls.push(args);
5177
+ try {
5178
+ const result = mock._implementation ? mock._implementation(...args) : void 0;
5179
+ mock._results.push({ type: "return", value: result });
5180
+ return result;
5181
+ } catch (error) {
5182
+ mock._results.push({ type: "throw", value: error });
5183
+ throw error;
5184
+ }
5185
+ };
5186
+ mock._isMock = true;
5187
+ mock._calls = [];
5188
+ mock._results = [];
5189
+ mock._implementation = null;
5190
+ mock.mockImplementation = function(fn) {
5191
+ mock._implementation = fn;
5192
+ return mock;
5193
+ };
5194
+ mock.mockReturnValue = function(value) {
5195
+ mock._implementation = (() => value);
5196
+ return mock;
5197
+ };
5198
+ mock.mockResolvedValue = function(value) {
5199
+ mock._implementation = (() => Promise.resolve(value));
5200
+ return mock;
5201
+ };
5202
+ mock.mockRejectedValue = function(value) {
5203
+ mock._implementation = (() => Promise.reject(value));
5204
+ return mock;
5205
+ };
5206
+ mock.restore = function() {
5207
+ mock._calls = [];
5208
+ mock._results = [];
5209
+ mock._implementation = null;
5210
+ };
5211
+ mock.clear = function() {
5212
+ mock._calls = [];
5213
+ mock._results = [];
5214
+ };
5215
+ return mock;
5120
5216
  }
5217
+ var vi = {
5218
+ fn: () => createMockFunction(),
5219
+ spyOn: (obj, method) => {
5220
+ const original = obj[method];
5221
+ const mock = createMockFunction();
5222
+ mock.mockImplementation(original);
5223
+ obj[method] = mock;
5224
+ mock.restore = () => {
5225
+ obj[method] = original;
5226
+ };
5227
+ return mock;
5228
+ },
5229
+ clearAllMocks: () => {
5230
+ },
5231
+ restoreAllMocks: () => {
5232
+ }
5233
+ };
5234
+
5235
+ // src/test/runtime/test-api.ts
5121
5236
  function createTestFunction(defaultTimeout = 5e3) {
5122
5237
  const testFn = function(name, fn, timeout) {
5123
5238
  const test = {
5124
5239
  name,
5125
5240
  fn,
5126
- skip: currentSuite.skip,
5241
+ skip: runtimeState.currentSuite.skip,
5127
5242
  only: false,
5128
5243
  todo: false,
5129
5244
  timeout: timeout ?? defaultTimeout,
5130
- suite: currentSuite
5245
+ suite: runtimeState.currentSuite
5131
5246
  };
5132
- currentSuite.tests.push(test);
5247
+ runtimeState.currentSuite.tests.push(test);
5133
5248
  };
5134
5249
  testFn.skip = (name, fn, timeout) => {
5135
5250
  const test = {
@@ -5139,12 +5254,12 @@ error: ${text}`);
5139
5254
  only: false,
5140
5255
  todo: false,
5141
5256
  timeout: timeout ?? defaultTimeout,
5142
- suite: currentSuite
5257
+ suite: runtimeState.currentSuite
5143
5258
  };
5144
- currentSuite.tests.push(test);
5259
+ runtimeState.currentSuite.tests.push(test);
5145
5260
  };
5146
5261
  testFn.only = (name, fn, timeout) => {
5147
- hasOnly = true;
5262
+ runtimeState.hasOnly = true;
5148
5263
  const test = {
5149
5264
  name,
5150
5265
  fn,
@@ -5152,9 +5267,9 @@ error: ${text}`);
5152
5267
  only: true,
5153
5268
  todo: false,
5154
5269
  timeout: timeout ?? defaultTimeout,
5155
- suite: currentSuite
5270
+ suite: runtimeState.currentSuite
5156
5271
  };
5157
- currentSuite.tests.push(test);
5272
+ runtimeState.currentSuite.tests.push(test);
5158
5273
  };
5159
5274
  testFn.todo = (name, fn, timeout) => {
5160
5275
  const test = {
@@ -5164,15 +5279,15 @@ error: ${text}`);
5164
5279
  only: false,
5165
5280
  todo: true,
5166
5281
  timeout: timeout ?? defaultTimeout,
5167
- suite: currentSuite
5282
+ suite: runtimeState.currentSuite
5168
5283
  };
5169
- currentSuite.tests.push(test);
5284
+ runtimeState.currentSuite.tests.push(test);
5170
5285
  };
5171
5286
  return testFn;
5172
5287
  }
5173
5288
  function createDescribeFunction() {
5174
5289
  const describeFn = function(name, fn) {
5175
- const parent = currentSuite;
5290
+ const parent = runtimeState.currentSuite;
5176
5291
  const suite = {
5177
5292
  name,
5178
5293
  tests: [],
@@ -5182,12 +5297,12 @@ error: ${text}`);
5182
5297
  only: parent.only
5183
5298
  };
5184
5299
  parent.suites.push(suite);
5185
- currentSuite = suite;
5300
+ runtimeState.currentSuite = suite;
5186
5301
  fn();
5187
- currentSuite = parent;
5302
+ runtimeState.currentSuite = parent;
5188
5303
  };
5189
5304
  describeFn.skip = (name, fn) => {
5190
- const parent = currentSuite;
5305
+ const parent = runtimeState.currentSuite;
5191
5306
  const suite = {
5192
5307
  name,
5193
5308
  tests: [],
@@ -5197,13 +5312,13 @@ error: ${text}`);
5197
5312
  only: false
5198
5313
  };
5199
5314
  parent.suites.push(suite);
5200
- currentSuite = suite;
5315
+ runtimeState.currentSuite = suite;
5201
5316
  fn();
5202
- currentSuite = parent;
5317
+ runtimeState.currentSuite = parent;
5203
5318
  };
5204
5319
  describeFn.only = (name, fn) => {
5205
- hasOnly = true;
5206
- const parent = currentSuite;
5320
+ runtimeState.hasOnly = true;
5321
+ const parent = runtimeState.currentSuite;
5207
5322
  const suite = {
5208
5323
  name,
5209
5324
  tests: [],
@@ -5213,594 +5328,476 @@ error: ${text}`);
5213
5328
  only: true
5214
5329
  };
5215
5330
  parent.suites.push(suite);
5216
- currentSuite = suite;
5331
+ runtimeState.currentSuite = suite;
5217
5332
  fn();
5218
- currentSuite = parent;
5333
+ runtimeState.currentSuite = parent;
5219
5334
  };
5220
5335
  return describeFn;
5221
5336
  }
5222
- var Expect = class _Expect {
5223
- constructor(actual, isNot = false, isAsync = false) {
5224
- this.actual = actual;
5225
- this.isNot = isNot;
5226
- this.isAsync = isAsync;
5227
- this._not = null;
5228
- this._resolves = null;
5229
- this._rejects = null;
5337
+
5338
+ // src/test/runtime/globals.ts
5339
+ var globals = {
5340
+ describe: createDescribeFunction(),
5341
+ it: createTestFunction(5e3),
5342
+ test: createTestFunction(5e3),
5343
+ expect,
5344
+ beforeAll,
5345
+ afterAll,
5346
+ beforeEach,
5347
+ afterEach,
5348
+ vi
5349
+ };
5350
+ function setupGlobals() {
5351
+ global.describe = globals.describe;
5352
+ global.it = globals.it;
5353
+ global.test = globals.test;
5354
+ global.expect = globals.expect;
5355
+ global.beforeAll = globals.beforeAll;
5356
+ global.afterAll = globals.afterAll;
5357
+ global.beforeEach = globals.beforeEach;
5358
+ global.afterEach = globals.afterEach;
5359
+ global.vi = globals.vi;
5360
+ }
5361
+ function clearGlobals() {
5362
+ delete global.describe;
5363
+ delete global.it;
5364
+ delete global.test;
5365
+ delete global.expect;
5366
+ delete global.beforeAll;
5367
+ delete global.afterAll;
5368
+ delete global.beforeEach;
5369
+ delete global.afterEach;
5370
+ delete global.vi;
5371
+ }
5372
+
5373
+ // src/test/runtime/transpile.ts
5374
+ var import_esbuild = __toESM(require_main());
5375
+
5376
+ // src/server/path/platform.ts
5377
+ function getSeparator(isWin) {
5378
+ return isWin ? "\\" : "/";
5379
+ }
5380
+ function getCwd() {
5381
+ if (isNode || isBun) {
5382
+ return process.cwd();
5230
5383
  }
5231
- get not() {
5232
- if (!this._not) {
5233
- this._not = new _Expect(this.actual, !this.isNot, false);
5234
- }
5235
- return this._not;
5384
+ if (isDeno) {
5385
+ return Deno.cwd();
5236
5386
  }
5237
- get resolves() {
5238
- if (!this._resolves) {
5239
- this._resolves = new _Expect(this.actual, this.isNot, true);
5240
- }
5241
- return this._resolves;
5387
+ return "/";
5388
+ }
5389
+ var isWindows = (() => {
5390
+ if (isNode) {
5391
+ return process.platform === "win32";
5242
5392
  }
5243
- get rejects() {
5244
- if (!this._rejects) {
5245
- this._rejects = new _Expect(this.actual, this.isNot, true);
5393
+ if (isDeno) {
5394
+ return Deno.build.os === "windows";
5395
+ }
5396
+ return typeof process !== "undefined" && process.platform === "win32";
5397
+ })();
5398
+
5399
+ // src/server/path/operations.ts
5400
+ function findLastSeparator(path) {
5401
+ return Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
5402
+ }
5403
+ function isAbsolutePosix(path) {
5404
+ return path.length > 0 && path[0] === "/";
5405
+ }
5406
+ function isAbsoluteWin(path) {
5407
+ const len = path.length;
5408
+ if (len === 0) return false;
5409
+ const code = path.charCodeAt(0);
5410
+ if (code === 47 || code === 92) {
5411
+ return true;
5412
+ }
5413
+ if (code >= 65 && code <= 90 || code >= 97 && code <= 122) {
5414
+ if (len > 2 && path.charCodeAt(1) === 58) {
5415
+ const code2 = path.charCodeAt(2);
5416
+ if (code2 === 47 || code2 === 92) {
5417
+ return true;
5418
+ }
5246
5419
  }
5247
- return this._rejects;
5248
5420
  }
5249
- assertCondition(condition, message, showExpectedReceived = true, expectedDisplay, callerStack) {
5250
- if (this.isNot) {
5251
- condition = !condition;
5421
+ return false;
5422
+ }
5423
+ function normalizePath(path, isWin) {
5424
+ if (path.length === 0) return ".";
5425
+ const separator = getSeparator(isWin);
5426
+ const isAbsolute = isWin ? isAbsoluteWin(path) : isAbsolutePosix(path);
5427
+ const trailingSeparator = path[path.length - 1] === separator || isWin && path[path.length - 1] === "/";
5428
+ const normalized = path.replace(isWin ? /[\/\\]+/g : /\/+/g, separator);
5429
+ const parts = normalized.split(separator);
5430
+ const result = [];
5431
+ for (let index = 0; index < parts.length; index++) {
5432
+ const part = parts[index];
5433
+ if (part === "" || part === ".") {
5434
+ if (index === 0 && isAbsolute) result.push("");
5435
+ continue;
5252
5436
  }
5253
- if (!condition) {
5254
- let errorMsg = message;
5255
- if (showExpectedReceived) {
5256
- const expectedValue = expectedDisplay ?? this.stringify(this.expected ?? "truthy");
5257
- errorMsg += `
5258
- Expected: ${expectedValue}
5259
- Received: ${this.stringify(this.actual)}`;
5260
- }
5261
- const stack = callerStack || new Error().stack;
5262
- let lineNumber = void 0;
5263
- let codeSnippet = void 0;
5264
- let assertionMethod = void 0;
5265
- if (stack) {
5266
- const assertionMatch = stack.match(/at _Expect\.(\w+)/);
5267
- if (assertionMatch) {
5268
- assertionMethod = assertionMatch[1];
5269
- }
5270
- }
5271
- if (stack) {
5272
- const lines = stack.split("\n");
5273
- const stackFrames = [];
5274
- for (const line of lines) {
5275
- const match = line.match(/<anonymous>:([0-9]+):([0-9]+)/);
5276
- if (match) {
5277
- stackFrames.push({
5278
- line: parseInt(match[1], 10),
5279
- column: parseInt(match[2], 10)
5280
- });
5281
- }
5282
- }
5283
- const targetFrame = stackFrames.length > 1 ? stackFrames[1] : stackFrames[0];
5284
- if (targetFrame && currentSourceMapConsumer) {
5285
- try {
5286
- const transpiledLine = targetFrame.line - wrapperLineOffset;
5287
- const originalPosition = currentSourceMapConsumer.originalPositionFor({
5288
- line: transpiledLine,
5289
- column: targetFrame.column
5290
- });
5291
- if (originalPosition.line !== null) {
5292
- lineNumber = originalPosition.line;
5293
- if (currentTestFile) {
5294
- try {
5295
- let sourceCode = readFileSync(currentTestFile, "utf-8");
5296
- if (Buffer.isBuffer(sourceCode)) {
5297
- sourceCode = sourceCode.toString("utf-8");
5298
- }
5299
- const sourceLines = sourceCode.split("\n");
5300
- let targetPattern = ".toBe(";
5301
- if (assertionMethod === "toEqual") targetPattern = ".toEqual(";
5302
- else if (assertionMethod === "toStrictEqual") targetPattern = ".toStrictEqual(";
5303
- else if (assertionMethod === "toMatch") targetPattern = ".toMatch(";
5304
- else if (assertionMethod === "toContain") targetPattern = ".toContain(";
5305
- else if (assertionMethod === "toHaveLength") targetPattern = ".toHaveLength(";
5306
- else if (assertionMethod === "toBeDefined") targetPattern = ".toBeDefined(";
5307
- else if (assertionMethod === "toBeNull") targetPattern = ".toBeNull(";
5308
- else if (assertionMethod === "toBeUndefined") targetPattern = ".toBeUndefined(";
5309
- else if (assertionMethod === "toBeTruthy") targetPattern = ".toBeTruthy(";
5310
- else if (assertionMethod === "toBeFalsy") targetPattern = ".toBeFalsy(";
5311
- else if (assertionMethod === "toThrow") targetPattern = ".toThrow(";
5312
- else if (assertionMethod === "toBeGreaterThan") targetPattern = ".toBeGreaterThan(";
5313
- else if (assertionMethod === "toBeGreaterThanOrEqual") targetPattern = ".toBeGreaterThanOrEqual(";
5314
- else if (assertionMethod === "toBeLessThan") targetPattern = ".toBeLessThan(";
5315
- else if (assertionMethod === "toBeLessThanOrEqual") targetPattern = ".toBeLessThanOrEqual(";
5316
- if (lineNumber > 0 && lineNumber <= sourceLines.length) {
5317
- const mappedLine = sourceLines[lineNumber - 1];
5318
- const hasMatchingAssertion = mappedLine.includes(targetPattern);
5319
- if (!hasMatchingAssertion) {
5320
- for (let i = 1; i <= 3; i++) {
5321
- const searchLine = lineNumber - i;
5322
- if (searchLine > 0 && searchLine <= sourceLines.length) {
5323
- const testLine = sourceLines[searchLine - 1];
5324
- if (testLine.includes(targetPattern)) {
5325
- lineNumber = searchLine;
5326
- break;
5327
- }
5328
- }
5329
- }
5330
- }
5331
- }
5332
- } catch (e) {
5333
- }
5334
- }
5335
- } else {
5336
- const posWithoutColumn = currentSourceMapConsumer.originalPositionFor({
5337
- line: transpiledLine,
5338
- column: 0
5339
- });
5340
- if (posWithoutColumn.line !== null) {
5341
- lineNumber = posWithoutColumn.line;
5342
- } else {
5343
- const lineMappings = [];
5344
- currentSourceMapConsumer.eachMapping((mapping) => {
5345
- if (mapping.originalLine !== null) {
5346
- const distance = Math.abs(mapping.generatedLine - transpiledLine);
5347
- lineMappings.push({
5348
- line: mapping.originalLine,
5349
- distance
5350
- });
5351
- }
5352
- });
5353
- if (lineMappings.length > 0) {
5354
- lineMappings.sort((a, b) => a.distance - b.distance);
5355
- lineNumber = lineMappings[0].line;
5356
- }
5357
- }
5358
- }
5359
- } catch (e) {
5360
- }
5361
- }
5362
- if (currentTestFile && lineNumber) {
5363
- try {
5364
- let sourceCode = readFileSync(currentTestFile, "utf-8");
5365
- if (Buffer.isBuffer(sourceCode)) {
5366
- sourceCode = sourceCode.toString("utf-8");
5367
- }
5368
- const sourceLines = sourceCode.split("\n");
5369
- if (lineNumber > 0 && lineNumber <= sourceLines.length) {
5370
- const codeLine = sourceLines[lineNumber - 1];
5371
- if (codeLine) {
5372
- codeSnippet = codeLine.trim();
5373
- }
5374
- }
5375
- } catch (e) {
5376
- }
5437
+ if (part === "..") {
5438
+ if (result.length > 0 && result[result.length - 1] !== "..") {
5439
+ if (!(result.length === 1 && result[0] === "")) {
5440
+ result.pop();
5377
5441
  }
5442
+ } else if (!isAbsolute) {
5443
+ result.push("..");
5378
5444
  }
5379
- throw new AssertionError(errorMsg, currentTestFile, lineNumber, void 0, codeSnippet);
5445
+ } else {
5446
+ result.push(part);
5380
5447
  }
5381
5448
  }
5382
- stringify(value) {
5383
- if (value === void 0) return "undefined";
5384
- if (value === null) return "null";
5385
- if (typeof value === "string") return `"${value}"`;
5386
- if (typeof value === "number" || typeof value === "boolean") return String(value);
5387
- if (typeof value === "function") return "Function";
5388
- if (Array.isArray(value)) return `[${value.map((v) => this.stringify(v)).join(", ")}]`;
5389
- if (typeof value === "object") {
5390
- const keys = Object.keys(value);
5391
- if (keys.length === 0) return "{}";
5392
- return `{ ${keys.slice(0, 3).map((k) => `${k}: ${this.stringify(value[k])}`).join(", ")}${keys.length > 3 ? "..." : ""} }`;
5393
- }
5394
- return String(value);
5449
+ let finalPath = result.join(separator);
5450
+ if (finalPath.length === 0) {
5451
+ return isAbsolute ? separator : ".";
5395
5452
  }
5396
- async handleAsyncAssertion(value, assertion) {
5397
- try {
5398
- const resolvedValue = await this.actual;
5399
- if (this.isNot) {
5400
- throw new Error(`Promise resolved when it should have rejected`);
5401
- }
5402
- assertion(resolvedValue);
5403
- return Promise.resolve(resolvedValue);
5404
- } catch (error) {
5405
- if (this.isNot) {
5406
- return Promise.resolve(void 0);
5407
- }
5408
- if (typeof value === "string") {
5409
- this.assertCondition(
5410
- error.message?.includes(value),
5411
- `Expected error message to include "${value}"`
5412
- );
5413
- } else if (value instanceof RegExp) {
5414
- this.assertCondition(
5415
- value.test(error.message),
5416
- `Expected error message to match ${value}`
5417
- );
5453
+ if (trailingSeparator && finalPath[finalPath.length - 1] !== separator) {
5454
+ finalPath += separator;
5455
+ }
5456
+ return finalPath;
5457
+ }
5458
+ function joinPaths(paths, isWin) {
5459
+ if (paths.length === 0) return ".";
5460
+ const separator = getSeparator(isWin);
5461
+ let joined = "";
5462
+ for (let index = 0; index < paths.length; index++) {
5463
+ const path = paths[index];
5464
+ if (path && path.length > 0) {
5465
+ if (joined.length === 0) {
5466
+ joined = path;
5467
+ } else {
5468
+ joined += separator + path;
5418
5469
  }
5419
- return Promise.resolve(void 0);
5420
5470
  }
5421
5471
  }
5422
- toBe(value) {
5423
- const stack = new Error().stack;
5424
- if (this.isAsync) {
5425
- return this.handleAsyncAssertion(value, (actual) => {
5426
- this.expected = value;
5427
- this.assertCondition(actual === value, `Expected values to be strictly equal (using ===)`, false, void 0, stack);
5428
- if (typeof actual !== typeof value) {
5429
- throw new Error(`Types don't match: expected ${typeof value} but got ${typeof actual}`);
5430
- }
5431
- });
5432
- }
5433
- this.expected = value;
5434
- this.assertCondition(this.actual === value, `Expected values to be strictly equal (using ===)`, true, void 0, stack);
5435
- if (typeof this.actual !== typeof value) {
5436
- throw new Error(`Types don't match: expected ${typeof value} but got ${typeof this.actual}`);
5472
+ if (joined.length === 0) return ".";
5473
+ return normalizePath(joined, isWin);
5474
+ }
5475
+ function resolvePaths(paths, isWin) {
5476
+ const separator = getSeparator(isWin);
5477
+ let resolved = "";
5478
+ let absolute = false;
5479
+ for (let index = paths.length - 1; index >= 0 && !absolute; index--) {
5480
+ const path = paths[index];
5481
+ if (path && path.length > 0) {
5482
+ resolved = path + (resolved.length > 0 ? separator + resolved : "");
5483
+ absolute = isWin ? isAbsoluteWin(resolved) : isAbsolutePosix(resolved);
5437
5484
  }
5438
5485
  }
5439
- toEqual(value) {
5440
- const stack = new Error().stack;
5441
- this.expected = value;
5442
- const isEqual = (a, b) => {
5443
- if (a === b) return true;
5444
- if (a == null || b == null) return a === b;
5445
- if (typeof a !== typeof b) return false;
5446
- if (typeof a !== "object") return a === b;
5447
- if (Array.isArray(a) !== Array.isArray(b)) return false;
5448
- if (Array.isArray(a)) {
5449
- if (a.length !== b.length) return false;
5450
- return a.every((item, i) => isEqual(item, b[i]));
5451
- }
5452
- const keysA = Object.keys(a);
5453
- const keysB = Object.keys(b);
5454
- if (keysA.length !== keysB.length) return false;
5455
- return keysA.every((key) => isEqual(a[key], b[key]));
5456
- };
5457
- this.assertCondition(isEqual(this.actual, value), "Expected values to be deeply equal", false, void 0, stack);
5458
- }
5459
- toBeTruthy() {
5460
- const stack = new Error().stack;
5461
- this.assertCondition(!!this.actual, `Expected value to be truthy`, false, void 0, stack);
5462
- }
5463
- toBeFalsy() {
5464
- const stack = new Error().stack;
5465
- this.assertCondition(!this.actual, `Expected value to be falsy`, false, void 0, stack);
5466
- }
5467
- toBeNull() {
5468
- const stack = new Error().stack;
5469
- this.assertCondition(this.actual === null, `Expected value to be null`, false, void 0, stack);
5486
+ if (!absolute) {
5487
+ const cwd = getCwd();
5488
+ resolved = cwd + (resolved.length > 0 ? separator + resolved : "");
5470
5489
  }
5471
- toBeUndefined() {
5472
- const stack = new Error().stack;
5473
- this.assertCondition(this.actual === void 0, `Expected value to be undefined`, false, void 0, stack);
5490
+ return normalizePath(resolved, isWin);
5491
+ }
5492
+ function relativePath(from, to, isWin) {
5493
+ const resolvedFrom = resolvePaths([from], isWin);
5494
+ const resolvedTo = resolvePaths([to], isWin);
5495
+ if (resolvedFrom === resolvedTo) return "";
5496
+ const separator = getSeparator(isWin);
5497
+ const fromParts = resolvedFrom.split(separator).filter((part) => part.length > 0);
5498
+ const toParts = resolvedTo.split(separator).filter((part) => part.length > 0);
5499
+ const minLength = Math.min(fromParts.length, toParts.length);
5500
+ let commonLength = 0;
5501
+ for (let index = 0; index < minLength; index++) {
5502
+ if (fromParts[index] === toParts[index]) {
5503
+ commonLength++;
5504
+ } else {
5505
+ break;
5506
+ }
5474
5507
  }
5475
- toBeDefined() {
5476
- const stack = new Error().stack;
5477
- this.assertCondition(this.actual !== void 0, `Expected value to be defined`, false, void 0, stack);
5508
+ const result = [];
5509
+ const upCount = fromParts.length - commonLength;
5510
+ for (let index = 0; index < upCount; index++) {
5511
+ result.push("..");
5478
5512
  }
5479
- toBeGreaterThan(value) {
5480
- const stack = new Error().stack;
5481
- this.expected = value;
5482
- this.assertCondition(
5483
- typeof this.actual === "number" && this.actual > value,
5484
- `Expected ${this.stringify(this.actual)} to be greater than ${value}`,
5485
- true,
5486
- String(value),
5487
- stack
5488
- );
5513
+ for (let index = commonLength; index < toParts.length; index++) {
5514
+ result.push(toParts[index]);
5489
5515
  }
5490
- toBeGreaterThanOrEqual(value) {
5491
- const stack = new Error().stack;
5492
- this.expected = value;
5493
- this.assertCondition(
5494
- typeof this.actual === "number" && this.actual >= value,
5495
- `Expected ${this.stringify(this.actual)} to be greater than or equal to ${value}`,
5496
- true,
5497
- `${value}`,
5498
- stack
5499
- );
5516
+ return result.join(separator) || ".";
5517
+ }
5518
+ function getDirname(path, isWin) {
5519
+ if (path.length === 0) return ".";
5520
+ const separator = getSeparator(isWin);
5521
+ const normalized = normalizePath(path, isWin);
5522
+ const lastSeparatorIndex = normalized.lastIndexOf(separator);
5523
+ if (lastSeparatorIndex === -1) return ".";
5524
+ if (lastSeparatorIndex === 0) return separator;
5525
+ return normalized.slice(0, lastSeparatorIndex);
5526
+ }
5527
+ function getBasename(path, ext, isWin) {
5528
+ if (path.length === 0) return "";
5529
+ const lastSeparatorIndex = isWin ? findLastSeparator(path) : path.lastIndexOf("/");
5530
+ let base = lastSeparatorIndex === -1 ? path : path.slice(lastSeparatorIndex + 1);
5531
+ if (ext && base.endsWith(ext)) {
5532
+ base = base.slice(0, base.length - ext.length);
5500
5533
  }
5501
- toBeLessThan(value) {
5502
- const stack = new Error().stack;
5503
- this.expected = value;
5504
- this.assertCondition(
5505
- typeof this.actual === "number" && this.actual < value,
5506
- `Expected ${this.stringify(this.actual)} to be less than ${value}`,
5507
- true,
5508
- String(value),
5509
- stack
5510
- );
5534
+ return base;
5535
+ }
5536
+ function getExtname(path) {
5537
+ const lastDotIndex = path.lastIndexOf(".");
5538
+ const lastSeparatorIndex = findLastSeparator(path);
5539
+ if (lastDotIndex === -1 || lastDotIndex < lastSeparatorIndex || lastDotIndex === path.length - 1) {
5540
+ return "";
5511
5541
  }
5512
- toBeLessThanOrEqual(value) {
5513
- const stack = new Error().stack;
5514
- this.expected = value;
5515
- this.assertCondition(
5516
- typeof this.actual === "number" && this.actual <= value,
5517
- `Expected ${this.stringify(this.actual)} to be less than or equal to ${value}`,
5518
- true,
5519
- `${value}`,
5520
- stack
5521
- );
5542
+ return path.slice(lastDotIndex);
5543
+ }
5544
+ function parsePath(path, isWin) {
5545
+ let root = "";
5546
+ if (isWin) {
5547
+ if (path.length >= 2 && path[1] === ":") {
5548
+ root = path.slice(0, 2);
5549
+ if (path.length > 2 && (path[2] === "\\" || path[2] === "/")) {
5550
+ root += "\\";
5551
+ }
5552
+ } else if (path[0] === "\\" || path[0] === "/") {
5553
+ root = "\\";
5554
+ }
5555
+ } else if (path[0] === "/") {
5556
+ root = "/";
5522
5557
  }
5523
- toContain(value) {
5524
- const stack = new Error().stack;
5525
- this.expected = value;
5526
- if (typeof this.actual === "string") {
5527
- this.assertCondition(
5528
- this.actual.includes(value),
5529
- `Expected "${this.actual}" to contain "${value}"`,
5530
- false,
5531
- void 0,
5532
- stack
5533
- );
5534
- } else if (Array.isArray(this.actual)) {
5535
- this.assertCondition(
5536
- this.actual.some((item) => this.deepEqual(item, value)),
5537
- `Expected array to contain ${this.stringify(value)}`,
5538
- false,
5539
- void 0,
5540
- stack
5541
- );
5542
- } else {
5543
- throw new Error(`toContain expects string or array, got ${typeof this.actual}`);
5558
+ const dir = getDirname(path, isWin);
5559
+ const base = getBasename(path, void 0, isWin);
5560
+ const ext = getExtname(path);
5561
+ const name = ext ? base.slice(0, base.length - ext.length) : base;
5562
+ return { root, dir, base, ext, name };
5563
+ }
5564
+ function formatPath(pathObject, isWin) {
5565
+ const separator = getSeparator(isWin);
5566
+ const dir = pathObject.dir || pathObject.root || "";
5567
+ const base = pathObject.base || (pathObject.name || "") + (pathObject.ext || "");
5568
+ if (!dir) return base;
5569
+ if (dir === pathObject.root) return dir + base;
5570
+ return dir + separator + base;
5571
+ }
5572
+ function createPathOps(isWin) {
5573
+ return {
5574
+ sep: getSeparator(isWin),
5575
+ delimiter: isWin ? ";" : ":",
5576
+ normalize: (path) => normalizePath(path, isWin),
5577
+ join: (...paths) => joinPaths(paths, isWin),
5578
+ resolve: (...paths) => resolvePaths(paths, isWin),
5579
+ isAbsolute: (path) => isWin ? isAbsoluteWin(path) : isAbsolutePosix(path),
5580
+ relative: (from, to) => relativePath(from, to, isWin),
5581
+ dirname: (path) => getDirname(path, isWin),
5582
+ basename: (path, ext) => getBasename(path, ext, isWin),
5583
+ extname: (path) => getExtname(path),
5584
+ parse: (path) => parsePath(path, isWin),
5585
+ format: (pathObject) => formatPath(pathObject, isWin)
5586
+ };
5587
+ }
5588
+
5589
+ // src/server/path/index.ts
5590
+ var posix = createPathOps(false);
5591
+ var win32 = createPathOps(true);
5592
+ function dirname(path) {
5593
+ return getDirname(path, isWindows);
5594
+ }
5595
+
5596
+ // src/test/runtime/transpile.ts
5597
+ var TEST_MODULE_EXTENSIONS = [".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs", ".json"];
5598
+ function resolveTestLoader(filePath) {
5599
+ return /\.(?:ts|tsx|mts|cts)$/i.test(filePath) ? "ts" : "js";
5600
+ }
5601
+ function createTestTransformOptions(filePath, format, sourcemap) {
5602
+ return {
5603
+ loader: resolveTestLoader(filePath),
5604
+ format,
5605
+ sourcemap,
5606
+ sourcefile: filePath,
5607
+ target: "es2020",
5608
+ tsconfigRaw: {
5609
+ compilerOptions: {
5610
+ jsx: "react",
5611
+ jsxFactory: "h",
5612
+ jsxFragmentFactory: "Fragment"
5613
+ }
5544
5614
  }
5615
+ };
5616
+ }
5617
+ function extractInlineSourceMap(code) {
5618
+ const sourceMapMatch = code.match(/\/\/# sourceMappingURL=data:application\/json;base64,(.+)/);
5619
+ if (!sourceMapMatch) {
5620
+ return void 0;
5545
5621
  }
5546
- toHaveLength(length) {
5547
- const stack = new Error().stack;
5548
- this.expected = length;
5549
- const actualLength = this.actual?.length;
5550
- this.assertCondition(
5551
- actualLength === length,
5552
- `Expected length to be ${length}, but got ${actualLength}`,
5553
- false,
5554
- void 0,
5555
- stack
5556
- );
5622
+ const json = Buffer.from(sourceMapMatch[1], "base64").toString("utf-8");
5623
+ return JSON.parse(json);
5624
+ }
5625
+ function resolveExistingTestModulePath(basePath) {
5626
+ const nodePath = __require("path");
5627
+ if (existsSync(basePath) && statSync(basePath).isFile()) {
5628
+ return basePath;
5557
5629
  }
5558
- toThrow(error) {
5559
- if (this.isAsync) {
5560
- return this.handleAsyncAssertion(error, () => {
5561
- });
5630
+ for (const extension of TEST_MODULE_EXTENSIONS) {
5631
+ const candidatePath = `${basePath}${extension}`;
5632
+ if (existsSync(candidatePath) && statSync(candidatePath).isFile()) {
5633
+ return candidatePath;
5562
5634
  }
5563
- let threw = false;
5564
- let thrownError = null;
5565
- try {
5566
- if (typeof this.actual === "function") {
5567
- this.actual();
5635
+ }
5636
+ if (existsSync(basePath) && statSync(basePath).isDirectory()) {
5637
+ const packageJsonPath = nodePath.join(basePath, "package.json");
5638
+ if (existsSync(packageJsonPath) && statSync(packageJsonPath).isFile()) {
5639
+ try {
5640
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
5641
+ for (const candidateEntry of [packageJson.main, packageJson.module]) {
5642
+ if (typeof candidateEntry !== "string" || candidateEntry.trim().length === 0) {
5643
+ continue;
5644
+ }
5645
+ try {
5646
+ return resolveExistingTestModulePath(nodePath.resolve(basePath, candidateEntry));
5647
+ } catch {
5648
+ continue;
5649
+ }
5650
+ }
5651
+ } catch {
5568
5652
  }
5569
- } catch (e) {
5570
- threw = true;
5571
- thrownError = e;
5572
5653
  }
5573
- this.assertCondition(threw, `Expected function to throw an error`);
5574
- if (error) {
5575
- if (typeof error === "string") {
5576
- this.assertCondition(
5577
- thrownError.message.includes(error),
5578
- `Expected error message to include "${error}"`
5579
- );
5580
- } else if (error instanceof RegExp) {
5581
- this.assertCondition(
5582
- error.test(thrownError.message),
5583
- `Expected error message to match ${error}`
5584
- );
5654
+ for (const extension of TEST_MODULE_EXTENSIONS) {
5655
+ const candidatePath = nodePath.join(basePath, `index${extension}`);
5656
+ if (existsSync(candidatePath) && statSync(candidatePath).isFile()) {
5657
+ return candidatePath;
5585
5658
  }
5586
5659
  }
5587
5660
  }
5588
- toMatch(pattern) {
5589
- this.expected = pattern;
5590
- const str = String(this.actual);
5591
- if (pattern instanceof RegExp) {
5592
- this.assertCondition(
5593
- pattern.test(str),
5594
- `Expected "${str}" to match ${pattern}`
5595
- );
5596
- } else {
5597
- this.assertCondition(
5598
- str.includes(pattern),
5599
- `Expected "${str}" to contain "${pattern}"`
5600
- );
5601
- }
5602
- }
5603
- toBeInstanceOf(classType) {
5604
- this.expected = classType;
5605
- this.assertCondition(
5606
- this.actual instanceof classType,
5607
- `Expected value to be instance of ${classType.name}`
5608
- );
5661
+ return basePath;
5662
+ }
5663
+ function resolveTestModulePath(fromFilePath, specifier) {
5664
+ if (!specifier.startsWith(".") && !specifier.startsWith("/")) {
5665
+ return specifier;
5609
5666
  }
5610
- toHaveProperty(path, value) {
5611
- const keys = Array.isArray(path) ? path : path.split(".");
5612
- let obj = this.actual;
5613
- for (const key of keys) {
5614
- if (obj == null || !Object.hasOwnProperty.call(obj, key)) {
5615
- throw new Error(`Expected object to have property "${path}"`);
5616
- }
5617
- obj = obj[key];
5667
+ const nodePath = __require("path");
5668
+ const basePath = specifier.startsWith(".") ? nodePath.resolve(dirname(fromFilePath), specifier) : specifier;
5669
+ return resolveExistingTestModulePath(basePath);
5670
+ }
5671
+ function shouldTranspileTestModule(filePath) {
5672
+ return /\.(?:ts|tsx|mts|cts|js|jsx|mjs|cjs)$/i.test(filePath);
5673
+ }
5674
+ function createTestModuleRequire(fromFilePath, moduleCache) {
5675
+ return (specifier) => {
5676
+ if (specifier.startsWith("elit/") || specifier === "elit") {
5677
+ return __require(specifier);
5618
5678
  }
5619
- if (value !== void 0) {
5620
- this.assertCondition(
5621
- this.deepEqual(obj, value),
5622
- `Expected property "${path}" to equal ${this.stringify(value)}`
5623
- );
5679
+ const resolvedPath = resolveTestModulePath(fromFilePath, specifier);
5680
+ if (resolvedPath === specifier) {
5681
+ return __require(specifier);
5624
5682
  }
5683
+ if (!existsSync(resolvedPath) || !statSync(resolvedPath).isFile()) {
5684
+ return __require(resolvedPath);
5685
+ }
5686
+ if (!shouldTranspileTestModule(resolvedPath)) {
5687
+ return __require(resolvedPath);
5688
+ }
5689
+ return loadTranspiledTestModule(resolvedPath, moduleCache);
5690
+ };
5691
+ }
5692
+ function loadTranspiledTestModule(modulePath, moduleCache) {
5693
+ const cached = moduleCache.get(modulePath);
5694
+ if (cached) {
5695
+ return cached.exports;
5625
5696
  }
5626
- // Mock function matchers
5627
- toBeCalled() {
5628
- this.assertCondition(
5629
- this.actual._isMock && this.actual._calls.length > 0,
5630
- `Expected mock function to have been called`
5631
- );
5632
- }
5633
- toBeCalledTimes(times) {
5634
- this.assertCondition(
5635
- this.actual._isMock && this.actual._calls.length === times,
5636
- `Expected mock to be called ${times} times, but was called ${this.actual._calls?.length || 0} times`
5637
- );
5638
- }
5639
- toBeCalledWith(...args) {
5640
- this.assertCondition(this.actual._isMock && this.actual._calls.some((call) => this.deepEqual(call, args)), `Expected mock to be called with ${this.stringify(args)}`);
5697
+ const source = readFileSync(modulePath, "utf-8");
5698
+ let transpiled;
5699
+ try {
5700
+ transpiled = (0, import_esbuild.transformSync)(source, createTestTransformOptions(modulePath, "cjs", false));
5701
+ } catch (error) {
5702
+ throw new Error(`Failed to transpile test dependency ${modulePath}: ${error instanceof Error ? error.message : String(error)}`);
5641
5703
  }
5642
- lastReturnedWith(value) {
5643
- const lastResult = this.actual._results?.[this.actual._results.length - 1];
5644
- this.assertCondition(
5645
- lastResult && this.deepEqual(lastResult.value, value),
5646
- `Expected last call to return ${this.stringify(value)}`
5647
- );
5704
+ const moduleRecord = { exports: {} };
5705
+ const moduleObject = { exports: moduleRecord.exports };
5706
+ moduleCache.set(modulePath, moduleRecord);
5707
+ try {
5708
+ const fn = new Function("module", "exports", "require", "__filename", "__dirname", transpiled.code);
5709
+ const requireFn = createTestModuleRequire(modulePath, moduleCache);
5710
+ fn(moduleObject, moduleObject.exports, requireFn, modulePath, dirname(modulePath));
5711
+ } catch (error) {
5712
+ throw new Error(`Failed to execute test dependency ${modulePath}: ${error instanceof Error ? error.message : String(error)}`);
5648
5713
  }
5649
- deepEqual(a, b) {
5650
- return JSON.stringify(a) === JSON.stringify(b);
5714
+ moduleRecord.exports = moduleObject.exports;
5715
+ if (!modulePath.includes(".test.") && !modulePath.includes(".spec.")) {
5716
+ runtimeState.coveredFiles.add(modulePath);
5651
5717
  }
5652
- };
5653
- function expect(actual) {
5654
- return new Expect(actual);
5718
+ return moduleRecord.exports;
5655
5719
  }
5656
- function createMockFunction() {
5657
- const mock = function(...args) {
5658
- mock._calls.push(args);
5659
- try {
5660
- const result = mock._implementation ? mock._implementation(...args) : void 0;
5661
- mock._results.push({ type: "return", value: result });
5662
- return result;
5663
- } catch (error) {
5664
- mock._results.push({ type: "throw", value: error });
5665
- throw error;
5666
- }
5667
- };
5668
- mock._isMock = true;
5669
- mock._calls = [];
5670
- mock._results = [];
5671
- mock._implementation = null;
5672
- mock.mockImplementation = function(fn) {
5673
- mock._implementation = fn;
5674
- return mock;
5675
- };
5676
- mock.mockReturnValue = function(value) {
5677
- mock._implementation = (() => value);
5678
- return mock;
5679
- };
5680
- mock.mockResolvedValue = function(value) {
5681
- mock._implementation = (() => Promise.resolve(value));
5682
- return mock;
5683
- };
5684
- mock.mockRejectedValue = function(value) {
5685
- mock._implementation = (() => Promise.reject(value));
5686
- return mock;
5687
- };
5688
- mock.restore = function() {
5689
- mock._calls = [];
5690
- mock._results = [];
5691
- mock._implementation = null;
5692
- };
5693
- mock.clear = function() {
5694
- mock._calls = [];
5695
- mock._results = [];
5720
+ async function transpileFile(filePath) {
5721
+ const source = await readFile(filePath, "utf-8");
5722
+ const result = (0, import_esbuild.transformSync)(source, createTestTransformOptions(filePath, "esm", "inline"));
5723
+ return {
5724
+ code: result.code,
5725
+ sourceMap: extractInlineSourceMap(result.code)
5696
5726
  };
5697
- return mock;
5698
5727
  }
5699
- var vi = {
5700
- fn: () => createMockFunction(),
5701
- spyOn: (obj, method) => {
5702
- const original = obj[method];
5703
- const mock = createMockFunction();
5704
- mock.mockImplementation(original);
5705
- obj[method] = mock;
5706
- mock.restore = () => {
5707
- obj[method] = original;
5708
- };
5709
- return mock;
5710
- },
5711
- clearAllMocks: () => {
5712
- },
5713
- restoreAllMocks: () => {
5728
+
5729
+ // src/test/runtime/runner.ts
5730
+ var import_esbuild2 = __toESM(require_main());
5731
+ var import_source_map = __toESM(require_source_map());
5732
+ function escapeRegex(str) {
5733
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
5734
+ }
5735
+ function destroyCurrentSourceMapConsumer() {
5736
+ if (runtimeState.currentSourceMapConsumer) {
5737
+ runtimeState.currentSourceMapConsumer.destroy();
5738
+ runtimeState.currentSourceMapConsumer = void 0;
5714
5739
  }
5715
- };
5716
- var beforeAllHooks = [];
5717
- var afterAllHooks = [];
5718
- var beforeEachHooks = [];
5719
- var afterEachHooks = [];
5720
- var beforeAll = (fn) => beforeAllHooks.push(fn);
5721
- var afterAll = (fn) => afterAllHooks.push(fn);
5722
- var beforeEach = (fn) => beforeEachHooks.push(fn);
5723
- var afterEach = (fn) => afterEachHooks.push(fn);
5740
+ }
5741
+ function suiteOrDescendantMatches(suite) {
5742
+ if (!runtimeState.describePattern) {
5743
+ return true;
5744
+ }
5745
+ const regex = new RegExp(escapeRegex(runtimeState.describePattern), "i");
5746
+ if (regex.test(suite.name)) {
5747
+ return true;
5748
+ }
5749
+ for (const child of suite.suites) {
5750
+ if (suiteOrDescendantMatches(child)) {
5751
+ return true;
5752
+ }
5753
+ }
5754
+ return false;
5755
+ }
5724
5756
  async function runTests(options) {
5725
- const { files, timeout = 5e3, bail = false, describePattern: descPattern, testPattern: tPattern } = options;
5726
- describePattern = descPattern;
5727
- testPattern = tPattern;
5728
- testResults.length = 0;
5729
- hasOnly = false;
5757
+ const { files, timeout = 5e3, bail = false, describePattern, testPattern } = options;
5758
+ runtimeState.describePattern = describePattern;
5759
+ runtimeState.testPattern = testPattern;
5760
+ runtimeState.testResults.length = 0;
5730
5761
  for (const file of files) {
5731
- currentTestFile = file;
5762
+ resetSuiteState();
5763
+ resetHookState();
5764
+ resetSourceMapState();
5765
+ runtimeState.currentTestFile = file;
5732
5766
  try {
5733
5767
  const source = await readFile(file, "utf-8");
5734
5768
  const testFileDir = dirname(file);
5735
- const result = (0, import_esbuild.transformSync)(source, createTestTransformOptions(file, "cjs", "inline"));
5736
- let code = result.code;
5737
- const sourceMapMatch = code.match(/\/\/# sourceMappingURL=data:application\/json;base64,(.+)/);
5738
- if (sourceMapMatch) {
5739
- const base64 = sourceMapMatch[1];
5740
- const json = Buffer.from(base64, "base64").toString("utf-8");
5741
- const sourceMap = JSON.parse(json);
5742
- currentSourceMapConsumer = await new import_source_map.SourceMapConsumer(sourceMap);
5743
- } else {
5744
- currentSourceMapConsumer = void 0;
5745
- }
5746
- wrapperLineOffset = 0;
5769
+ const result = (0, import_esbuild2.transformSync)(source, createTestTransformOptions(file, "cjs", "inline"));
5770
+ const sourceMap = extractInlineSourceMap(result.code);
5771
+ runtimeState.currentSourceMapConsumer = sourceMap ? await new import_source_map.SourceMapConsumer(sourceMap) : void 0;
5772
+ runtimeState.wrapperLineOffset = 0;
5747
5773
  setupGlobals();
5748
5774
  const moduleCache = /* @__PURE__ */ new Map();
5749
5775
  const moduleRecord = { exports: {} };
5750
- const moduleObj = { exports: moduleRecord.exports };
5776
+ const moduleObject = { exports: moduleRecord.exports };
5751
5777
  moduleCache.set(file, moduleRecord);
5752
- const fn = new Function("module", "exports", "require", "__filename", "__dirname", code);
5778
+ const fn = new Function("module", "exports", "require", "__filename", "__dirname", result.code);
5753
5779
  const requireFn = createTestModuleRequire(file, moduleCache);
5754
- await fn(moduleObj, moduleObj.exports, requireFn, file, testFileDir);
5755
- await executeSuite(currentSuite, timeout, bail);
5756
- if (currentSourceMapConsumer) {
5757
- currentSourceMapConsumer.destroy();
5758
- currentSourceMapConsumer = void 0;
5759
- }
5760
- currentSuite = {
5761
- name: "root",
5762
- tests: [],
5763
- suites: [],
5764
- skip: false,
5765
- only: false
5766
- };
5767
- hasOnly = false;
5768
- beforeAllHooks = [];
5769
- afterAllHooks = [];
5770
- beforeEachHooks = [];
5771
- afterEachHooks = [];
5780
+ await fn(moduleObject, moduleObject.exports, requireFn, file, testFileDir);
5781
+ await executeSuite(runtimeState.currentSuite, timeout, bail);
5772
5782
  } catch (error) {
5773
- if (currentSourceMapConsumer) {
5774
- currentSourceMapConsumer.destroy();
5775
- currentSourceMapConsumer = void 0;
5776
- }
5777
5783
  console.error(`Error loading test file ${file}:`, error);
5784
+ } finally {
5785
+ destroyCurrentSourceMapConsumer();
5778
5786
  }
5779
5787
  }
5780
- const passed = testResults.filter((r) => r.status === "pass").length;
5781
- const failed = testResults.filter((r) => r.status === "fail").length;
5782
- const skipped = testResults.filter((r) => r.status === "skip").length;
5783
- const todo = testResults.filter((r) => r.status === "todo").length;
5784
- return { passed, failed, skipped, todo, results: testResults };
5788
+ const passed = runtimeState.testResults.filter((result) => result.status === "pass").length;
5789
+ const failed = runtimeState.testResults.filter((result) => result.status === "fail").length;
5790
+ const skipped = runtimeState.testResults.filter((result) => result.status === "skip").length;
5791
+ const todo = runtimeState.testResults.filter((result) => result.status === "todo").length;
5792
+ return { passed, failed, skipped, todo, results: runtimeState.testResults };
5785
5793
  }
5786
5794
  async function executeSuite(suite, timeout, bail, parentMatched = false) {
5787
5795
  let directMatch = false;
5788
- if (describePattern) {
5789
- const escapedPattern = escapeRegex(describePattern);
5790
- const regex = new RegExp(escapedPattern, "i");
5796
+ if (runtimeState.describePattern) {
5797
+ const regex = new RegExp(escapeRegex(runtimeState.describePattern), "i");
5791
5798
  directMatch = regex.test(suite.name);
5792
5799
  }
5793
- function suiteOrDescendantMatches(s) {
5794
- if (!describePattern) return true;
5795
- const escapedPattern = escapeRegex(describePattern);
5796
- const regex = new RegExp(escapedPattern, "i");
5797
- if (regex.test(s.name)) return true;
5798
- for (const child of s.suites) {
5799
- if (suiteOrDescendantMatches(child)) return true;
5800
- }
5801
- return false;
5802
- }
5803
- const shouldRunSuite = !describePattern || directMatch || parentMatched || suiteOrDescendantMatches(suite);
5800
+ const shouldRunSuite = !runtimeState.describePattern || directMatch || parentMatched || suiteOrDescendantMatches(suite);
5804
5801
  if (!shouldRunSuite) {
5805
5802
  return;
5806
5803
  }
@@ -5809,47 +5806,46 @@ error: ${text}`);
5809
5806
  await executeSuite(childSuite, timeout, bail, parentMatched || directMatch);
5810
5807
  }
5811
5808
  }
5812
- const shouldRunTests = !describePattern || directMatch || parentMatched || suite.name === "";
5809
+ const shouldRunTests = !runtimeState.describePattern || directMatch || parentMatched || suite.name === "";
5813
5810
  if (!shouldRunTests) {
5814
5811
  return;
5815
5812
  }
5816
- for (const hook of beforeAllHooks) {
5813
+ for (const hook of runtimeState.beforeAllHooks) {
5817
5814
  await hook();
5818
5815
  }
5819
5816
  for (const test of suite.tests) {
5820
- if (hasOnly && !test.only && !suite.only) {
5817
+ if (runtimeState.hasOnly && !test.only && !suite.only) {
5821
5818
  continue;
5822
5819
  }
5823
5820
  let testMatches = true;
5824
- if (testPattern) {
5825
- const escapedPattern = escapeRegex(testPattern);
5826
- const regex = new RegExp(escapedPattern, "i");
5821
+ if (runtimeState.testPattern) {
5822
+ const regex = new RegExp(escapeRegex(runtimeState.testPattern), "i");
5827
5823
  testMatches = regex.test(test.name);
5828
5824
  }
5829
5825
  if (!testMatches) {
5830
5826
  continue;
5831
5827
  }
5832
5828
  if (test.skip || suite.skip) {
5833
- testResults.push({
5829
+ runtimeState.testResults.push({
5834
5830
  name: test.name,
5835
5831
  status: "skip",
5836
5832
  duration: 0,
5837
5833
  suite: suite.name,
5838
- file: currentTestFile
5834
+ file: runtimeState.currentTestFile
5839
5835
  });
5840
5836
  continue;
5841
5837
  }
5842
5838
  if (test.todo) {
5843
- testResults.push({
5839
+ runtimeState.testResults.push({
5844
5840
  name: test.name,
5845
5841
  status: "todo",
5846
5842
  duration: 0,
5847
5843
  suite: suite.name,
5848
- file: currentTestFile
5844
+ file: runtimeState.currentTestFile
5849
5845
  });
5850
5846
  continue;
5851
5847
  }
5852
- for (const hook of beforeEachHooks) {
5848
+ for (const hook of runtimeState.beforeEachHooks) {
5853
5849
  await hook();
5854
5850
  }
5855
5851
  const startTime = Date.now();
@@ -5860,27 +5856,27 @@ error: ${text}`);
5860
5856
  (_, reject) => setTimeout(() => reject(new Error(`Test timed out after ${test.timeout}ms`)), test.timeout)
5861
5857
  )
5862
5858
  ]);
5863
- testResults.push({
5859
+ runtimeState.testResults.push({
5864
5860
  name: test.name,
5865
5861
  status: "pass",
5866
5862
  duration: Date.now() - startTime,
5867
5863
  suite: suite.name,
5868
- file: currentTestFile
5864
+ file: runtimeState.currentTestFile
5869
5865
  });
5870
5866
  } catch (error) {
5871
- let lineNumber = void 0;
5872
- let codeSnippet = void 0;
5867
+ let lineNumber;
5868
+ let codeSnippet;
5873
5869
  if (error instanceof AssertionError) {
5874
5870
  lineNumber = error.lineNumber;
5875
5871
  codeSnippet = error.codeSnippet;
5876
5872
  }
5877
- testResults.push({
5873
+ runtimeState.testResults.push({
5878
5874
  name: test.name,
5879
5875
  status: "fail",
5880
5876
  duration: Date.now() - startTime,
5881
5877
  error,
5882
5878
  suite: suite.name,
5883
- file: currentTestFile,
5879
+ file: runtimeState.currentTestFile,
5884
5880
  lineNumber,
5885
5881
  codeSnippet
5886
5882
  });
@@ -5888,51 +5884,12 @@ error: ${text}`);
5888
5884
  throw error;
5889
5885
  }
5890
5886
  }
5891
- for (const hook of afterEachHooks) {
5887
+ for (const hook of runtimeState.afterEachHooks) {
5892
5888
  await hook();
5893
5889
  }
5894
5890
  }
5895
- for (const hook of afterAllHooks) {
5891
+ for (const hook of runtimeState.afterAllHooks) {
5896
5892
  await hook();
5897
5893
  }
5898
5894
  }
5899
- var globals = {
5900
- describe: createDescribeFunction(),
5901
- it: createTestFunction(5e3),
5902
- test: createTestFunction(5e3),
5903
- expect,
5904
- beforeAll,
5905
- afterAll,
5906
- beforeEach,
5907
- afterEach,
5908
- vi
5909
- };
5910
- function setupGlobals() {
5911
- global.describe = globals.describe;
5912
- global.it = globals.it;
5913
- global.test = globals.test;
5914
- global.expect = globals.expect;
5915
- global.beforeAll = globals.beforeAll;
5916
- global.afterAll = globals.afterAll;
5917
- global.beforeEach = globals.beforeEach;
5918
- global.afterEach = globals.afterEach;
5919
- global.vi = globals.vi;
5920
- }
5921
- function clearGlobals() {
5922
- delete global.describe;
5923
- delete global.it;
5924
- delete global.test;
5925
- delete global.expect;
5926
- delete global.beforeAll;
5927
- delete global.afterAll;
5928
- delete global.beforeEach;
5929
- delete global.afterEach;
5930
- delete global.vi;
5931
- }
5932
- function getCoveredFiles() {
5933
- return coveredFiles;
5934
- }
5935
- function resetCoveredFiles() {
5936
- coveredFiles.clear();
5937
- }
5938
5895
  })();