chore: migrate jest to @nx/jest plugin with swc-jest#160
Draft
X-Guardian wants to merge 9 commits intoopen-constructs:mainfrom
Draft
chore: migrate jest to @nx/jest plugin with swc-jest#160X-Guardian wants to merge 9 commits intoopen-constructs:mainfrom
X-Guardian wants to merge 9 commits intoopen-constructs:mainfrom
Conversation
added 9 commits
May 4, 2026 18:15
Contributor
Author
|
Blocked by #166 |
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.
Description
The previous setup had the jest configuration duplicated across every package, with
ts-jestdoing TypeScript transforms on every test run andlerna runorchestrating package-level scripts that didn't understand the dependency graph. That meant slow tests, repeated boilerplate when adding a new package, and CI workflows that ran every package on every PR even when only one was affected.This PR adopts the standard Nx jest setup. The motivations:
nx affectedskips packages whose source (and upstream dependencies) didn't change, so PRs touching one package don't pay the full matrix cost.jest.preset.jsplus a tiny per-packagejest.config.jsplus a.spec.swcrcreplaces the bespoke ts-jest config each package carried. Adding a new package is now a copy-paste of three small files.@nx/jestplugin honoursdependsOn: ["^build"]fromnx.json, so cross-package tests no longer fail with "module not found" when an upstream hasn't been built. The per-packagepretest: yarn buildworkarounds disappear.needs:terraform) lets the rest run in a single, faster job.Summary
Migrates the jest test pipeline from per-package
ts-jestconfigs driven bylerna runto the@nx/jestplugin with shared swc-jest transformer, and rewires CI to usenx affectedwith coverage surfacing in the GitHub job summary.Test runner
cdktn,cdktn-cli,@cdktn/commons,@cdktn/cli-core,@cdktn/hcl-tools,@cdktn/hcl2cdk,@cdktn/hcl2json,@cdktn/provider-generator,@cdktn/provider-schema..spec.swcrcand a thinjest.config.jsthat extends the new rootjest.preset.js(which itself extends@nx/jest/preset).ts-jest,jest, and@types/jestremoved from per-package devDependencies; hoisted to root.@nx/jest/plugin(registered innx.json) provides thetesttarget, replacing per-packagetestandtest:ciscripts.test:updateandjest-watchretained.cdktn,@cdktn/provider-schema,@cdktn/provider-generator) carry annx.tags: ["needs:terraform"]tag for CI partitioning.@cdktn/hcl2cdk'stesttarget declares an Nx target-level dependency oncdktn-cli:build. ItsglobalSetup.tsspawnspackages/cdktn-cli/bundle/bin/cdktn get, so the CLI bundle must exist before tests run. Wiring this in nx (rather than as a CI step) makes it work uniformly fornx affected,nx test <pkg>, and local runs.Root scripts
test,test:ci,test:updatefromlerna runtonx run-many.pretest: yarn build(nx now handles^build) and the rootpretestlint hook (lint runs separately vialinting.yml).CI
pr-unit.ymlrewritten: replaces an 8x2 matrix (16 jobs) with twonx affectedjobs -affected_no_terraform(no matrix) andaffected_terraform(1.6.5/1.5.5 matrix). Both use--excludepatterns: the no-terraform job excludestag:needs:terraform,@examples/*, andgenerate-function-bindings; the terraform job uses*,!tag:needs:terraformto keep only terraform-tagged projects.nrwl/nx-set-shasaction pinned to v5.0.1; explicit--base="$NX_BASE" --head="$NX_HEAD"passed to suppress info output.--reporters=github-actions.unit.yml(still called fromrelease.ymlandrelease_next.yml) updated tonx test <pkg>.pr-unit.ymlandunit.ymlrunyarn packageconditionally before tests when@cdktn/hcl2cdkis affected. ItsglobalSetup.tscallscdktn init --dist=...which reads jsii tarballs from the workspace-rootdist/directory — that's produced byyarn package+tools/collect-dist.sh, not by an Nx target chain. Most PRs don't pay the cost.npx nxinvocations in workflows replaced withyarn nxso they use the workspace-pinned versions.examples.ymlmatrix builder switched fromnpx lerna list --scopetoyarn workspaces info | jq. The previous form was reaching for a globally-installed lerna whose bundled Nx couldn't resolve@nx/jest/plugin; the replacement needs neither lerna noryarn install.--coveragepluscoverageReportersin the preset) and rendered to$GITHUB_STEP_SUMMARYvia a newtools/test-coverage-summary.mjsESM script that aggregates per-packagecoverage-summary.jsoninto a markdown table (jest has no built-in cross-project aggregator).knip
test/(the integration test workspace) toknip.jsoncworkspaces with TODOignoreDependenciesmatching the convention used elsewhere.Workarounds
cdktn/lib/private/fs.ts:archiveSync- small workaround so itsexecSync(node ${__filename})self-spawn resolves the compiled.jsrather than the.tssource under swc-jest. MarkedTODO: remove when PR #148 lands.@cdktn/cli-core- extratransformIgnorePatternsfortemplates/(sscaff template hooks rely on sloppy-mode globals) andmoduleFileExtensions: ['js','ts','tsx']override (sscaff in node_modules ships both.tssource and compiled.js).cdktn-cli- samemoduleFileExtensionsoverride (sscaff again).Checklist