Skip to content
forked from typicode/xv

❌ ✔️ A simple, fast and small test runner with native ESM support

License

Notifications You must be signed in to change notification settings

sandip-gavade/xv

 
 

Repository files navigation



xv


Node.js CI install size

Setting up/updating a test framework can sometimes be complex and time consuming. I've created xv to be a test runner that is low maintainance, easy to setup and use.

xv is great for small and medium projects.

Features

  • 🐦 Lighweight - 40 LOC, with zero dependencies
  • Modern - native ESM support
  • 🔰 Simple & straightforward - no API to learn, zero-config
  • Super fast - with almost zero abstractions, xv is as fast as Node
  • 🦉 Extracted from lowdb
  • 💖 GitHub Sponsors

Install

npm install xv --save-dev
yarn add xv --dev

Usage

Create a test file src/add.test.js and use Node's built-in assert module:

import { strict as assert } from 'assert' // Node <=16
// import assert from 'assert/strict'     // Node >=16

export function testAdd() {
  assert.equal(1 + 2, 3)
}

Edit package.json:

// package.json
{
  "scripts": {
    "test": "xv src"
  }
}

Run your tests:

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

xv is extremely simple, there's nothing else to learn.

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/ :

// tsconfig.json
{
  "compilerOptions": {
    "outDir": "./lib"
  }
}

Edit package.json to run xv after tsc:

// package.json
{
  "scripts": {
    "build": "rm -rf lib && tsc",
    "test": "npm run build && xv lib" // run test files in lib/
  }
}

If you're publishing to npm, exclude test files:

// package.json
{
  "files": [
    "lib",
    // exclude compiled test files
    "!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).

About

❌ ✔️ A simple, fast and small test runner with native ESM support

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 96.1%
  • Shell 3.9%