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

feat(snapshot): ability to skip snapshot from custom serializer + attest example #6852

Closed
wants to merge 26 commits into from

Conversation

hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Nov 5, 2024

Description

From my quick research, there are currently two blockers for attest to be able to make use of Vitest snapshot system.

One is that, Vitest snapshot workflow normally expects a watch re-run, for example, for new inline snapshot or when updating failed snapshots. Attest relies on globalSetup to trigger analyze once, so this was the issue, but should be solved by #6803 and it looks good now.

Secondly, to support skipType mode (which is essential to allow running only normal tests without heavy typescript analysis), we'll probably need a concept of "skipped" snapshot check so that Vitest gracefully let invalid attest snapshots pass. This is what PR implements.

This approach assumes that attest is kept as 3rd party integration. If it'll end up as core feature, then there might be a way to special case attest usage like expectAttest().toMatchTypeSnapshot(), which then implement "skip mode" behavior there instead of doing the magic in serializer level, but I haven't investigate this direction yet.

tbd

  • ideas for faster re-run?
  • ideas for core integration e.g. custom attest alias like expectAttest?
  • how to support attest in browser mode where fs is not available? (can we send precache result ahead and access it synchronously?)

todo

  • fix windows

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 feat(snapshot): ability to skip snapshot from custom serializer feat(snapshot): ability to skip snapshot from custom serializer + attest example Nov 5, 2024
Copy link

netlify bot commented Nov 5, 2024

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit d3208ca
🔍 Latest deploy log https://app.netlify.com/sites/vitest-dev/deploys/67453d0aca6f64000835e3bc
😎 Deploy Preview https://deploy-preview-6852--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 changed the title feat(snapshot): ability to skip snapshot from custom serializer + attest example feat(snapshot): ability to skip snapshot from custom serializer + attest example Nov 5, 2024
@hi-ogawa hi-ogawa marked this pull request as ready for review November 9, 2024 04:49

This comment was marked as resolved.

@hi-ogawa hi-ogawa marked this pull request as draft November 16, 2024 01:15
@hi-ogawa hi-ogawa mentioned this pull request Nov 26, 2024
25 tasks
@hi-ogawa
Copy link
Contributor Author

Closing in favor of

@hi-ogawa hi-ogawa closed this Nov 26, 2024
@hi-ogawa hi-ogawa deleted the feat-skip-snapshot-serialize branch November 26, 2024 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is it possible to add snapshots in type testing?
1 participant