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

Open
wants to merge 21 commits into
base: main
Choose a base branch
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 f6f0bf5
🔍 Latest deploy log https://app.netlify.com/sites/vitest-dev/deploys/6736dc9fb0582200086cba0e
😎 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
Copy link

pkg-pr-new bot commented Nov 15, 2024

@vitest/browser

pnpm add https://pkg.pr.new/@vitest/browser@6852

@vitest/coverage-istanbul

pnpm add https://pkg.pr.new/@vitest/coverage-istanbul@6852

@vitest/expect

pnpm add https://pkg.pr.new/@vitest/expect@6852

@vitest/mocker

pnpm add https://pkg.pr.new/@vitest/mocker@6852

@vitest/pretty-format

pnpm add https://pkg.pr.new/@vitest/pretty-format@6852

@vitest/coverage-v8

pnpm add https://pkg.pr.new/@vitest/coverage-v8@6852

@vitest/runner

pnpm add https://pkg.pr.new/@vitest/runner@6852

@vitest/snapshot

pnpm add https://pkg.pr.new/@vitest/snapshot@6852

@vitest/spy

pnpm add https://pkg.pr.new/@vitest/spy@6852

@vitest/ui

pnpm add https://pkg.pr.new/@vitest/ui@6852

@vitest/utils

pnpm add https://pkg.pr.new/@vitest/utils@6852

vite-node

pnpm add https://pkg.pr.new/vite-node@6852

vitest

pnpm add https://pkg.pr.new/vitest@6852

@vitest/web-worker

pnpm add https://pkg.pr.new/@vitest/web-worker@6852

@vitest/ws-client

pnpm add https://pkg.pr.new/@vitest/ws-client@6852

commit: f6f0bf5

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