CLI Reference¶
Usage: readme-assert [options]
Options:
--file, -f readme.md file to read
--main, -m Entry point of the module
--auto, -a Auto discover test code blocks
--all, -l Run all supported code blocks
--require, -r Require a module before running [array]
--import, -i Import a module before running [array]
--print-code, -p Print the transformed code
--version, -v Show version number
-h, --help Show help
Examples¶
Run tests in the current directory's readme:
Specify a file:
Auto-discover test blocks:
Print the transformed code (useful for debugging):
Using --require¶
The --require flag loads a module before test execution. This is useful
for setting up environments like jsdom or registering transpilers like
Babel:
readme-assert --require jsdom-global/register
readme-assert --require @babel/register --main ./src/index.js
readme-assert --require ./test-setup.js
--require modules are passed directly to node --require, so they
must be CommonJS modules that run synchronously.
Using --import¶
The --import flag is the ESM equivalent of --require:
Using --main¶
By default, readme-assert resolves imports of your package name using
the main or exports field in package.json. Use --main to
override:
Module Detection¶
readme-assert detects whether your code blocks use ESM or CJS:
- ESM imports/exports →
.mjstemp file with staticimport assert require()calls →.cjstemp file withconst assert = require(...)- Neither →
.mjstemp file withawait import()(top-level await)
When --require is passed and the code has no CJS syntax, readme-assert
downgrades to CJS so that require hooks work correctly.