Skip to content
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

Vitest currentTestName causing ENAMETOOLONG #345

Open
programmer24601 opened this issue Jan 3, 2024 · 2 comments
Open

Vitest currentTestName causing ENAMETOOLONG #345

programmer24601 opened this issue Jan 3, 2024 · 2 comments

Comments

@programmer24601
Copy link

programmer24601 commented Jan 3, 2024

When using vitest 1.1.1 my snapshots are getting renamed to include the file path.

For example, a test file with:

  • path ./lib/chart-components/drawChart.test.ts
  • describe name draw-chart
  • test name 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() option customSnapshotIdentifier might help but reducing it to:

{
  customSnapshotIdentifier: (parameters) =>
    kebabCase(`${parameters.currentTestName}`)
}

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!

@programmer24601
Copy link
Author

programmer24601 commented Jan 4, 2024

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.

@programmer24601
Copy link
Author

Raised issue on vitest: vitest-dev/vitest#4874

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant