fix(testing): convert executor-based jest.config.ts and preserve type-only imports#35286
Open
leosvelperez wants to merge 1 commit intomasterfrom
Open
fix(testing): convert executor-based jest.config.ts and preserve type-only imports#35286leosvelperez wants to merge 1 commit intomasterfrom
leosvelperez wants to merge 1 commit intomasterfrom
Conversation
…-only imports Runs convert-jest-config-to-cjs for every jest.config.ts with a CJS-compatible package.json type, not just plugin-registered ones, so executor-based workspaces stop crashing on native type-stripping loaders (readConfig). Keeps `import type` declarations and splits inline `type` specifiers into a type-only import plus a require so editor/tsc type safety is retained.
✅ Deploy Preview for nx-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for nx-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
|
View your CI Pipeline Execution ↗ for commit 599bbb4
☁️ Nx Cloud last updated this comment at |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Current Behavior
nx migrate --run-migrationscrashes on workspaces that use the@nx/jest:jestexecutor (viatargetDefaults) instead of@nx/jest/plugin:The
convert-jest-config-to-cjsmigration (update-22-2-0) is gated on@nx/jest/pluginbeing registered innx.json, so executor-based workspaces skip it entirely. Theirjest.config.tsfiles (often a mix of ESM syntax and CJS globals like__dirname) never get converted. The laterreplace-removed-matcher-aliases-v22-3migration then callsjest-config.readConfigon everyjest.config.ts, which on Node 22+/24+ with native type-stripping reparses the file as ESM and crashes.Separately, the conversion logic also didn't handle
import typedeclarations — it rewrote them toconst { X } = require('mod'), which unnecessarily pulls the module at runtime and drops type references the IDE/tsc relied on. For types-only specifiers, it could even crash at runtime.Expected Behavior
convert-jest-config-to-cjsruns for everyjest.config.tswhose project is CommonJS (plugin registration is no longer required), so executor-based setups are covered. Thetype: moduleguard still skips ESM projects.Type-only imports are preserved:
import type { Config } from 'jest'— left untouched (Node's type-stripping erases it, so it doesn't force ESM parsing at runtime).import { type Foo, bar } from 'mod'— split intoimport type { Foo } from 'mod'plusconst { bar } = require('mod').import { type Foo as JestFoo, run } from 'mod') preserved.Related Issue(s)
Fixes #34593