@forge-ts/doctest
v0.23.1
Published
TSDoc @example block extractor and test runner for forge-ts
Readme
@forge-ts/doctest
Executable documentation testing for the forge-ts toolchain. Extracts @example code blocks from TSDoc comments and runs them as tests.
When to use this package
Most users should install @forge-ts/cli instead and use npx forge-ts test. This package is for programmatic use.
npm install @forge-ts/doctestHow it works
- Walks your TypeScript AST to find
@exampleblocks in TSDoc comments - Generates virtual test files with auto-injected imports
- Adds inline source maps pointing back to your original source
- Converts
// => valuecomments into assertions - Runs tests via Node 24's built-in
node:testrunner
Example
import { loadConfig } from "@forge-ts/core";
import { doctest } from "@forge-ts/doctest";
const config = await loadConfig();
const result = await doctest(config);
if (!result.success) {
console.error(`${result.errors.length} doctest(s) failed`);
process.exit(1);
}Part of forge-ts
See the main repo for full documentation.
License
MIT
