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

[Bug]: dependencyExtractor does not exclude type-only imports #15308

Closed
CoryDanielson opened this issue Sep 16, 2024 · 3 comments
Closed

[Bug]: dependencyExtractor does not exclude type-only imports #15308

CoryDanielson opened this issue Sep 16, 2024 · 3 comments

Comments

@CoryDanielson
Copy link

CoryDanielson commented Sep 16, 2024

Version

29.7.0

Steps to reproduce

See this PR for unit tests which reproduce the issue #15307

// dependencyExtractor will exclude this dep
import type {foo} from 'file';
// but include this dep
import {type foo} from 'file';
// this too, and other syntaxes where all named imports are all type imports
import {type foo, type bar} from 'file';

Expected behavior

Test should pass

Actual behavior

Test fails

Additional context

I recently swept through a large repo and added an import {type ABC} from 'some/file';. In the following days our CI suite ran far more tests than we had expected for all PRs.

We traced this down to Jest's dependencyExtractor including this type import to the dependencies of every file that I had touched. We expected that Jest would have ignored type imports, and were surprised to see that it did not.

While looking at the dependencyExtractor code further, I see that it does make an attempt to exclude type imports, but only if the import statement is explicitly states that all imports are types (ie: import type ...). I had considered adding eslint rules to follow this import syntax more often, but if this "bug" could be addressed in the dependencyExtractor, that would be lovely.

Environment

System:
    OS: macOS 14.6.1
    CPU: (14) arm64 Apple M3 Max
  Binaries:
    Node: 20.12.2 - ~/.nvm/versions/node/v20.12.2/bin/node
    Yarn: 1.22.18 - ~/.nvm/versions/node/v20.12.2/bin/yarn
    npm: 8.19.4 - ~/.nvm/versions/node/v20.12.2/bin/npm
  npmPackages:
    jest: ^29.7.0 => 29.7.0
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Oct 16, 2024
Copy link

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 15, 2024
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant