UNPKG

2.59 kBMarkdownView Raw
1<h1 align="center">
2 <br>
3 <br>
4 <img src="xv.svg" alt="xv" height=50>
5 <br>
6 <br>
7 <br>
8</h1>
9
10[![Node.js CI](https://github.com/typicode/xv/actions/workflows/node.js.yml/badge.svg)](https://github.com/typicode/xv/actions/workflows/node.js.yml)
11
12Setting up and maintaining a test framework can sometimes be complex and time consuming. I've created `xv` to be a low maintainance, easy to setup and learn test lib/CLI. Great for small and medium projects.
13
14## Features
15
16- Lightweight and fast
17- Zero-config, zero-API, simple
18- Used in [lowdb](https://github.com/typicode/lowdb) and [steno](https://github.com/typicode/steno)
19
20_Requires Node v12.20.0+_
21
22## Install
23
24Install `xv`:
25
26```sh
27npm install xv --save-dev
28yarn add xv --dev
29```
30
31## Usage
32
33Create a test file `src/add.test.js` (or `src/test.js`)and use Node's built-in [`assert`](https://nodejs.org/api/assert.html) module.
34
35If you need your tests to be compatible with **Node <=16**:
36
37```js
38import { strict as assert } from 'assert'
39
40export function testAdd() {
41 assert.equal(1 + 2, 3)
42}
43```
44
45If you're targeting **Node >=16**, you can simplify your code:
46
47```js
48import { equal } from 'assert/strict'
49
50export function testAdd() {
51 equal(1 + 2, 3)
52}
53```
54
55In `package.json`, edit `test` script:
56
57```json
58{
59 "scripts": {
60 "test": "xv src"
61 }
62}
63```
64
65```sh
66npm test # run all test files in ./src
67npx xv src/add.test.js # run a single test file
68```
69
70**That's all there is to know... for real :)**
71
72_Note_ `xv` is a pure ESM package, read [this](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
73
74## Early access for Sponsors
75
76For a limited time `xv` is available to Sponsors only. Once the goal of 70 sponsors is reached (currently 57), I'll release it under MIT for everyone 🎉
77
78**If you like this project and my work, please help me reach this goal by [becoming a sponsor here](https://github.com/sponsors/typicode). Thank you!**
79
80_Note: if you're already sponsoring me via [husky](https://github.com/typicode/husky), feel free to use `xv` in any type of project._
81
82## TypeScript
83
84If you're using TypeScript, compile your `.ts` and run `xv` directly on compiled `.js` files.
85
86Assuming you have the following `tsconfig.json`:
87
88```json
89{
90 "compilerOptions": {
91 "outDir": "./lib"
92 }
93}
94```
95
96Edit `package.json` to exclude test files from being published andrun `tsc` before `xv`:
97
98```js
99{
100 "files": [
101 "lib",
102 // exclude test files
103 "!lib/**/*.test.js",
104 "!lib/**/test.js"
105 ],
106 "scripts": {
107 "build": "rm -rf lib && tsc",
108 "test": "npm run build && xv lib"
109 }
110}
111```