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 |
|
12 | Setting 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 |
|
24 | Install `xv`:
|
25 |
|
26 | ```sh
|
27 | npm install xv --save-dev
|
28 | yarn add xv --dev
|
29 | ```
|
30 |
|
31 | ## Usage
|
32 |
|
33 | Create 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 |
|
35 | If you need your tests to be compatible with **Node <=16**:
|
36 |
|
37 | ```js
|
38 | import { strict as assert } from 'assert'
|
39 |
|
40 | export function testAdd() {
|
41 | assert.equal(1 + 2, 3)
|
42 | }
|
43 | ```
|
44 |
|
45 | If you're targeting **Node >=16**, you can simplify your code:
|
46 |
|
47 | ```js
|
48 | import { equal } from 'assert/strict'
|
49 |
|
50 | export function testAdd() {
|
51 | equal(1 + 2, 3)
|
52 | }
|
53 | ```
|
54 |
|
55 | In `package.json`, edit `test` script:
|
56 |
|
57 | ```json
|
58 | {
|
59 | "scripts": {
|
60 | "test": "xv src"
|
61 | }
|
62 | }
|
63 | ```
|
64 |
|
65 | ```sh
|
66 | npm test # run all test files in ./src
|
67 | npx 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 |
|
76 | For 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 |
|
84 | If you're using TypeScript, compile your `.ts` and run `xv` directly on compiled `.js` files.
|
85 |
|
86 | Assuming you have the following `tsconfig.json`:
|
87 |
|
88 | ```json
|
89 | {
|
90 | "compilerOptions": {
|
91 | "outDir": "./lib"
|
92 | }
|
93 | }
|
94 | ```
|
95 |
|
96 | Edit `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 | ```
|