MCPcopy
hub / github.com/vitest-dev/vitest / parseStacktrace

Function parseStacktrace

packages/utils/src/source-map.ts:226–287  ·  view source on GitHub ↗
(
  stack: string,
  options: StackTraceParserOptions = {},
)

Source from the content-addressed store, hash-verified

224}
225
226export function parseStacktrace(
227 stack: string,
228 options: StackTraceParserOptions = {},
229): ParsedStack[] {
230 const { ignoreStackEntries = stackIgnorePatterns } = options
231 let stacks = !CHROME_IE_STACK_REGEXP.test(stack)
232 ? parseFFOrSafariStackTrace(stack)
233 : parseV8Stacktrace(stack)
234
235 // remove vi.defineHelper's internal stacks
236 const helperIndex = stacks.findLastIndex(s =>
237 // this covers cases such as
238 // "__VITEST_HELPER__"
239 // "__VITEST_HELPER__ [as <object method name>]"
240 // "async*__VITEST_HELPER__" (firefox)
241 // "async __VITEST_HELPER__" (webkit)
242 s.method.includes('__VITEST_HELPER__'),
243 )
244 if (helperIndex >= 0) {
245 stacks = stacks.slice(helperIndex + 1)
246 }
247
248 return stacks.map((stack) => {
249 if (options.getUrlId) {
250 stack.file = options.getUrlId(stack.file)
251 }
252
253 const map = options.getSourceMap?.(stack.file) as
254 | SourceMapLike
255 | null
256 | undefined
257 if (!map || typeof map !== 'object' || !map.version) {
258 return shouldFilter(ignoreStackEntries, stack.file) ? null : stack
259 }
260
261 const traceMap = new DecodedMap(map, stack.file)
262 const position = getOriginalPosition(traceMap, stack)
263 if (!position) {
264 return stack
265 }
266
267 const { line, column, source, name } = position
268 let file = source || stack.file
269 if (file.match(/\/\w:\//)) {
270 file = file.slice(1)
271 }
272
273 if (shouldFilter(ignoreStackEntries, file)) {
274 return null
275 }
276
277 if (line != null && column != null) {
278 return {
279 line,
280 column,
281 file,
282 method: name || stack.method,
283 }

Callers 7

initiateRunnerFunction · 0.90
parseStacktraceMethod · 0.90
parseErrorFunction · 0.90
onFilterStackTraceFunction · 0.90
onUserConsoleLogFunction · 0.90
printLeaksSummaryFunction · 0.90
parseErrorStacktraceFunction · 0.85

Calls 8

parseV8StacktraceFunction · 0.85
shouldFilterFunction · 0.85
getOriginalPositionFunction · 0.85
getSourceMapMethod · 0.80
filterMethod · 0.65
testMethod · 0.45
matchMethod · 0.45

Tested by

no test coverage detected