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: match jest json output by providing full stack trace #4843

Conversation

bard
Copy link
Contributor

@bard bard commented Jan 1, 2024

Description

Continuation of #4826.

Jest's JSON output reports the full stack trace in the failureMessage field. This PR aligns Vitest's JSON reporter output to Jest's in that regard.

Note: not sure what's causing the conflict on the snapshot, I can't seem to reproduce it locally.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Copy link

netlify bot commented Jan 1, 2024

Deploy Preview for fastidious-cascaron-4ded94 canceled.

Name Link
🔨 Latest commit a366cc0
🔍 Latest deploy log https://app.netlify.com/sites/fastidious-cascaron-4ded94/deploys/659311c7083ec50008fc4c5f

@bard bard force-pushed the fix-match-jest-output-by-providing-full-stack-trace branch from c1de09e to 97a3cc1 Compare January 1, 2024 17:50
@bard bard force-pushed the fix-match-jest-output-by-providing-full-stack-trace branch from 97a3cc1 to ad08c1f Compare January 1, 2024 17:52
@bard bard marked this pull request as ready for review January 1, 2024 17:56
@sheremet-va
Copy link
Member

You can't reproduce it locally because the file paths in stack traces lead to files on your PC, not CI's 😄

@bard
Copy link
Contributor Author

bard commented Jan 1, 2024

You can't reproduce it locally because the file paths in stack traces lead to files on your PC, not CI's 😄

Hmm, that is the case on json.test.ts.snap, but the conflict is reported to be on reporters.spec.ts.snap.

Still, it's a problem on json.test.ts.snap. Not sure how to handle it though.

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Jan 3, 2024

Still, it's a problem on json.test.ts.snap. Not sure how to handle it though.

I don't think it's necessary to snapshot the whole "stack" string? How about moving out the part of the assertion and do it manually like this?

    expect(result.failureMessages[0]).toMatch(
      /^AssertionError: expected 2 to deeply equal 1\n.*json-fail.test.ts:8:13/);
    result.failureMessages = [];

expect(result).toMatchSnapshot()

@sheremet-va
Copy link
Member

sheremet-va commented Apr 5, 2024

This should be fixed by #5434 in the next major version.

@sheremet-va sheremet-va closed this Apr 5, 2024
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