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

Merged
merged 29 commits into from
Dec 5, 2024

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 force-pushed the rework-snapshot-state branch from 7cd37a6 to 7cf11f5 Compare October 30, 2024 04:51
@hi-ogawa hi-ogawa force-pushed the rework-snapshot-state branch from e3239a0 to c5e4527 Compare October 30, 2024 10:27
@hi-ogawa hi-ogawa force-pushed the rework-snapshot-state branch from e9f8133 to b441f8a Compare October 31, 2024 02:52
@hi-ogawa hi-ogawa force-pushed the rework-snapshot-state branch from b441f8a to 3fc11d5 Compare October 31, 2024 02:53
@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 force-pushed the rework-snapshot-state branch from 620e2ce to 4a69ec1 Compare October 31, 2024 07:57
@hi-ogawa hi-ogawa force-pushed the rework-snapshot-state branch from 278ada9 to e0768a1 Compare October 31, 2024 08:27
@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 hi-ogawa force-pushed the rework-snapshot-state branch from 08db7bb to d9b5f23 Compare November 4, 2024 07:54
@hi-ogawa hi-ogawa force-pushed the rework-snapshot-state branch from d9b5f23 to 99c64e6 Compare November 4, 2024 08:01
@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).

@ffMathy
Copy link

ffMathy commented Dec 4, 2024

This is awesome. Could solve: #7011

Anything I can do to help get this out somehow? What's missing?

@hi-ogawa
Copy link
Contributor Author

hi-ogawa commented Dec 5, 2024

This is a breaking change, so unfortunately we have to wait until next major v3.

@ffMathy
Copy link

ffMathy commented Dec 5, 2024

Oh okay. How often do major releases like this release? Are we talking years, or is there a chance we'll see this in H1 of 2025?

@sheremet-va sheremet-va added this to the 3.0.0 milestone Dec 5, 2024
@sheremet-va
Copy link
Member

Oh okay. How often do major releases like this release? Are we talking years, or is there a chance we'll see this in H1 of 2025?

You won't believe it. Vitest 3 comes out in January.

@ffMathy
Copy link

ffMathy commented Dec 5, 2024

Hahahaha ❤️
That's awesome!

@sheremet-va sheremet-va merged commit e8ce94c into vitest-dev:main Dec 5, 2024
17 checks passed
@hi-ogawa hi-ogawa deleted the rework-snapshot-state branch December 6, 2024 00:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Approved
3 participants