Capability 014: TypeScript Builds and Coverage¶
Status: Accepted
Context¶
The programmed tests and the scenarios measure the same code, the sources below src/, but run
it in two places. The programmed tests run in Node, and their runner instruments the sources it
loads. The scenarios run in a browser against the bundle of the build, which Node never sees. They
count only if that bundle is instrumented and the counts are collected from the browser and merged
with those of the programmed tests. A line counts as covered if a programmed test or a scenario
reaches it. App.tsx, for example, is rendered by no programmed test, only by a scenario that
opens the page. The server that delivers the bundle to the browser is no code of the project and
does not count.
An instrumented bundle is larger and slower and must never reach a user. It therefore needs a directory of its own, apart from the production bundle. This capability defines the builds and how the TypeScript profile measures the figure of capability 011.
References¶
Details¶
Builds:
| Build | Output | Configuration | Used by |
|---|---|---|---|
| Production | dist/ |
Minified, no instrumentation | build, preview, bdd-test |
| Coverage | build/coverage/ |
As Production, plus instrumentation | coverage |
The container image builds its production bundle on its own and is not affected.
Where the counts come from:
| Programmed tests | Scenarios | |
|---|---|---|
| Where the code runs | Node, with a simulated DOM | A real browser |
| What runs | The modules a test imports | The whole bundle, as a user gets it |
| How it is counted | The test runner instruments each module as it loads it | The coverage build is instrumented and counts in the browser |
| What the counts refer to | The lines of the sources | The lines of the bundle, mapped back to the sources before merging |
Coverage:
| Aspect | Value |
|---|---|
| Metric | Lines |
| Counted | The programmed tests, and the scenarios against the coverage build, merged into one report |
| Excluded | src/main.tsx, the tests, and the generated scenario code |
Functional Requirements¶
coverageruns the programmed tests and the scenarios against the coverage build and reports their counts together, as Details defines.- After each scenario, the counts of the browser are collected for the figure.
build,preview,bdd-test, and the container image use a bundle without instrumentation.- Before the counts are merged, both refer to the lines of the sources, as Details defines.
Non-Functional Requirements¶
None.
Technical Requirements¶
- Vite builds, Vitest runs the programmed tests, Playwright with playwright-bdd runs the scenarios, and nyc maps and merges the counts. The testing and TypeScript guidelines prescribe Vitest and the scenario runner, and the TypeScript CI image provides the browser.
Error Handling¶
None.
Out of Scope¶
- What capability 011 defines for every language
- Coverage in browsers other than the one the scenarios use
Acceptance Criteria¶
- TypeScript frontend: the programmed tests count in the format of Decision 1.
- TypeScript frontend:
coveragebuilds the coverage build into its directory of Details and runs the scenarios against it.buildwritesdist/without instrumentation. - TypeScript frontend: the scenario code collects the browser's counts after each scenario.
- Generated TypeScript frontend, a function reached only by a scenario:
make coveragereports it as covered (manual testtest/manual/generated_coverage.md). - Generated TypeScript frontend, a source file that the programmed tests cover completely:
make coveragereports it as covered completely (manual testtest/manual/generated_coverage.md).
Decisions¶
- istanbul for Vitest and the bundle. Merging needs one format. The browser's counts of an instrumented bundle are istanbul's, so Vitest uses istanbul as well. Consequence: Vitest gives up the V8 provider, which needs no instrumentation.
- A coverage build apart from the production bundle.
An instrumented bundle must never be served to a user or shipped in the image.
Consequence:
coveragebuilds the frontend a second time.