MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / formatStackTrace

Function formatStackTrace

test/jest-config.ts:43–67  ·  view source on GitHub ↗
(s: string)

Source from the content-addressed store, hash-verified

41 .join('\n');
42}
43
44function formatStackTrace(s: string): string {
45 const curDir = __dirname;
46 const parentDir = curDir.match(/(.*)\/([^\/]*)$/)?.[1];
47 if (!parentDir || !curDir) return s;
48 s = s
49 .replace(new RegExp(parentDir, 'g'), '..')
50 .replace(new RegExp(curDir, 'g'), '.');
51
52 const lines = s.split('\n').map((line) => {
53 if (/\.\.\/node_modules/.test(line)) return '';
54 if (/\(node:internal/.test(line)) return '';
55
56 line = line.replace(' at ', ' > ');
57
58 const [_, prefix, filename, suffix] =
59 line.match(/(?:(.+)\()([^:]+)(\:[^)]+)/) ?? [];
60 if (!prefix) return line;
61 if (/Object.<anonymous>/.test(prefix) || prefix.startsWith(' > console.'))
62 return GREY + ' > ' + CYAN + filename + GREY + suffix;
63 return GREY + prefix + CYAN + filename + GREY + suffix;
64 });
65 lines[0] = '';
66 lines[1] = '';
67 return RESET + lines.filter((line) => line.length > 0).join('\n') + RESET;
68}
69
70/**

Callers 3

logMethod · 0.85
errorMethod · 0.85
assertMethod · 0.85

Calls 3

matchMethod · 0.65
replaceMethod · 0.65
mapMethod · 0.65

Tested by

no test coverage detected