( stack: string, config: StackTraceConfig, options: StackTraceOptions, testPath?: string, )
| 339 | } |
| 340 | |
| 341 | export function formatStackTrace( |
| 342 | stack: string, |
| 343 | config: StackTraceConfig, |
| 344 | options: StackTraceOptions, |
| 345 | testPath?: string, |
| 346 | ): string { |
| 347 | const lines = getStackTraceLines(stack, options); |
| 348 | let renderedCallsite = ''; |
| 349 | const relativeTestPath = testPath |
| 350 | ? slash(path.relative(config.rootDir, testPath)) |
| 351 | : null; |
| 352 | |
| 353 | if (!options.noStackTrace && !options.noCodeFrame) { |
| 354 | const topFrame = getTopFrame(lines); |
| 355 | if (topFrame) { |
| 356 | const {column, file: filename, line} = topFrame; |
| 357 | |
| 358 | if (line && filename && path.isAbsolute(filename)) { |
| 359 | let fileContent; |
| 360 | try { |
| 361 | // TODO: check & read HasteFS instead of reading the filesystem: |
| 362 | // see: https://github.com/jestjs/jest/pull/5405#discussion_r164281696 |
| 363 | fileContent = fs.readFileSync(filename, 'utf8'); |
| 364 | renderedCallsite = getRenderedCallsite(fileContent, line, column); |
| 365 | } catch { |
| 366 | // the file does not exist or is inaccessible, we ignore |
| 367 | } |
| 368 | } |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | const stacktrace = |
| 373 | lines.length === 0 |
| 374 | ? '' |
| 375 | : `\n${lines |
| 376 | .map( |
| 377 | line => |
| 378 | STACK_INDENT + |
| 379 | formatPath(trimPaths(line), config, relativeTestPath), |
| 380 | ) |
| 381 | .join('\n')}`; |
| 382 | |
| 383 | return renderedCallsite + stacktrace; |
| 384 | } |
| 385 | |
| 386 | type FailedResults = Array<{ |
| 387 | /** Stringified version of the error */ |
no test coverage detected