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

feat(jest): add __mocks__ to entry files #925

Merged
merged 4 commits into from
Jan 24, 2025

Conversation

TkDodo
Copy link
Contributor

@TkDodo TkDodo commented Jan 24, 2025

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

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
Copy link

pkg-pr-new bot commented Jan 24, 2025

Open in Stackblitz

npm i https://pkg.pr.new/knip@925

commit: 525b2f4

Copy link
Collaborator

@webpro webpro left a 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__/**'];
Copy link
Collaborator

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

Copy link
Collaborator

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

Copy link
Contributor Author

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?

Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like this?

256aa4a

Copy link
Collaborator

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?

Copy link
Contributor Author

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

@webpro webpro merged commit 895434b into webpro-nl:main Jan 24, 2025
23 checks passed
@webpro
Copy link
Collaborator

webpro commented Jan 24, 2025

🚀 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.

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

Successfully merging this pull request may close these issues.

2 participants