UNPKG

2.52 kBMarkdownView Raw
1<p align="center">
2 <br>
3 <br>
4 <img src="xv.svg" alt="xv" height=50>
5 <br>
6 <br>
7 <br>
8</p>
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[![install size](https://packagephobia.com/badge?p=xv)](https://packagephobia.com/result?p=xv)
12
13## Features
14
15- 🐦 __Lighweight__ - [`40 LOC`](https://github.com/typicode/xv/blob/main/src/bin.ts), with zero dependencies
16- __Modern__ - native ESM support
17- 🔰 __Simple & straightforward__ - no API to learn, zero-config
18- __Super fast__ - with almost zero abstractions, `xv` is as fast as Node
19- 🦉 Used in [lowdb](https://github.com/typicode/lowdb), [steno](https://github.com/typicode/steno) and other [awesome projects](https://github.com/typicode/xv/network/dependents)
20- 💖 [GitHub Sponsors](https://github.com/sponsors/typicode)
21
22## Install
23
24```sh
25npm install xv --save-dev
26yarn add xv --dev
27```
28
29## Usage
30
31_`xv` is extremely simple, there's nothing else to learn._
32
33Create a test file `src/add.test.js` and use Node's built-in [`assert`](https://nodejs.org/api/assert.html) module:
34
35```js
36import { strict as assert } from 'assert' // Node <=16
37// import assert from 'assert/strict' // Node >=16
38
39export function testAdd() {
40 assert.equal(1 + 2, 3)
41}
42```
43
44Edit `package.json`:
45
46```js
47// package.json
48{
49 "scripts": {
50 "test": "xv src"
51 }
52}
53```
54
55Run your tests:
56
57```sh
58npm test # run all test files in ./src
59npx xv src/add.test.js # run a single test file
60```
61
62## Convention
63
64When provided a directory, `xv` will look for files named `*.test.js` (or `test.js`) and run exported functions sequentially.
65
66## TypeScript
67
68To 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__.
69
70For example, assuming your compiled files are in `lib/` :
71
72```js
73// tsconfig.json
74{
75 "compilerOptions": {
76 "outDir": "./lib"
77 }
78}
79```
80
81Edit `package.json` to run `xv` after `tsc`:
82
83```js
84// package.json
85{
86 "scripts": {
87 "build": "rm -rf lib && tsc",
88 "test": "npm run build && xv lib" // run test files in lib/
89 }
90}
91```
92
93If you're publishing to npm, exclude test files:
94
95```js
96// package.json
97{
98 "files": [
99 "lib",
100 // exclude compiled test files
101 "!lib/**/*.test.js",
102 "!lib/**/test.js"
103 ]
104}
105```
106
107You can run `npm publish --dry` to check that it's working (nothing is going to be published with the `--dry` option).