Role. You are a senior TypeScript test engineer. Your job here is narrow:
write a consumer smoke test that proves the committed generated tree in
packages/example/src/fhir/ still compiles and wires up against the current
@fhir-dsl/core. This package is a consumer of the generator's output — it
exists to catch breaking changes in core or the generator before they ship.
fhir-dsl is a type-safe FHIR monorepo. @fhir-dsl/example is a
deliberately test-free demo showing what consumers get after running the CLI:
src/fhir/ contains a committed snapshot of generated FHIR R4 + US Core
output, and src/index.ts exercises the public surface (search, read,
transactions, profiles).
Do not test FHIR or DSL behavior here — that belongs in @fhir-dsl/core
and @fhir-dsl/generator. Your tests guard the integration contract.
packages/example/src/index.ts— example consumer code using the generated client. Has deliberate@ts-expect-errorlines at the bottom.packages/example/src/fhir/r4/— committed generated tree (client.ts,resources/,schemas/,profiles/, …).
packages/example/src/index.tspackages/example/src/fhir/r4/client.tspackages/example/src/fhir/r4/index.ts(orresources/index.ts)packages/core/src/fhir-client.ts(the interface the generated client composes with)
None. This is the first test for the package.
Write tests in packages/example/test/. Keep them small and focused:
- Generated
createClientexposes the expected methods. ImportcreateClientfrom./src/fhir/r4/client.js, call it with a baseUrl and a fakefetch, and assert the returned client hassearch,read,transaction,batchas functions. fhir.search("Patient")returns a builder that compiles. Chain.where(...).sort(...).count(1).compile()and assert the resultingCompiledQueryhas the rightmethod,path, and aparamsarray containing the expected entries.- Profile-aware search narrows types. In a
*.test-d.tsfile, assert thatfhir.search("Patient", "us-core-patient")yields a builder whose.execute()promise resolves to{ data: USCorePatientProfile[], ... }(or whichever exact profile type name is generated — read it off the generated file). - Schemas are wired into the client by default. When generated with
--validator, the generatedcreateClientpassesschemas: SchemaRegistryinto core. Import the generatedSchemaRegistry, spy/override nothing, and verify that calling.validate()on a search builder does not throwValidationUnavailableError. - Committed
@ts-expect-errorlines still fire. In a*.test-d.tsfile, re-state one of the negative type assertions frompackages/example/src/index.ts(e.g.fhir.search("Foo")on an unknown resource) with@ts-expect-error, so if core regresses its inference the expect-error becomes a green line and the suite fails.
- Standard Schema V1: https://standardschema.dev/ — the
~standard.validatesignature you'll see exposed by generated schemas. - vitest typecheck integration:
https://vitest.dev/guide/testing-types — how
*.test-d.tsruns. - Generated FHIR R4 resource list: check
packages/example/src/fhir/r4/resources/for what's actually emitted.
- Keep this suite small: the goal is fast early-warning, not coverage. Five tests total is plenty.
- No network. Pass a
fetchstub tocreateClient. - Do not import anything from
packages/example/src/index.tsdirectly if it runs top-levelfhir.search(...)calls — import the generated modules instead so tests don't trigger the demo HTTP code.
- Read the listed files.
- Write
packages/example/test/smoke.test.tsandpackages/example/test/types.test-d.ts. - Gates:
pnpm test pnpm lint pnpm -r typecheck - If a test fails because the generated tree lags behind core, stop and flag it — regenerating the example is a human decision, not a test fix.
- Every scenario above has a corresponding test.
- All three gates green.
- No changes to
packages/example/src/**.
- Running the real generator. The committed tree is the fixture.
- Exercising every generated resource type. One representative (Patient) is enough for the smoke test.
- HTTP-layer testing — that belongs in
@fhir-dsl/runtime.