@everyonesoftware/common 8.0.0 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,7 +9,7 @@ import {
9
9
  TestRunner,
10
10
  TestSkip,
11
11
  test
12
- } from "./chunk-FEQPKLDH.js";
12
+ } from "./chunk-HMQKVFIP.js";
13
13
  import "./chunk-OYMWB5SX.js";
14
14
  export {
15
15
  AssertTest,
package/outputs/tests.cjs CHANGED
@@ -8656,56 +8656,51 @@ var BasicTestError = class _BasicTestError {
8656
8656
  }
8657
8657
  return result;
8658
8658
  }
8659
+ static getStackFrameLineMatch(line) {
8660
+ return line.match(/^(\s*)at (.*) \((.+)\)$/) ?? line.match(/^(\s*)at (.+)$/);
8661
+ }
8662
+ static normalizePath(path2) {
8663
+ return path2.replace(/\\/g, "/");
8664
+ }
8665
+ static getStackFrameAbsolutePath(stackFrameLocation) {
8666
+ let result = _BasicTestError.normalizePath(stackFrameLocation);
8667
+ if (result.startsWith("file:///")) {
8668
+ result = _BasicTestError.normalizePath((0, import_url.fileURLToPath)(result));
8669
+ } else if (!/^[A-Za-z]:[\\/]/.test(result) && !result.startsWith("/")) {
8670
+ result = void 0;
8671
+ }
8672
+ return result;
8673
+ }
8659
8674
  static removeNonProjectPaths(errorString, currentFolderPath) {
8660
- currentFolderPath = currentFolderPath.replaceAll("\\", "/");
8675
+ currentFolderPath = _BasicTestError.normalizePath(currentFolderPath);
8661
8676
  return errorString.split("\n").filter((line) => {
8662
- let keepLine = false;
8663
- const trimmedLine = line.trim();
8664
- const match = trimmedLine.match(/^at .* \((.+)\)$/) ?? trimmedLine.match(/^at (.+)$/);
8665
- if (!match) {
8666
- keepLine = true;
8667
- } else {
8668
- const location = match[1];
8669
- try {
8670
- const filePath = import_path.default.resolve((0, import_url.fileURLToPath)(location)).replaceAll("\\", "/");
8671
- keepLine = filePath.startsWith(currentFolderPath);
8672
- } catch {
8673
- }
8677
+ let keepLine = true;
8678
+ const stackFrameLineMatch = _BasicTestError.getStackFrameLineMatch(line);
8679
+ if (stackFrameLineMatch) {
8680
+ const hasFunctionName = stackFrameLineMatch.length === 4;
8681
+ const location = hasFunctionName ? stackFrameLineMatch[3] : stackFrameLineMatch[2];
8682
+ const filePath = _BasicTestError.getStackFrameAbsolutePath(location);
8683
+ keepLine = !!filePath && filePath.startsWith(currentFolderPath) && !filePath.includes("/node_modules/");
8674
8684
  }
8675
8685
  return keepLine;
8676
8686
  }).join("\n");
8677
8687
  }
8678
8688
  static makeFilePathsRelative(errorString, currentFolderPath) {
8679
8689
  return errorString.split("\n").map((line) => {
8680
- const match = line.match(/^(\s*)at (.+?) \((.+)\)$/) ?? line.match(/^(\s*)at (.+)$/);
8681
- if (match) {
8682
- const hasFunctionName = match.length === 4;
8683
- const indentation = match[1];
8684
- const functionName = hasFunctionName ? match[2] : void 0;
8685
- const location = hasFunctionName ? match[3] : match[2];
8690
+ const stackFrameLineMatch = _BasicTestError.getStackFrameLineMatch(line);
8691
+ if (stackFrameLineMatch) {
8692
+ const hasFunctionName = stackFrameLineMatch.length === 4;
8693
+ const indentation = stackFrameLineMatch[1];
8694
+ const functionName = hasFunctionName ? stackFrameLineMatch[2] : void 0;
8695
+ const location = hasFunctionName ? stackFrameLineMatch[3] : stackFrameLineMatch[2];
8686
8696
  let relativeLocation = location;
8687
- try {
8688
- const pathMatch = location.match(/^(.*?):(\d+):(\d+)$/);
8689
- if (pathMatch) {
8690
- const fullPath = pathMatch[1];
8691
- const lineNumber = pathMatch[2];
8692
- const columnNumber = pathMatch[3];
8693
- let absolutePath;
8694
- if (fullPath.startsWith("file:///")) {
8695
- absolutePath = (0, import_url.fileURLToPath)(fullPath);
8696
- } else if (/^[A-Za-z]:[\\/]/.test(fullPath) || fullPath.startsWith("/")) {
8697
- absolutePath = fullPath;
8698
- }
8699
- if (absolutePath) {
8700
- let relativePath = import_path.default.relative(
8701
- currentFolderPath,
8702
- absolutePath
8703
- );
8704
- relativePath = relativePath.replace(/\\/g, "/");
8705
- relativeLocation = `${relativePath}:${lineNumber}:${columnNumber}`;
8706
- }
8697
+ const pathMatch = location.match(/^(.*?):(\d+):(\d+)$/);
8698
+ if (pathMatch) {
8699
+ const absolutePath = _BasicTestError.getStackFrameAbsolutePath(location);
8700
+ if (absolutePath) {
8701
+ const relativePath = import_path.default.relative(currentFolderPath, absolutePath);
8702
+ relativeLocation = _BasicTestError.normalizePath(relativePath);
8707
8703
  }
8708
- } catch {
8709
8704
  }
8710
8705
  if (relativeLocation !== location) {
8711
8706
  if (functionName) {
@@ -18707,6 +18702,34 @@ function test55(runner) {
18707
18702
  const result = BasicTestError.removeNonProjectPaths(errorStringLines.join("\n"), currentFolderPath);
18708
18703
  test56.assertEqual(expectedLines, result.split("\n"));
18709
18704
  });
18705
+ runner.test("with Windows file paths and 'node_modules' references in stack trace", (test56) => {
18706
+ const errorStringLines = [
18707
+ "AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:",
18708
+ "",
18709
+ " 1 !== 2",
18710
+ "",
18711
+ " at _AssertTest.assertEqual (C:\\my\\code\\cli-typescript\\node_modules\\@everyonesoftware\\common\\tests\\assertTest.ts:76:16)",
18712
+ " at C:\\my\\code\\cli-typescript\\tests\\mainTests.ts:9:18",
18713
+ " at C:\\my\\code\\cli-typescript\\node_modules\\@everyonesoftware\\common\\tests\\consoleTestRunner.ts:498:31",
18714
+ " at processTicksAndRejections (node:internal/process/task_queues:104:5)",
18715
+ " at _TestAction.action (C:\\my\\code\\cli-typescript\\node_modules\\@everyonesoftware\\common\\tests\\consoleTestRunner.ts:178:17)",
18716
+ " at _ConsoleTestRunner.runAsync (C:\\my\\code\\cli-typescript\\node_modules\\@everyonesoftware\\common\\tests\\consoleTestRunner.ts:531:17)",
18717
+ " at C:\\my\\code\\cli-typescript\\node_modules\\@everyonesoftware\\common\\tests\\consoleTestRunner.ts:112:13",
18718
+ " at _CurrentProcess.run (C:\\my\\code\\cli-typescript\\node_modules\\@everyonesoftware\\common\\sources\\currentProcess.ts:39:43)",
18719
+ " at test2 (C:\\my\\code\\cli-typescript\\tests\\tests.ts:6:5)"
18720
+ ];
18721
+ const currentFolderPath = "C:/my/code/cli-typescript/";
18722
+ const expectedLines = [
18723
+ "AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:",
18724
+ "",
18725
+ " 1 !== 2",
18726
+ "",
18727
+ " at C:\\my\\code\\cli-typescript\\tests\\mainTests.ts:9:18",
18728
+ " at test2 (C:\\my\\code\\cli-typescript\\tests\\tests.ts:6:5)"
18729
+ ];
18730
+ const result = BasicTestError.removeNonProjectPaths(errorStringLines.join("\n"), currentFolderPath);
18731
+ test56.assertEqual(expectedLines, result.split("\n"));
18732
+ });
18710
18733
  });
18711
18734
  runner.testFunction("makeFilePathsRelative()", () => {
18712
18735
  runner.test("with 'file:///' URLs and a 'node:internal' path", (test56) => {