✨ Compile doc code fences into tests
Every `ts`-tagged fence in README.md / CONTRIBUTING.md now becomes an executed `node:test` case in a gitignored generated file, so a documented example cannot drift from the API. The generator hoists and merges the leading imports, rewrites the library specifier to the `#test-tiny-pattern-ts` alias, and rejects a fence with no describing paragraph or one that re-imports a prelude module. CI regenerates via `pretest:ci`; `create:doc-tests` runs the generator, formats, then typechecks the output against a scoped tsconfig that relaxes `noUnusedLocals`. c8's default excludes already omit the generated `*.test.ts`, so `test:ci` is unchanged.
This commit is contained in:
1 parent
d1963b0329
commit
30d97a9209
15 files changed
+1180
-8
No files matched your search
+18
-3
@@ -22,6 +22,8 @@ the rules so agents and humans don't diverge.
|
||||
- **Test:** `npm run test`, `npm run test:ci`
|
||||
- **Watch:** `npm run watch` - re-runs tests on file save, humans only
|
||||
- **Checks:** `npm run check`, `npm run fix`
|
||||
- **Doc tests:** `npm run create:doc-tests` — compile the `ts`-tagged fences
|
||||
in the prose docs into executed, gitignored tests
|
||||
- **Verify:** `npm run verify` — the definition of done
|
||||
- **Maintenance:** `npm run maintain` — advisory only
|
||||
- **Individual fixes:** `npm run fix:oxfmt`, `npm run fix:oxlint`
|
||||
@@ -87,6 +89,17 @@ Per [AGENTS.md § Never do](./AGENTS.md#never-do), reach green honestly — fix
|
||||
types, never suppress the checks you can't make pass. Full rationale:
|
||||
[development/testing.md](./development/testing.md).
|
||||
|
||||
## Documentation examples
|
||||
|
||||
Every `ts`-tagged fence in `README.md` / `CONTRIBUTING.md` is compiled into an
|
||||
executed test, so a documented example cannot drift from the API. Describe each
|
||||
fence with the paragraph directly above it (that text becomes the test title),
|
||||
and keep its library import self-contained;
|
||||
`npm run create:doc-tests` regenerates, formats and type-checks the tests under
|
||||
`src/doc-test/__generated__/`. CI runs it automatically via `pretest:ci`, so run
|
||||
it yourself before `npm run verify` when you touched a fence. Why:
|
||||
[development/docs.md](./development/docs.md).
|
||||
|
||||
## Code style and formatting
|
||||
|
||||
`oxfmt` is the formatter and `oxlint` is the linter (with type-aware rules).
|
||||
@@ -115,10 +128,12 @@ intended to run. A `<prefix>:<name>` script is implicitly aggregated by a
|
||||
`<prefix>` script (if one exists) and run by the corresponding lefthook hook or
|
||||
CI step. Pick the prefix that matches the script's lifecycle:
|
||||
|
||||
- `create:*` — front doors of the repo's own workflow; these mutate git state
|
||||
rather than the source. `create:branch` opens a unit of work, `create:finish`
|
||||
- `create:*` — front doors of the repo's own workflow; these produce or mutate
|
||||
workflow artifacts (git state, generated doc-tests) rather than the
|
||||
hand-written source. `create:branch` opens a unit of work, `create:finish`
|
||||
closes the branch half, `create:release` closes the release half
|
||||
(maintainer-only). No bare `create` aggregator on purpose.
|
||||
(maintainer-only), and `create:doc-tests` regenerates the compiled prose
|
||||
examples. No bare `create` aggregator on purpose.
|
||||
- `check:*` — read-only verification; never modifies files. Aggregated by
|
||||
`npm run check`.
|
||||
- `fix:*` — mutating counterpart of a `check:*` script. Aggregated by
|
||||
|
||||
Reference in new issue
Block a user