Skip to content

examples: nothing runs the examples' test scripts or validates example config against package.json #428

Description

@sakul-learning

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 with Module <rootDir>/setup.js in the setupFilesAfterEnv option was not found; it is the only one of the 22 examples missing the setup.js its config requires.
  • examples/typescript/aws-move — ts-jest cannot compile the test file under typescript ~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:

  1. Config-consistency check in tools/lint-examples.mjs (or a sibling script wired into CI): assert that the command in an example's cdktf.json app references only packages the example declares, and that any Jest preset/transform entry in jest.config.js resolves from the example's package.json — i.e. ts-jest preset ⇒ a ts-jest dependency. This turns the entire drift class into a CI failure instead of a latent trap.

  2. Run the examples' test target, either by adding it to tools/build-example.mjs or as a separate low-cost job. Current signal is low — all 22 __tests__/main-test.ts are it.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:111 writes app: "npx ts-node main.ts" into a temporary cdktf.json that is only ever used with cdktn get.
  • packages/@cdktn/cli-core/src/test/lib/terraform-parallelism.test.ts:151,185,221,252,285,317 pass synthCommand: "npx ts-node main.ts" into a mocked synth.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions