Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use correct source maps in stacktrace #2027

Merged
merged 17 commits into from Oct 7, 2022
Merged
10 changes: 7 additions & 3 deletions packages/vitest/src/utils/source-map.ts
Expand Up @@ -25,10 +25,14 @@ export async function interpretSourcePos(stackFrames: ParsedStack[], ctx: Vitest
for (const frame of stackFrames) {
if ('sourcePos' in frame)
continue
const transformResult = ctx.server.moduleGraph.getModuleById(frame.file)?.ssrTransformResult
if (!transformResult)
const ssrTransformResult = ctx.server.moduleGraph.getModuleById(frame.file)?.ssrTransformResult
const transformResult = ctx.server.moduleGraph.getModuleById(frame.file)?.transformResult
const result = ssrTransformResult || transformResult
haikyuu marked this conversation as resolved.
Show resolved Hide resolved
if (!result)
continue
const sourcePos = await getOriginalPos(transformResult.map as any as RawSourceMap | undefined, frame)
const fetchResult = ctx.vitenode.fetchCache.get(frame.file)?.result
const map = fetchResult?.map || ssrTransformResult?.map
const sourcePos = await getOriginalPos(map as any as RawSourceMap | undefined, frame)
if (sourcePos)
frame.sourcePos = sourcePos
}
Expand Down