readme-assert

Run code blocks in your readme as tests

MIT 52 个版本
安装
npm install readme-assert
yarn add readme-assert
pnpm add readme-assert
bun add readme-assert
README

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

版本列表
10.1.3 2026-04-14
10.1.2 2026-04-13
10.1.1 2026-04-13
10.1.0 2026-04-13
10.0.0 2026-04-13
9.0.0 2026-04-13
8.1.0 2026-04-13
8.0.1 2026-04-13
8.0.0 2026-04-12
7.3.0 2026-04-12
7.2.2 2026-04-12
7.2.1 2026-04-12
7.2.0 2026-04-12
7.1.0 2026-04-12
7.0.0 2026-04-03
6.0.3 2019-06-12
6.0.2 2019-06-11
6.0.1 2019-06-11
6.0.0 2019-06-11
5.0.6 2017-09-08
5.0.5 2017-04-11
5.0.4 2017-04-11
5.0.3 2017-04-11
5.0.2 2016-09-09
5.0.1 2016-09-09
5.0.0 2016-07-12
4.0.6 2016-06-05
4.0.5 2016-06-05
4.0.4 2016-05-08
4.0.3 2016-04-30
4.0.2 2016-04-23
4.0.1 2016-04-22
4.0.0 2016-04-22
3.1.2 2016-04-22
3.1.1 2016-04-18
3.1.0 2016-04-18
3.0.2 2016-04-17
3.0.1 2016-04-17
3.0.0 2016-04-17
2.2.2 2016-04-16
2.2.1 2016-04-15
2.2.0 2016-04-15
2.1.5 2016-04-14
2.1.4 2016-04-13
2.1.3 2016-04-12
2.1.2 2016-04-10
2.1.1 2016-04-10
2.1.0 2016-04-10
2.0.1 2016-03-15
2.0.0 2016-03-14
1.0.1 2016-03-02
1.0.0 2016-01-29