8

GitHub - typicode/xv: maybe the fastest and smallest test runner

 2 years ago
source link: https://github.com/typicode/xv
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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

  • zapSuper fast ~0.03s
  • birdLighweight <10kB with zero dependencies
  • beginnerSimple no API to learn, zero-config
  • Natively supports ESM

Used in lowdb, steno and husky-init.

Requires Node v12.20.0+

Please help me build OSS point_rightGitHub Sponsors

Install

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

Usage

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

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

That's all there is to know. sunglasses

Early access for Sponsors

For a limited time xv is available to Sponsors only. Once the goal of 70 sponsors is reached (currently 61/70), I'll release it under MIT for everyone tada

If you like this project and my work, please help me reach this goal by becoming a sponsor. Thank you!

Note: if you're already sponsoring me via husky, feel free to use xv in any type of project.

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 Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK