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

Why

  • User-friendly - zero-config, no API to learn, simple convention
  • 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

Used in lowdb, steno and other awesome projects.

A word on releases

xv being very simple by design, there probably won't be frequent updates (which is a good thing as it means less work for you). However, this doesn't mean that the project is not maintained or not used, it's just (probably) feature complete as it is :)

xv will be updated to follow the latest Node API changes or improvements.

Install

npm install xv --save-dev

Usage

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 

Convention

When provided a directory, xv will look for files named *.test.js or test.js and run exported functions sequentially.

TypeScript

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.jsonto exclude compiled test files:

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

Watch mode

xv doesn't integrate a watch mode, instead if the feature is needed, it's recommended to use tools like watchexec or chokidar-cli.