-
Notifications
You must be signed in to change notification settings - Fork 393
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
test: better snapshot errors #4985
Conversation
Co-Authored-By: Will Harney <[email protected]> Co-Authored-By: John Hefferman <[email protected]>
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.
Very nice!
const otherSnapshot = readFileSync( | ||
path.resolve(dirname, otherName), | ||
'utf8' | ||
); |
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.
It's a shame we have to keep reading in snapshot files when presumably Vitest is already doing this elsewhere.
? brokenSnapshot | ||
: otherSnapshot, | ||
actual: brokenResultHasContent ? brokenResult : otherResult, | ||
}); |
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.
TIL about AssertionError
!
Details
If you have a test fixture for a "success" scenario, it will generate an
expected.html
(or.js
, etc) with content and an emptyerror.txt
. If you then update some code and it causes a failure, then the test output will be an emptyexpected.html
(or.js
, etc) and anerror.txt
with content. The snapshot checker only compares files of the same name, so the output looks lomething like this:That's not very helpful, so I added some logic to check for that case (and the other way around), to make it more clear that your outputs have gotten mixed up.
Does this pull request introduce a breaking change?
Does this pull request introduce an observable change?
GUS work item