-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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): allow inline snapshot calls on same location with same snapshot #7464
Conversation
…will take the first result.
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, thanks for the PR 👋
Previously we have decided that throwing is good for consistency, but if we can figure out well-defined behavior without breaking, then it's worth revisiting. 🤔
Can you add tests in test/snapshots
? The one in test/cli/fixtures/fails/inline-snapshop-inside-loop.test.ts
isn't so flexible to simulate many scenarios, but you can take a look at tests like test/snapshots/test/skip-test.test.ts
or test/snapshots/test/summary.test.ts
to test various scenarios like initial snapshot creation, updating snapshot, etc...
Thank you @hi-ogawa for the message & hints. I looked into what you said and updated a few things (everything ^^). And added a few tests as you suggested. Let me know what you think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously we have decided that throwing is good for consistency, but if we can figure out well-defined behavior without breaking, then it's worth revisiting. 🤔
Totally agree. This would be great to support but it needs to be well supported. I've recently seen multiple projects utilizing inline snapshots in loops and custom test()
, that will fail once they upgrade to v3. (Also I'd like to personally use this feature in many of my tests, as I want to avoid writing assertions.)
@AriPerkkio you saw something to enhance on this PR to have this back ? |
I'll start to look into this 👍 I think there's a way to make this work, so I might push some tests and code here. One issue came back on this PR is that the following example causes an update-rerun loop on terminal. This is something we still want to prevent and probably that's possible. pnpm -C examples/basic test repro.test.ts -- -u // repro.test.ts
import { expect, test } from 'vitest';
test('repro', () => {
example(1);
example(2); // for example, the user only had `example(1)` initially, but added `example(2)` later.
});
// this happens same when `example(2)` is in a different test case
// test('repro2', () => {
// example(2);
// })
function example(v: any) {
expect(v).toMatchInlineSnapshot(`1`);
}
This change actually already happened on Vitest 2, so it wasn't even considered a breaking change 🙃 |
Yeah, it's not a breaking from 2.1.9 to 3. It's a regression, breaking between 2.0.5. and 2.1.9 (somewhere 🫣) I let you continu on this ? Or you need something from me ? |
@vitest/browser
@vitest/coverage-istanbul
@vitest/expect
@vitest/mocker
@vitest/coverage-v8
@vitest/pretty-format
@vitest/runner
@vitest/snapshot
@vitest/spy
@vitest/ui
@vitest/utils
vite-node
vitest
@vitest/web-worker
@vitest/ws-client
commit: |
@jycouet So far so good. As you can see in the diff, this simply relaxes the error condition, so it's a matter of whether this is relaxing enough for the desired use cases to work again. Please feel free to try and let me know if you spot something 🙏 |
Our CI is running well with what you deployed with I'm wondering why some tests are failing (Looks like not linked with what we are doing). It's some flaky tests ? 🤔 |
Browser mode especially on Windows has been flaky, so probably nothing to worry. |
So, it all looks good to me 👍 |
@hi-ogawa could yuo tell me what are the next steps ? You need anything else from me ? |
This looks good to me. I'll wait for another review from team just in case. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
Description
fix(inline-snapshot): can be used by multiple tests. On clean state, will take the first result.
fix: #7450
From
2.1.9
and after, it was not possible to have multiple tests using the sametoMatchInlineSnapshot
. It's the result of #6327 & #6332. I Belive that the root cause is "What to put as default value from a clean state ?" And before, the cli was adding all serialized result. This PR is fixing this by adding only the first result.Summarized by:
Let me know what I missed, I'm new here 👋
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yaml
unless you introduce a new test example.Tests
pnpm test:ci
.Documentation
pnpm run docs
command.Changesets
feat:
,fix:
,perf:
,docs:
, orchore:
.