Skip to content

fix(snapshot)!: fail test with obsolete snapshot on CI #7963

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

Merged
merged 7 commits into from
Jun 22, 2025

Conversation

hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented May 12, 2025

Description

example

$ CI=1 TEST_OBSOLETE=1 pnpm -C test/snapshots test:fixtures --root test/fixture
s/obsolete

...

 RUN  v3.2.0-beta.1 /home/hiroshi/code/others/vitest/test/snapshots/test/fixtures/obsolete

 ✓ src/test2.test.ts (2 tests) 2ms
 ❯ src/test1.test.ts (3 tests) 2ms
   ✓ foo 1ms
   ✓ fuu 0ms
   ✓ bar 1ms

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 FAIL  src/test1.test.ts [ src/test1.test.ts ]
Error: Obsolete snapshots found when no snapshot update is expected.
· foo 1
· fuu 1

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯


  Snapshots  2 obsolete
             ↳ src/test1.test.ts
               · foo 1
               · fuu 1

 Test Files  1 failed | 1 passed (2)
      Tests  5 passed (5)
   Start at  09:00:48
   Duration  205ms (transform 29ms, setup 0ms, collect 29ms, tests 4ms, environment 0ms, prepare 94ms)

 ELIFECYCLE  Command failed with exit code 1.

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 May 12, 2025

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit ec1c009
🔍 Latest deploy log https://app.netlify.com/sites/vitest-dev/deploys/6823d874a3bc87000785d21e
😎 Deploy Preview https://deploy-preview-7963--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 fix(snapshot): fail ci when obsolete snapshot is found fix(snapshot): fail test with obsolete snapshot on CI May 12, 2025
@hi-ogawa hi-ogawa marked this pull request as ready for review May 12, 2025 09:59
this.workerState.config.snapshotOptions.updateSnapshot === 'none'
&& result.unchecked
) {
const error = new Error(`Obsolete snapshots found: ${result.uncheckedKeys.join(', ')}`)
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we can print it in a better way (should we? obsolete snapshots are already printed one line at a time, but without the separation by test file)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tweaked the error message. Please check the example in the PR description. It's mostly a copy of the base reporter.

@sheremet-va sheremet-va added this to the 4.0.0 milestone May 23, 2025
sheremet-va
sheremet-va previously approved these changes Jun 9, 2025
@sheremet-va sheremet-va changed the title fix(snapshot): fail test with obsolete snapshot on CI fix(snapshot)!: fail test with obsolete snapshot on CI Jun 11, 2025
@sheremet-va sheremet-va merged commit 4d84f0a into vitest-dev:main Jun 22, 2025
13 of 14 checks passed
@sheremet-va
Copy link
Member

We also need to add this to migration guide

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.

Obsolete test snapshots do not cause test run to fail in CI environments
2 participants