- User-friendly - zero-config, no API to learn, simple convention, ESM support
- Extremely lighweight - only
40 lines of code
and no dependencies - Blazingly fast - with almost zero abstractions, xv is as fast as Node
- Stable - very low maintenance
- Unix philosophy™ -
do one thing well
, xv is only a test runner
lowdb (local JSON database), steno (fast file writer) and other awesome projects are using xv to run tests.
The project being very simple by design, there probably won't be frequent updates to the code (which is a good thing for you, unless you like Dependabot alerts and updating devDependencies). It will be updated to support latest Node releases and implement potential improvements.
tl;dr xv is maintained and used even though code updates may not be recent.
npm install xv --save-dev
Create a test file and use Node's built-in assert
module:
// src/add.test.js
import { strict as assert } from 'assert'
export function testAdd() {
assert.equal(1 + 2, 3)
}
Edit package.json
:
{
"scripts": {
"test": "xv src"
}
}
Run all test files:
npm test
Run a single test file:
npx xv src/add.test.js
When provided with a directory, xv will look for files named *.test.js
or test.js
and run exported functions sequentially.
To test TypeScript code, compile your .ts
files and run xv
on compiled .js
files.
For example, assuming your compiled files are in lib/
, edit package.json
to run xv
after tsc
:
{
"scripts": {
- "test": "xv src"
+ "test": "tsc && xv lib"
}
}
If you're publishing to npm, edit package.json
to exclude compiled test files:
{
"files": [
"lib",
+ "!lib/**/*.test.js",
+ "!lib/**/test.js"
]
}
xv doesn't integrate a watch mode. If the feature is needed, it's recommended to use tools like watchexec or chokidar-cli to re-run xv when there are changes.