Skip to content
/ xv Public

🙅‍♀️ ✌️ fastest test runner

License

Notifications You must be signed in to change notification settings

typicode/xv

Repository files navigation


xv

Node.js CIinstall size

A tiny (~80 lines of TypeScript) test runner focused on simplicity and speed

$ xv./src
src/add.test.js: 0.103ms
src/sub.test.js: 0.064ms

Extracted fromlowdb.Fastest test runner according to thisbenchmark.

Why

If you've used other test runners, you probably have spent a significant amount of time reading docs, configuring, maintaining and debugging them.

By being extremely simple, xv gets out of your way and lets you be productive faster. In fact, the whole project documentation fits in this page;)

Install

npm install xv --save-dev

Usage

Create a test file and use Node's built-inassertmodule:

// src/add.test.js
importassertfrom'node:assert/strict'
importaddfrom'./add.js'

// This is plain Node code, there's no xv API
exportfunctiontestAdd(){
assert.equal(add(1,2),3)
}

Editpackage.json:

{
"scripts":{
"test":"xv src"
}
}

Run tests:

npmtest#run all test files in./src
npx xv src/add.test.js#run a single test file

Convention

By default, xv will look for files named:*.test.js,test.js,*.test.tsandtest.ts

TypeScript

With TypeScript +ts-node

npm install ts-node --save-dev
{
"scripts":{
"test":"xv --loader=ts-node/esm src"
}
}

With TypeScript only

Compile your.tsfiles usingtscand runxvon compiled.jsfiles.

For example, assuming your compiled files are inlib/,editpackage.jsonto runxvaftertsc:

{
"scripts":{
"test":"tsc && xv lib"
}
}

If you're publishing to npm, editpackage.jsonto exclude compiled test files:

{
"files":[
"lib",
"!lib/**/*.test.js",
"!lib/**/test.js"
]
}

Common JS

// src/add.test.js
constassert=require('assert').strict;
constadd=require('./add')

exports.testAdd=function(){
assert.equal(add(1,2),3)
}

Watch mode

xv doesn't have a watch mode. If the feature is needed, it's recommended to use tools likewatchexecorchokidar-clito re-run xv when there are changes.