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: render original source if mapped in node #987

Merged

Conversation

mikearnaldi
Copy link
Contributor

@mikearnaldi mikearnaldi commented Mar 19, 2022

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:
Screenshot 2022-03-19 153140

While it still shows test files as before:
Screenshot 2022-03-19 153243

@netlify
Copy link

netlify bot commented Mar 19, 2022

✅ 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

@@ -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
Copy link
Member

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

Suggested change
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

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solved

@antfu antfu merged commit 42406a3 into vitest-dev:main Mar 20, 2022
chaii3 pushed a commit to chaii3/vitest that referenced this pull request May 13, 2022
Co-authored-by: Jan Morawietz <jan.morawietz@paessler.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants