MCPcopy
hub / github.com/jestjs/jest / formatPath

Function formatPath

packages/jest-message-util/src/index.ts:290–312  ·  view source on GitHub ↗
(
  line: string,
  config: StackTraceConfig,
  relativeTestPath: string | null = null,
)

Source from the content-addressed store, hash-verified

288};
289
290export const formatPath = (
291 line: string,
292 config: StackTraceConfig,
293 relativeTestPath: string | null = null,
294): string => {
295 // Extract the file path from the trace line.
296 const match = line.match(/(^\s*at .*?\(?)([^()]+)(:\d+:\d+\)?.*$)/);
297 if (!match) {
298 return line;
299 }
300
301 let filePath = slash(path.relative(config.rootDir, match[2]));
302 // highlight paths from the current test file
303 if (
304 (config.testMatch &&
305 config.testMatch.length > 0 &&
306 picomatch(config.testMatch)(filePath)) ||
307 filePath === relativeTestPath
308 ) {
309 filePath = chalk.reset.cyan(filePath);
310 }
311 return STACK_TRACE_COLOR(match[1]) + filePath + STACK_TRACE_COLOR(match[3]);
312};
313
314export function getStackTraceLines(
315 stack: string,

Callers 2

#getMessageDetailsMethod · 0.90
formatStackTraceFunction · 0.85

Calls 1

matchMethod · 0.80

Tested by

no test coverage detected