vitest
vitest copied to clipboard
fix(expect,pretty-format,utils)!: check more properties for error equality
Description
- closes https://github.com/vitest-dev/vitest/issues/5244
- closes https://github.com/vitest-dev/vitest/issues/5697
NodeJs PR for a reference
- https://github.com/nodejs/node/pull/51805
todo
- [x] error equality
- [x] error formatting
- [x] asymmetrically show
causediff - [x] handle cyclic object
- [x] ~it can fail due to chai's error message generation~ https://github.com/chaijs/chai/issues/1645 Fixed!
- [x] should we update
toThrowError(new Error(...))usage too? (I think so) - [ ] should we break snapshot too? (for now, new error formatter is applied only when diffing and this looks fine)
- [x] docs
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
- [x] 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.
- [x] Ideally, include a test that fails without this PR but passes with it.
- [ ] Please, don't make changes to
pnpm-lock.yamlunless 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 docscommand.
Changesets
- [x] 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:, orchore:.
@hi-ogawa is there anything specific that keeps this PR in draft? Can I help?
I had a concern about whether we should print diff when custom properties are different. Currently, Vitest cannot show any diff in this case since pretty-format strips it off. Fortunately, chai/loupe can print them, but it's possible that the message will be truncated and not visible to users. This is an example from test cases:
exports[`Error equality > basic 4`] = `
{
"actual": "[Error: hello]",
"diff": "Compared values have no visual difference.",
"expected": "[Error: hello]",
"message": "expected Error: hello { cause: 'x' } to deeply equal Error: hello { cause: 'y' }",
}
`;
Do you think it's worth changing pretty-format side (I haven't attempted anything yet whether it's possible or not) or just keep it as is and rely on chai error message?
Do you think it's worth changing pretty-format side (I haven't attempted anything yet whether it's possible or not) or just keep it as is and rely on chai error message?
I think we can maybe introduce a flag in pretty-print (or maybe there is already one?) to print Error as an object.
Deploy Preview for vitest-dev ready!
Built without sensitive environment variables
| Name | Link |
|---|---|
| Latest commit | baf414bdc0c023ec67e4696d334fcf2e27457c54 |
| Latest deploy log | https://app.netlify.com/sites/vitest-dev/deploys/67578f91cb654800080d3bcf |
| Deploy Preview | https://deploy-preview-5876--vitest-dev.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
This fails now since we changed how diff is displayed 😄