Date: 2025-12-13 Status: Accepted
Decision Makers: Maintainer Tags: documentation, testing, jsdoc
Bedrock generates documentation from TSDoc comments (ADR-004). JSDoc @example
blocks demonstrate API usage but can become stale when implementations change.
Publishing documentation with broken examples undermines user trust and causes
frustration. Good intentions aren't enough - without tooling, regressions are
inevitable.
Use generate-jsdoc-example-tests to generate executable tests from
@example comments, combined with typedoc-plugin-replace-text to strip test
assertions from published documentation.
This ensures:
- CI fails if any
@exampleis incorrect - Published docs show clean usage examples (no
expect()calls)
- Required: Public API functions used in documentation generation
- Encouraged: Any function with an
@exampletag
- Documentation cannot be published with broken examples
- Single source of truth (examples are both docs and tests)
- Explicit imports in examples help users know where to import from
- Aligns with TDD culture (ADR-003)
- Verbose examples (explicit imports required in every
@example) - Two-tool workflow (gen-jet for tests, TypeDoc replace-text for clean output)
- Contributors must learn the
@exampleformat requirements
Maintain @example blocks for documentation and separate unit tests for
verification.
Rejected because: Examples and tests inevitably drift. Without automated enforcement, regressions will occur regardless of good intentions.
Trust code review to catch stale examples.
Rejected because: Manual processes don't scale and are error-prone. Tooling provides consistent enforcement.
Accept that some examples may be incorrect.
Rejected because: Broken documentation erodes user trust and contradicts the project's quality standards.
Examples must use fenced code blocks. Import the module being demonstrated; the
expect function is provided by the test generator's header:
/**
* @example
*
* ```ts
* import { myFunction } from "./module";
*
* const result = myFunction();
* expect(result).toBe(expected);
* ```
*/The typedoc-plugin-replace-text strips vitest imports and assertions:
{
"replaceText": {
"replacements": [
{
"pattern": ".*import.*from [\"']vitest[\"'].*\\n",
"replace": ""
},
{ "pattern": ".*expect\\(.*\\n", "replace": "" }
]
}
}- ADR-003: Testing Strategy (TDD mandatory, 100% coverage)
- ADR-004: Documentation Site (TSDoc generates documentation)