americanexpress / jest-image-snapshot

✨ Jest matcher for image comparisons. Most commonly used for visual regression testing.
Apache License 2.0
3.84k stars 200 forks source link

Vitest: Incorrect filename when running concurrently #356

Open HalfdanJ opened 3 months ago

HalfdanJ commented 3 months ago

When using jest-image-snapshots in vitest, the naming of the snapshot files are incorrect when a test suite is run concurrently (describe.concurrent().

Instead of getting the name of each test, it instead gets the name of the last test in the suite, appended with an index, and the order depends on which tests finish first.

I'm unsure if this is a vitest issue or jest-image-snapshot issue.

vinnymac commented 1 week ago

This is likely related to #181.

I am experiencing a similar issue with test.concurrent.for where the tests fail on the second run every time. test.for does not behave this way. If I replace toMatchImageSnapshot with toMatchSnapshot it also works without issue.

This leads me to believe that the global state referenced in #181 means this library does not currently support concurrent testing. While it'd be nice if the README mentioned this, ideally this would get fixed internally, perhaps to match the behavior of toMatchSnapshot. AsyncLocalStorage may be one solution for example 🤔