(
e: TestError | Error,
options: StackTraceParserOptions = {},
)
| 305 | } |
| 306 | |
| 307 | export function parseErrorStacktrace( |
| 308 | e: TestError | Error, |
| 309 | options: StackTraceParserOptions = {}, |
| 310 | ): ParsedStack[] { |
| 311 | if (!e || isPrimitive(e)) { |
| 312 | return [] |
| 313 | } |
| 314 | |
| 315 | if ('stacks' in e && e.stacks) { |
| 316 | return e.stacks |
| 317 | } |
| 318 | |
| 319 | const stackStr = e.stack || '' |
| 320 | // if "stack" property was overwritten at runtime to be something else, |
| 321 | // ignore the value because we don't know how to process it |
| 322 | let stackFrames = typeof stackStr === 'string' |
| 323 | ? parseStacktrace(stackStr, options) |
| 324 | : [] |
| 325 | |
| 326 | if (!stackFrames.length) { |
| 327 | const e_ = e as any |
| 328 | if (e_.fileName != null && e_.lineNumber != null && e_.columnNumber != null) { |
| 329 | stackFrames = parseStacktrace(`${e_.fileName}:${e_.lineNumber}:${e_.columnNumber}`, options) |
| 330 | } |
| 331 | if (e_.sourceURL != null && e_.line != null && e_._column != null) { |
| 332 | stackFrames = parseStacktrace(`${e_.sourceURL}:${e_.line}:${e_.column}`, options) |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | if (options.frameFilter) { |
| 337 | stackFrames = stackFrames.filter( |
| 338 | f => options.frameFilter!(e as TestError, f) !== false, |
| 339 | ) |
| 340 | } |
| 341 | |
| 342 | ;(e as TestError).stacks = stackFrames |
| 343 | return stackFrames |
| 344 | } |
| 345 | |
| 346 | interface SourceMapLike { |
| 347 | version: number |
no test coverage detected