elit 3.6.3 → 3.6.5

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.
@@ -34,7 +34,7 @@
34
34
 
35
35
  // node_modules/esbuild/lib/main.js
36
36
  var require_main = __commonJS({
37
- "node_modules/esbuild/lib/main.js"(exports, module2) {
37
+ "node_modules/esbuild/lib/main.js"(exports, module) {
38
38
  "use strict";
39
39
  var __defProp2 = Object.defineProperty;
40
40
  var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
@@ -69,7 +69,7 @@
69
69
  transformSync: () => transformSync2,
70
70
  version: () => version
71
71
  });
72
- module2.exports = __toCommonJS(node_exports);
72
+ module.exports = __toCommonJS(node_exports);
73
73
  function encodePacket(packet) {
74
74
  let visit = (value) => {
75
75
  if (value === null) {
@@ -2578,9 +2578,9 @@ error: ${text}`);
2578
2578
 
2579
2579
  // node_modules/source-map/lib/url.js
2580
2580
  var require_url = __commonJS({
2581
- "node_modules/source-map/lib/url.js"(exports, module2) {
2581
+ "node_modules/source-map/lib/url.js"(exports, module) {
2582
2582
  "use strict";
2583
- module2.exports = typeof URL === "function" ? URL : __require("url").URL;
2583
+ module.exports = typeof URL === "function" ? URL : __require("url").URL;
2584
2584
  }
2585
2585
  });
2586
2586
 
@@ -3363,11 +3363,11 @@ error: ${text}`);
3363
3363
 
3364
3364
  // node_modules/source-map/lib/read-wasm.js
3365
3365
  var require_read_wasm = __commonJS({
3366
- "node_modules/source-map/lib/read-wasm.js"(exports, module2) {
3366
+ "node_modules/source-map/lib/read-wasm.js"(exports, module) {
3367
3367
  "use strict";
3368
3368
  var fs2 = __require("fs");
3369
3369
  var path = __require("path");
3370
- module2.exports = function readWasm() {
3370
+ module.exports = function readWasm() {
3371
3371
  return new Promise((resolve, reject) => {
3372
3372
  const wasmPath = path.join(__dirname, "mappings.wasm");
3373
3373
  fs2.readFile(wasmPath, null, (error, data) => {
@@ -3379,7 +3379,7 @@ error: ${text}`);
3379
3379
  });
3380
3380
  });
3381
3381
  };
3382
- module2.exports.initialize = (_) => {
3382
+ module.exports.initialize = (_) => {
3383
3383
  console.debug(
3384
3384
  "SourceMapConsumer.initialize is a no-op when running in node.js"
3385
3385
  );
@@ -3389,7 +3389,7 @@ error: ${text}`);
3389
3389
 
3390
3390
  // node_modules/source-map/lib/wasm.js
3391
3391
  var require_wasm = __commonJS({
3392
- "node_modules/source-map/lib/wasm.js"(exports, module2) {
3392
+ "node_modules/source-map/lib/wasm.js"(exports, module) {
3393
3393
  "use strict";
3394
3394
  var readWasm = require_read_wasm();
3395
3395
  function Mapping() {
@@ -3402,7 +3402,7 @@ error: ${text}`);
3402
3402
  this.name = null;
3403
3403
  }
3404
3404
  var cachedWasm = null;
3405
- module2.exports = function wasm() {
3405
+ module.exports = function wasm() {
3406
3406
  if (cachedWasm) {
3407
3407
  return cachedWasm;
3408
3408
  }
@@ -4698,6 +4698,52 @@ error: ${text}`);
4698
4698
  }
4699
4699
  throw new Error("Unsupported runtime");
4700
4700
  }
4701
+ function existsSync(path) {
4702
+ try {
4703
+ statSync(path);
4704
+ return true;
4705
+ } catch {
4706
+ return false;
4707
+ }
4708
+ }
4709
+ function statSync(path) {
4710
+ if (isNode || isBun) {
4711
+ return fs.statSync(path);
4712
+ } else if (isDeno) {
4713
+ const info = Deno.statSync(path);
4714
+ return createStatsFromDenoFileInfo(info);
4715
+ }
4716
+ throw new Error("Unsupported runtime");
4717
+ }
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
+ }
4701
4747
 
4702
4748
  // src/path.ts
4703
4749
  function getSeparator(isWin) {
@@ -4945,12 +4991,16 @@ error: ${text}`);
4945
4991
  var currentTestFile = void 0;
4946
4992
  var currentSourceMapConsumer = void 0;
4947
4993
  var wrapperLineOffset = 0;
4948
- async function transpileFile(filePath) {
4949
- const source = await readFile(filePath, "utf-8");
4950
- const result = (0, import_esbuild.transformSync)(source, {
4951
- loader: filePath.endsWith(".ts") || filePath.endsWith(".tsx") ? "ts" : "js",
4952
- format: "esm",
4953
- sourcemap: "inline",
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,
4954
5004
  target: "es2020",
4955
5005
  tsconfigRaw: {
4956
5006
  compilerOptions: {
@@ -4959,7 +5009,106 @@ error: ${text}`);
4959
5009
  jsxFragmentFactory: "Fragment"
4960
5010
  }
4961
5011
  }
4962
- });
5012
+ };
5013
+ }
5014
+ function resolveExistingTestModulePath(basePath) {
5015
+ const nodePath = __require("path");
5016
+ if (existsSync(basePath) && statSync(basePath).isFile()) {
5017
+ return basePath;
5018
+ }
5019
+ for (const extension of TEST_MODULE_EXTENSIONS) {
5020
+ const candidatePath = `${basePath}${extension}`;
5021
+ if (existsSync(candidatePath) && statSync(candidatePath).isFile()) {
5022
+ return candidatePath;
5023
+ }
5024
+ }
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 {
5041
+ }
5042
+ }
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;
5047
+ }
5048
+ }
5049
+ }
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);
5071
+ }
5072
+ if (!existsSync(resolvedPath) || !statSync(resolvedPath).isFile()) {
5073
+ return __require(resolvedPath);
5074
+ }
5075
+ if (!shouldTranspileTestModule(resolvedPath)) {
5076
+ return __require(resolvedPath);
5077
+ }
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
+ }
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)}`);
5092
+ }
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)}`);
5102
+ }
5103
+ moduleRecord.exports = moduleObj.exports;
5104
+ if (!modulePath.includes(".test.") && !modulePath.includes(".spec.")) {
5105
+ coveredFiles.add(modulePath);
5106
+ }
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"));
4963
5112
  let sourceMap;
