Skip to content

laat/readme-assert

Repository files navigation

readme-assert

readme-assert

npm

Code examples in READMEs go stale. readme-assert runs them as tests so they can't.

Tag a code block, add an assertion comment, done:

```javascript test
import { add } from 'my-package';

add(1, 2); //=> 3
```
npx readme-assert

Imports of your package name are rewritten to your local source automatically.

Install

npm install --save-dev readme-assert

Assertions

let a = 1;
a; //=> 1
const fail = () => {
  throw new TypeError('bad input');
};
fail(); //=> TypeError: bad input
await Promise.resolve(true); //=> true

See 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; //=> 2

Auto-discover

Skip the test tag entirely. With --auto, any block containing an assertion comment is a test:

readme-assert --auto

Documentation

Full docs at readme-assert.laat.dev:

License

MIT

About

Run fenced code blocks in your README as tests — JavaScript, TypeScript, assertion comments, and a portable agent skill

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors