mohnuris / xv

:x: :heavy_check_mark: A simple, fast and small test runner with native ESM support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool



xv


Node.js CI

Setting up and maintaining 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

  • Super fast ~0.03s
  • 🐦 Lighweight <50 LOC with zero dependencies
  • 🔰 Simple no API to learn, zero-config
  • Modern ESM support without extra config

Used in lowdb, steno and husky-init.

Requires Node v12.20.0+

Please help me build OSS 👉 GitHub Sponsors

Install

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

Usage

Create a test file and use Node's built-in assert module:

// src/add.test.js (or src/test.js)
import { strict as assert } from 'assert' // Node <=16
// import { equal } from 'assert/strict'  // Node >=16

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

Edit 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 so simple that there's nothing else to learn 😎

TypeScript

If you're using TypeScript, compile your .ts and run xv directly on compiled .js files.

Assuming you have the following tsconfig.json:

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

Edit package.json to exclude test files from being published and run tsc before xv:

{
  "files": [
    "lib",
    // exclude test files
    "!lib/**/*.test.js",
    "!lib/**/test.js"
  ],
  "scripts": {
    "build": "rm -rf lib && tsc",
    "test": "npm run build && xv lib"
  }
}

About

:x: :heavy_check_mark: A simple, fast and small test runner with native ESM support

License:MIT License


Languages

Language:JavaScript 96.0%Language:Shell 4.0%