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(snapshot)!: reset snapshot state for retry and repeats #6817

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

Conversation

hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Oct 30, 2024

Description

todo

  • inline
  • file
  • multiple tests with same title
  • added/updated stats
  • tests
  • should we make @vitest/snapshot non breaking?
    • I changed SnapshotClient interface a lot to simplify the concept, but it's probably possible to make it non-breaking by keeping testId optional.
  • review @vitest/snapshot usage in the wild to see if new API is not bad.

I have an attempt to support different snapshot files per test in #6827, but I need to think a bit more to validate the idea and we should separate it from this fix.

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

Copy link

netlify bot commented Oct 30, 2024

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit eae4ed7
🔍 Latest deploy log https://app.netlify.com/sites/vitest-dev/deploys/67286f50949dd30008bc6ca8
😎 Deploy Preview https://deploy-preview-6817--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 force-pushed the rework-snapshot-state branch 2 times, most recently from 62cc7be to 7cd37a6 Compare October 30, 2024 03:54
@hi-ogawa hi-ogawa changed the title wip: rework snapshot state fix(snapshot): reset snapshot state for retry and repeats Oct 31, 2024
@hi-ogawa hi-ogawa marked this pull request as ready for review October 31, 2024 09:15
Copy link
Member

@sheremet-va sheremet-va left a comment

Choose a reason for hiding this comment

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

Looks very good! But we would have to release it as a breaking change (@vitest/snapshot is a public API and SnapshotState is exposed on expect.getState() - there are jest's custom matchers that rely on the jest interface)

test/snapshots/test/test-update.test.ts Outdated Show resolved Hide resolved
packages/snapshot/src/client.ts Outdated Show resolved Hide resolved
getSnapshotState(filepath: string): SnapshotState {
const state = this.snapshotStateMap.get(filepath)
if (!state) {
throw new Error('snapshot state not initialized')
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 maybe make it more presentable here, too? Since snapshot manager is a public API (even used in webdriverio, I think). Something like The snapshot state for ${file} was not initialised. Did you call manager.setup()?

packages/vitest/src/integrations/snapshot/chai.ts Outdated Show resolved Hide resolved
@hi-ogawa hi-ogawa changed the title fix(snapshot): reset snapshot state for retry and repeats fix(snapshot)!: reset snapshot state for retry and repeats Nov 4, 2024
@hi-ogawa
Copy link
Contributor Author

hi-ogawa commented Nov 4, 2024

Only 7 users on public 😃 https://www.npmjs.com/package/@vitest/snapshot?activeTab=dependents I'll check what webdriverio does and see if new API fits them.

@hi-ogawa
Copy link
Contributor Author

hi-ogawa commented Nov 4, 2024

I briefly reviewed expect-webdriverio's usage and new API should look okay.

Webdriverio doesn't seem to have testId, but they can reuse the test name for this like SnapshotClient.assert({ ..., name: testName, testId: testName}). One consideration for us is that maybe we can make testId optional on our side with name fallback automatically since this is only used for SnapshotClient.clearTest(file, testId).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants