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

Open
CoryDanielson opened this issue Sep 16, 2024 · 0 comments
Open

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

CoryDanielson opened this issue Sep 16, 2024 · 0 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant