-
-
Notifications
You must be signed in to change notification settings - Fork 201
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
feat(jest): add __mocks__ to entry files #925
Conversation
jest allows defining manual mocks within a special __mocks__ directory, so those files should be seen as used by knip. See: https://jestjs.io/docs/manual-mocks
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Dominik! One nit I have.
@@ -16,7 +16,7 @@ const isEnabled: IsPluginEnabled = ({ dependencies, manifest }) => | |||
|
|||
const config = ['jest.config.{js,ts,mjs,cjs,json}', 'package.json']; | |||
|
|||
const entry = ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)']; | |||
const entry = ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)', '**/__mocks__/**']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to have a file in that folder won't be reported as unused anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean in one of the jest fixtures folders
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, how can we achieve that?
what I did before was exclude them in project
:
!/**/__mocks__/**
but I don’t think that’s what we’d generally want?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could an empty file such as __mocks__/used.js
in of the fixtures folders. Before the change that was an unused file.
Btw, maybe also better to use something more specific like **/__mocks__/**/*.{js,tx}
- would that suffice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see my own typo now 🤦♂️ but yeah that's fine (i wouldn't expect jsx to be necessary here)
Any chance you could still add that file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, yeah, I think I got now what you mean: 615dd83
before the fix, this was reported as unused.
🚀 This pull request is included in v5.43.3. See Release 5.43.3 for release notes. Using Knip in a commercial project? Please consider becoming a sponsor. |
jest allows defining manual mocks within a special mocks directory, so those files should be seen as used by knip. See: https://jestjs.io/docs/manual-mocks