Open programmer24601 opened 6 months ago
Okay I've got a workaround:
customSnapshotIdentifier: (parameters) => {
const [filePath, describeTitle, testTitle] =
parameters.currentTestName.split(' > ');
const filename = filePath.split('/').at(-1);
return kebabCase(
`${filename}-${describeTitle}-${testTitle}-${parameters.counter}-snap`
);
I'd be nice if jest-image-snapshot
could determine the testing framework and do this automatically for vitest.
Raised issue on vitest: https://github.com/vitest-dev/vitest/issues/4874
When using vitest 1.1.1 my snapshots are getting renamed to include the file path.
For example, a test file with:
./lib/chart-components/drawChart.test.ts
draw-chart
should generate an image data url for scenario 38
Would, with jest, generate a snapshot filename:
draw-chart-test-ts-draw-chart-should-generate-an-image-data-url-for-scenario-38-1-snap.png
Whereas with vitest re-running the test generates a new snapshot file with filename:
draw-chart-test-ts-lib-chart-components-draw-chart-test-ts-draw-chart-should-generate-an-image-data-url-for-scenario-38-1-snap.png
Node is then falling over with ENAMETOOLONG error when running the tests from the root directory of my monorepo.
I thought the
toMatchImageSnapshot()
optioncustomSnapshotIdentifier
might help but reducing it to:Gives:
lib-chart-components-draw-chart-test-ts-draw-chart-should-generate-an-image-data-url-for-scenario-38.png
Which tells me the Vitest API differs from Jest.
I'm pretty much blocked by this so help would be appreciated!