readme-assert
v10.1.3
Published
Run code blocks in your readme as tests
Downloads
2,278
Maintainers
Readme
Tag a code block, add an assertion comment, done:
```javascript test
import { add } from 'my-package';
add(1, 2); //=> 3
```npx readme-assertImports of your package name are rewritten to your local source automatically.
Install
npm install --save-dev readme-assertAssertions
let a = 1;
a; //=> 1const fail = () => {
throw new TypeError('bad input');
};
fail(); //=> TypeError: bad inputawait Promise.resolve(true); //=> trueSee the full assertion syntax for throws, rejects, console.log, and more.
TypeScript
TypeScript blocks work out of the box — types are stripped before execution:
const sum: number = 1 + 1;
sum; //=> 2Auto-discover
Skip the test tag entirely. With --auto, any block containing an
assertion comment is a test:
readme-assert --autoDocumentation
Full docs at readme-assert.laat.dev:
- Assertion syntax — all comment forms
- Code block tags — tagging, grouping, and modes
- Import renaming — how package imports are resolved
- CLI reference — all flags and options
License
MIT
