You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit b0bc521
Browse filesBrowse the repository at this point in the historyBrowse files
docs: describe testing generated code through an example
Record the shape the complex extension flat contract test follows: the
StructureDefinition goes into an example's structure-definitions, its canonical
URL becomes a tree-shake root in that example's generate.ts, and the test is a
plain consumer of ./fhir-types — static imports plus snapshots read from disk.
The Makefile target's generate → typecheck → test order is what keeps such tests
small, so it is spelled out along with what it cannot cover.
When a change affects what generated code looks like or how it behaves for a consumer, prefer a test in `examples/` over an in-memory generator test in `test/`. Generation happens once, up front, as a build step — the test is then an ordinary consumer of the result.
153
+
154
+
1. Drop the StructureDefinition into the example's `structure-definitions/` (naming it `<id>.structuredefinition.json`)
155
+
2. Add its canonical URL as a tree-shake root in that example's `generate.ts`, in the existing local generation step — one type tree, no second output directory
156
+
3. Write `examples/<example>/<topic>.test.ts` that imports the generated profiles with plain **static** imports
157
+
4. Snapshot the generated modules by reading them from disk with `Bun.file(...).text()`, so a change to the emitted types shows up in the diff next to the behaviour change
158
+
159
+
The example's Makefile target supplies the rest, in this order:
Thatorderiswhatmakesthetestsmall: `tsc --project` covers the generated code *and* the test file, so `@ts-expect-error` in a test is a real assertion — a directive that stops erroring fails the build. The test never constructs an `APIBuilder`, writes a temp directory, or reaches for `ts.createProgram`/`Bun.Transpiler`.
169
+
170
+
The one thing this cannot express is "generated code must not compile" — the project typecheck fails for everyone, whatever the test says. Record that kind of defect with an in-memory test under `test/api/write-generator/` instead, and move it into the example once the fix lands.
0 commit comments