You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you use the --retry=n flag (where n > 0), inline snapshots that succeeded on the first try fail on the retries with toMatchInlineSnapshot cannot be called multiple times at the same location. This means that if you precede a flaky assertion with an inline snapshot, the --retry flag does not work.
It sounds like the some state that toMatchInlineSnapshot carries needs to be reset between retries.
I later learned that --retry=1 is enough – it’s the number of retries not the number of total tries.
import{expect,test}from"vitest";test("demo",()=>{// First an up-to-date snapshot.// Unfortunately, this fails on the second retry.expect("a").toMatchInlineSnapshot(`"a"`);// Then an assertion of a flaky function.expect(flakyFunction()).toBe(2);});// Imagine this being a flaky function that only sometimes gives the correct value.// In this demo, we make it always succeed the second time. Which means that if you// run with `--retry=2` the test should pass. However, since the snapshot fails on// the second attempt, the test never passes. Comment out the snapshot test above// to see it succeed.letflakyCounter=1;functionflakyFunction(){returnflakyCounter++;}
toMatshSnapshot is known to have an issue with retry#5312, but the recent validation made retry not work with toMatshInlineSnapshot as well (though technically there was an issue with retry and toMatshInlineSnapshot in some cases).
Both could be fixed by the same approach mentioned in #5312 (comment)
Describe the bug
When you use the
--retry=n
flag (wheren > 0
), inline snapshots that succeeded on the first try fail on the retries withtoMatchInlineSnapshot cannot be called multiple times at the same location
. This means that if you precede a flaky assertion with an inline snapshot, the--retry
flag does not work.It sounds like the some state that
toMatchInlineSnapshot
carries needs to be reset between retries.I later learned that
--retry=1
is enough – it’s the number of retries not the number of total tries.Reproduction
https://github.com/lydell/vitest-inline-snapshot-retry
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: