Imagine a world where you can just vitest run README.md!!! ddtds uses your existing test and TypeScript config to run and typecheck code examples in Markdown and JSDoc comments
~/coding/ddtds pnpm exec vitest run README.md
✓ readme README.md (1 test) 49ms
✓ README.md:23 49msrender(<p>Hello</p>);
expect(screen.getByText("Hello")).toBeTruthy();ddtds plugs into your test runner, so the docs run alongside your other tests
See architecture if you are interested in how it all works!
Annotations after the fence's language define how a fence is handled
| Annotation | Should compile | Passes when |
|---|---|---|
run |
yes | the fence does not throw |
fail |
yes | the fence throws |
compile_only |
yes | not run |
compile_fail |
no | not run |
skip |
not compiled | not run |
For example, this fence has a fail annotation. It must compile, and it passes because it throws
```ts fail
expect(1).toBe(2);
```By default, test names are file locations. Use a title to set a name for easier filtering
```ts title="adds numbers" run
expect(1 + 1).toBe(2);
```~/coding/ddtds pnpm exec vitest run README.md
✓ readme README.md (1 test) 49ms
✓ adds numbers 49msOne to many comments starting with ddt-setup are included in the following fence and hidden from markdown renderers. Use this for obvious or irrelevant imports
Markdown and JSDoc use <!-- ddt-setup ... -->, MDX uses {/* ddt-setup ... */}
<!-- ddt-setup
import { render, screen } from "@testing-library/react";
-->
```tsx run
render(<p>Hello</p>);
expect(screen.getByText("Hello")).toBeTruthy();
```Can extract code from md and mdx files, and from JSDoc comments in js, ts, jsx, tsx, mjs, mts, cjs and cts source files
Can extract and run these languages: js, ts, jsx, tsx, tsrx, mjs, mts, cjs, cts
Module type served to your framework of choice resolves in the following order
- Fence language (cts means typescript)
- Sniffs for ESM only syntax like static imports
- Nearest Package JSON module type
- Global default in case the type is at what it seems, for example, bundler transforms
- Frameworks decide what to do with the hint. E.g node respects the module type and vitest injects compatibility layers, checks package.json and sniffs import statements
debug level helps troubleshoot what module type a fence resolves to and where's it's generated
The log level is resolved like so
DDT_LOG_LEVELenvironment variablelogLeveloption- Default (
"info")