Description
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