4964
5113
  const sourceMapMatch = result.code.match(/\/\/# sourceMappingURL=data:application\/json;base64,(.+)/);
4965
5114
  if (sourceMapMatch) {
@@ -4971,7 +5120,7 @@ error: ${text}`);
4971
5120
  }
4972
5121
  function createTestFunction(defaultTimeout = 5e3) {
4973
5122
  const testFn = function(name, fn, timeout) {
4974
- const test2 = {
5123
+ const test = {
4975
5124
  name,
4976
5125
  fn,
4977
5126
  skip: currentSuite.skip,
@@ -4980,10 +5129,10 @@ error: ${text}`);
4980
5129
  timeout: timeout ?? defaultTimeout,
4981
5130
  suite: currentSuite
4982
5131
  };
4983
- currentSuite.tests.push(test2);
5132
+ currentSuite.tests.push(test);
4984
5133
  };
4985
5134
  testFn.skip = (name, fn, timeout) => {
4986
- const test2 = {
5135
+ const test = {
4987
5136
  name,
4988
5137
  fn,
4989
5138
  skip: true,
@@ -4992,11 +5141,11 @@ error: ${text}`);
4992
5141
  timeout: timeout ?? defaultTimeout,
4993
5142
  suite: currentSuite
4994
5143
  };
4995
- currentSuite.tests.push(test2);
5144
+ currentSuite.tests.push(test);
4996
5145
  };
4997
5146
  testFn.only = (name, fn, timeout) => {
4998
5147
  hasOnly = true;
4999
- const test2 = {
5148
+ const test = {
5000
5149
  name,
5001
5150
  fn,
5002
5151
  skip: false,
@@ -5005,10 +5154,10 @@ error: ${text}`);
5005
5154
  timeout: timeout ?? defaultTimeout,
5006
5155
  suite: currentSuite
5007
5156
  };
5008
- currentSuite.tests.push(test2);
5157
+ currentSuite.tests.push(test);
5009
5158
  };
5010
5159
  testFn.todo = (name, fn, timeout) => {
5011
- const test2 = {
5160
+ const test = {
5012
5161
  name,
5013
5162
  fn,
5014
5163
  skip: false,
@@ -5017,7 +5166,7 @@ error: ${text}`);
5017
5166
  timeout: timeout ?? defaultTimeout,
5018
5167
  suite: currentSuite
5019
5168
  };
5020
- currentSuite.tests.push(test2);
5169
+ currentSuite.tests.push(test);
5021
5170
  };
5022
5171
  return testFn;
5023
5172
  }
@@ -5583,29 +5732,7 @@ error: ${text}`);
5583
5732
  try {
5584
5733
  const source = await readFile(file, "utf-8");
5585
5734
  const testFileDir = dirname(file);
5586
- const importRegex = /import\s+{\s*([^}]+)\s*}\s+from\s+['"]([^'"]+)['"]/g;
5587
- const imports = {};
5588
- let importIndex = 0;
5589
- let codeWithoutImports = source.replace(importRegex, (_, named, path) => {
5590
- const varName = `__import_${importIndex++}`;
5591
- const trimmedNamed = named.trim();
5592
- imports[varName] = { path, named: trimmedNamed };
5593
- return `// ${trimmedNamed} import injected later
5594
- `;
5595
- });
5596
- const result = (0, import_esbuild.transformSync)(codeWithoutImports, {
5597
- loader: file.endsWith(".ts") || file.endsWith(".tsx") ? "ts" : "js",
5598
- format: "iife",
5599
- sourcemap: "inline",
5600
- target: "es2020",
5601
- tsconfigRaw: {
5602
- compilerOptions: {
5603
- jsx: "react",
5604
- jsxFactory: "h",
5605
- jsxFragmentFactory: "Fragment"
5606
- }
5607
- }
5608
- });
5735
+ const result = (0, import_esbuild.transformSync)(source, createTestTransformOptions(file, "cjs", "inline"));
5609
5736
  let code = result.code;
5610
5737
  const sourceMapMatch = code.match(/\/\/# sourceMappingURL=data:application\/json;base64,(.+)/);
5611
5738
  if (sourceMapMatch) {
@@ -5616,99 +5743,15 @@ error: ${text}`);
5616
5743
  } else {
5617
5744
  currentSourceMapConsumer = void 0;
5618
5745
  }
5619
- const importedValues = {};
5620
- const importParamNames = [];
5621
- const importAssignments = [];
5622
- if (Object.keys(imports).length > 0) {
5623
- for (const [, { path, named }] of Object.entries(imports)) {
5624
- let resolvedPath = path;
5625
- if (path.startsWith(".")) {
5626
- const nodePath = __require("path");
5627
- resolvedPath = nodePath.resolve(testFileDir, path);
5628
- }
5629
- if (!resolvedPath.endsWith(".ts") && !resolvedPath.endsWith(".js") && !resolvedPath.endsWith(".mjs") && !resolvedPath.endsWith(".cjs")) {
5630
- resolvedPath += ".ts";
5631
- }
5632
- if (resolvedPath.endsWith(".ts")) {
5633
- try {
5634
- const importSource = await readFile(resolvedPath, "utf-8");
5635
- const transpiled = (0, import_esbuild.transformSync)(importSource, {
5636
- loader: "ts",
5637
- format: "cjs",
5638
- target: "es2020",
5639
- tsconfigRaw: {
5640
- compilerOptions: {
5641
- jsx: "react",
5642
- jsxFactory: "h",
5643
- jsxFragmentFactory: "Fragment"
5644
- }
5645
- }
5646
- });
5647
- const moduleExports = {};
5648
- const moduleObj = { exports: moduleExports };
5649
- const fn2 = new Function("module", "exports", "require", "__filename", "__dirname", transpiled.code);
5650
- const requireFn = (id) => {
5651
- if (id.startsWith("elit/") || id === "elit") {
5652
- return __require(id);
5653
- }
5654
- if (id.startsWith(".")) {
5655
- const nodePath = __require("path");
5656
- const absPath = nodePath.resolve(dirname(resolvedPath), id);
5657
- return __require(absPath);
5658
- }
5659
- return __require(id);
5660
- };
5661
- fn2(moduleObj, moduleExports, requireFn, resolvedPath, dirname(resolvedPath));
5662
- if (!resolvedPath.includes(".test.") && !resolvedPath.includes(".spec.")) {
5663
- coveredFiles.add(resolvedPath);
5664
- }
5665
- let exportedValue = moduleObj.exports[named];
5666
- if (exportedValue === void 0 && moduleObj.exports.default) {
5667
- exportedValue = moduleObj.exports.default[named];
5668
- }
5669
- if (exportedValue === void 0 && typeof moduleObj.exports === "object") {
5670
- exportedValue = moduleObj.exports[named];
5671
- }
5672
- const paramKey = `__import_${Math.random().toString(36).substring(2, 11)}`;
5673
- importedValues[paramKey] = exportedValue;
5674
- importParamNames.push(paramKey);
5675
- importAssignments.push(`const ${named} = ${paramKey};`);
5676
- } catch (err) {
5677
- const paramKey = `__import_${Math.random().toString(36).substring(2, 11)}`;
5678
- importedValues[paramKey] = null;
5679
- importParamNames.push(paramKey);
5680
- importAssignments.push(`const ${named} = ${paramKey}; /* Error importing ${resolvedPath}: ${err} */`);
5681
- }
5682
- } else {
5683
- const requiredModule = __require(resolvedPath);
5684
- const exportedValue = requiredModule[named];
5685
- const paramKey = `__import_${Math.random().toString(36).substring(2, 11)}`;
5686
- importedValues[paramKey] = exportedValue;
5687
- importParamNames.push(paramKey);
5688
- importAssignments.push(`const ${named} = ${paramKey};`);
5689
- }
5690
- }
5691
- }
5692
- let preamble = "";
5693
- if (Object.keys(imports).length > 0) {
5694
- const iifeStartMatch = code.match(/^(\s*(?:var\s+\w+\s*=\s*)?\(\(\)\s*=>\s*\{\n)/);
5695
- if (iifeStartMatch) {
5696
- const iifePrefix = iifeStartMatch[1];
5697
- const assignments = `${importAssignments.join("\n")}
5698
- `;
5699
- preamble = iifePrefix;
5700
- code = iifePrefix + assignments + code.slice(iifeStartMatch[1].length);
5701
- } else {
5702
- preamble = importAssignments.join("\n") + "\n";
5703
- code = preamble + code;
5704
- }
5705
- }
5706
- wrapperLineOffset = preamble.split("\n").length;
5746
+ wrapperLineOffset = 0;
5707
5747
  setupGlobals();
5708
- const allParams = ["describe", "it", "test", "expect", "beforeAll", "afterAll", "beforeEach", "afterEach", "vi", "require", "module", "__filename", "__dirname", ...importParamNames];
5709
- const allArgs = [describe, it, test, expect, beforeAll, afterAll, beforeEach, afterEach, vi, __require, module, file, testFileDir, ...importParamNames.map((p) => importedValues[p])];
5710
- const fn = new Function(...allParams, code);
5711
- await fn(...allArgs);
5748
+ const moduleCache = /* @__PURE__ */ new Map();
5749
+ const moduleRecord = { exports: {} };
5750
+ const moduleObj = { exports: moduleRecord.exports };
5751
+ moduleCache.set(file, moduleRecord);
5752
+ const fn = new Function("module", "exports", "require", "__filename", "__dirname", code);
5753
+ const requireFn = createTestModuleRequire(file, moduleCache);
5754
+ await fn(moduleObj, moduleObj.exports, requireFn, file, testFileDir);
5712
5755
  await executeSuite(currentSuite, timeout, bail);
5713
5756
  if (currentSourceMapConsumer) {
5714
5757
  currentSourceMapConsumer.destroy();
@@ -5773,22 +5816,22 @@ error: ${text}`);
5773
5816
  for (const hook of beforeAllHooks) {
5774
5817
  await hook();
5775
5818
  }
5776
- for (const test2 of suite.tests) {
5777
- if (hasOnly && !test2.only && !suite.only) {
5819
+ for (const test of suite.tests) {
5820
+ if (hasOnly && !test.only && !suite.only) {
5778
5821
  continue;
5779
5822
  }
5780
5823
  let testMatches = true;
5781
5824
  if (testPattern) {
5782
5825
  const escapedPattern = escapeRegex(testPattern);
5783
5826
  const regex = new RegExp(escapedPattern, "i");
5784
- testMatches = regex.test(test2.name);
5827
+ testMatches = regex.test(test.name);
5785
5828
  }
5786
5829
  if (!testMatches) {
5787
5830
  continue;
5788
5831
  }
5789
- if (test2.skip || suite.skip) {
5832
+ if (test.skip || suite.skip) {
5790
5833
  testResults.push({
5791
- name: test2.name,
5834
+ name: test.name,
5792
5835
  status: "skip",
5793
5836
  duration: 0,
5794
5837
  suite: suite.name,
@@ -5796,9 +5839,9 @@ error: ${text}`);
5796
5839
  });
5797
5840
  continue;
5798
5841
  }
5799
- if (test2.todo) {
5842
+ if (test.todo) {
5800
5843
  testResults.push({
5801
- name: test2.name,
5844
+ name: test.name,
5802
5845
  status: "todo",
5803
5846
  duration: 0,
5804
5847
  suite: suite.name,
@@ -5812,13 +5855,13 @@ error: ${text}`);
5812
5855
  const startTime = Date.now();
5813
5856
  try {
5814
5857
  await Promise.race([
5815
- test2.fn(),
5858
+ test.fn(),
5816
5859
  new Promise(
5817
- (_, reject) => setTimeout(() => reject(new Error(`Test timed out after ${test2.timeout}ms`)), test2.timeout)
5860
+ (_, reject) => setTimeout(() => reject(new Error(`Test timed out after ${test.timeout}ms`)), test.timeout)
5818
5861
  )
5819
5862
  ]);
5820
5863
  testResults.push({
5821
- name: test2.name,
5864
+ name: test.name,
5822
5865
  status: "pass",
5823
5866
  duration: Date.now() - startTime,
5824
5867
  suite: suite.name,
@@ -5832,7 +5875,7 @@ error: ${text}`);
5832
5875
  codeSnippet = error.codeSnippet;
5833
5876
  }
5834
5877
  testResults.push({
5835
- name: test2.name,
5878
+ name: test.name,
5836
5879
  status: "fail",
5837
5880
  duration: Date.now() - startTime,
5838
5881
  error,