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
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/knip/src/plugins/jest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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


const resolveDependencies = async (config: JestInitialOptions, options: PluginOptions): Promise<Input[]> => {
const { configFileDir } = options;
Expand Down
Loading