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: render original source if mapped in node #987
fix: render original source if mapped in node #987
Conversation
✅ Deploy Preview for vitest-dev ready! 🔨 Explore the source changes: e1fc35c 🔍 Inspect the deploy log: https://app.netlify.com/sites/vitest-dev/deploys/623609d4a1fcd500081b6631 😎 Browse the preview: https://deploy-preview-987--vitest-dev.netlify.app |
packages/vitest/src/node/error.ts
Outdated
@@ -32,7 +32,8 @@ export async function printError(error: unknown, ctx: Vitest) { | |||
printErrorMessage(e, ctx.console) | |||
await printStack(ctx, stacks, nearest, async(s, pos) => { | |||
if (s === nearest && nearest) { | |||
const sourceCode = await fs.readFile(nearest.file, 'utf-8') | |||
const file = nearest.sourcePos && nearest.sourcePos.source && nearest.sourcePos.source !== '.' ? join(nearest.file, '../', nearest.sourcePos.source) : nearest.file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use ?.
here, and I think it will be good to extract a fileFromSourcePosition(position)
utility so it can be reused in printStack
const file = nearest.sourcePos && nearest.sourcePos.source && nearest.sourcePos.source !== '.' ? join(nearest.file, '../', nearest.sourcePos.source) : nearest.file | |
const file = nearest?.sourcePos?.source !== '.' ? join(nearest.file, '../', nearest.sourcePos.source) : nearest.file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracted as: fileFromParsedStack
, any idea why some tests appear to be failing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! The errors look unrelated, it seems an issue with a test expectation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Solved
Co-authored-by: Jan Morawietz <jan.morawietz@paessler.com>
Address the first phase of #832 when a stack trace is interpreted in case of errors in node if a source map is present it ensures the proper file is rendered in the test summary.
This PR doesn't address the full scope of the issue as it would be better (arguably?) to also show the test file names correspondent to the mapped source if present but I don't yet understand how that could be achieved because at the point test file names are rendered source maps are not yet parsed
After this PR the repro code produces:
While it still shows test files as before: