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(expect)!: check more properties for error equality #5876

Open
wants to merge 36 commits into
base: main
Choose a base branch
from

Conversation

hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Jun 12, 2024

Description

NodeJs PR for a reference

todo

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:.

@hi-ogawa hi-ogawa changed the title fix(expect)!: include custom properties for error equality fix(expect)!: check more properties for error equality Jun 12, 2024
@sheremet-va
Copy link
Member

@hi-ogawa is there anything specific that keeps this PR in draft? Can I help?

@hi-ogawa
Copy link
Contributor Author

hi-ogawa commented Jul 1, 2024

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?

@sheremet-va
Copy link
Member

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.

@hi-ogawa hi-ogawa changed the title fix(expect)!: check more properties for error equality fix(expect,pretty-format,utils)!: check more properties for error equality Oct 7, 2024
@hi-ogawa hi-ogawa force-pushed the error-equality-custom-properties branch from 6fae26a to 755cfb8 Compare October 7, 2024 02:15
Copy link

netlify bot commented Oct 7, 2024

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 1b41876
🔍 Latest deploy log https://app.netlify.com/sites/vitest-dev/deploys/6705cce565969f0008ae0004
😎 Deploy Preview https://deploy-preview-5876--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@hi-ogawa hi-ogawa marked this pull request as ready for review October 7, 2024 06:05
// - Only enumerable "own" properties are considered.
// - Error names, messages, causes, and errors are always compared, even if these are not enumerable properties. errors is also compared.
// (NOTE: causes and errors are added in v22)
return (
Copy link
Member

Choose a reason for hiding this comment

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

Can we rewrite it as a bunch of if statements? This is hard to process 😄

sheremet-va
sheremet-va previously approved these changes Oct 7, 2024
@sheremet-va sheremet-va changed the title fix(expect,pretty-format,utils)!: check more properties for error equality fix(expect)!: check more properties for error equality Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants