Skip to content
main
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 


xv

Why

  • User-friendly - zero-config, no API to learn, simple conventions
  • Extremely lighweight - 40 LOC and no dependencies
  • Super fast - with almost zero abstractions, xv is as fast as Node

Used in lowdb, steno and other awesome projects. Supports ESM and TypeScript.

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 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.jsonto 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).