- User-friendly - zero-config, no API to learn, simple conventions
- Extremely lighweight - only
40 lines of code
and no dependencies - Super fast - with almost zero abstractions,
xv
is as fast as Node - Stable - low maintenance and probably feature complete ;)
Used in lowdb, steno and other awesome projects.
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 a directory, xv
will look for files named *.test.js
or test.js
and run exported functions sequentially.
To use xv
with TypeScript, compile your .ts
files and run xv
directly on compiled .js
. This has the benefit of testing code that is really published.
For example, assuming your compiled files are in lib/
, edit package.json
to run xv
after tsc
:
{
"scripts": {
"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"
]
}
You can run npm publish --dry
to check that it's working (nothing is going to be published with the --dry
option).