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

rule: ensure vi.mock(<import>) is pointing to a valid file #665

Open
axel7083 opened this issue Feb 18, 2025 · 2 comments
Open

rule: ensure vi.mock(<import>) is pointing to a valid file #665

axel7083 opened this issue Feb 18, 2025 · 2 comments

Comments

@axel7083
Copy link

Description

Dealing with large repository often lead to refactoring where we rename, update, delete some path. Most IDE are able to rename, and show where the import are.

But when mocking a local import (https://vitest.dev/api/vi.html#vi-mock) we may have some tests failing, because we changed a filename, and finding where the problem is occurring might be difficult.

A rule where we would ensure that the path mocked exists would be amazing (if feasible)

@veritem
Copy link
Member

veritem commented Feb 18, 2025

how would that rule help you specifically, check if a file exists?

@axel7083
Copy link
Author

how would that rule help you specifically, check if a file exists?

I can see several cases

  • it would allow us to catch typo, if you misspelled a mock, it would tell you that the mock does not mock anything.
  • when running the CI, the linter is usually run before the unit tests (at least for us), so it would be before the tests are ran stating: the mock is not valid, you did a change that broke those tests

I don't know exactly how internally it would work (never implemented any eslint before), checking that file exists would be a solution, telling you this does not exist etc.

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

2 participants