Repository navigation
Description
Problem
Nothing in CI runs the TypeScript examples' own test scripts, and nothing validates an example's Jest configuration against the dependencies it declares. As a result the examples can carry a Jest setup that cannot start at all without any check noticing.
The examples' test script is never invoked by CI. Each example defines one (for example examples/typescript/aws-import/package.json:13 → "test": "jest"), but the examples workflow only drives four Nx targets. tools/build-example.mjs:83-88 runs:
await runInExample(`reinstall`);
await runWithRetry(`build`);
await runInExample(`beforeSynth`);
await runInExample(`synth`);No test target. The PR unit-test workflow selects only projects tagged unit-test / unit-test:terraform, which the example packages are not tagged with. So the example suites are dead weight from CI's point of view.
Concretely, this hides at least two current failures, both in examples that set preset: "ts-jest":
examples/typescript/azure-service-bus-queue-trigger— Jest aborts withModule <rootDir>/setup.js in the setupFilesAfterEnv option was not found; it is the only one of the 22 examples missing thesetup.jsits config requires.examples/typescript/aws-move— ts-jest cannot compile the test file undertypescript ~6.0.0(TS5107: Option 'moduleResolution=node10' is deprecated, forced by ts-jest internals).
tools/lint-examples.mjs does not cover this class of drift. It checks that each example has a package.json whose name matches @examples/<language>-<path>, that Nx recognises that project name, and that cdktf.json has no projectId / userId / sendCrashReports. It never compares cdktf.json's app command with the example's package.json dependencies. So an example left on "app": "npx ts-node main.ts" with no ts-node dependency, or one carrying a ts-jest preset with no ts-jest dependency, passes every existing check. That is precisely the drift class of #419 (migrating the examples from ts-node to tsx) and #182 (examples still referencing cdktf).
Suggested fix
Two independent halves; the second is likely the higher-value one:
-
Config-consistency check in
tools/lint-examples.mjs(or a sibling script wired into CI): assert that the command in an example'scdktf.jsonappreferences only packages the example declares, and that any Jestpreset/transformentry injest.config.jsresolves from the example'spackage.json— i.e.ts-jestpreset ⇒ ats-jestdependency. This turns the entire drift class into a CI failure instead of a latent trap. -
Run the examples'
testtarget, either by adding it totools/build-example.mjsor as a separate low-cost job. Current signal is low — all 22__tests__/main-test.tsareit.todo("should be tested")skeletons with the real assertions commented out — so the initial value is validating the Jest/ts-jest/tsconfig wiring rather than catching behavioural regressions. Worth deciding deliberately rather than by omission.
Related drift, currently harmless
Stale ts-node strings remain in fixtures after the tsx migration. They do not execute an app command today, so they are not bugs, but they are the same class of drift a consistency check would pin down:
packages/@cdktn/hcl2cdk/test/globalSetup.ts:111writesapp: "npx ts-node main.ts"into a temporarycdktf.jsonthat is only ever used withcdktn get.packages/@cdktn/cli-core/src/test/lib/terraform-parallelism.test.ts:151,185,221,252,285,317passsynthCommand: "npx ts-node main.ts"into a mocked synth.
Activity