xv

    1.1.1 • Public • Published



    xv


    Node.js CI install size

    Features

    • 🐦 Lighweight - 40 LOC, with zero dependencies
    • Modern - native ESM support
    • 🔰 Simple & straightforward - no API to learn, zero-config
    • Super fast - with almost zero abstractions, xv is as fast as Node
    • 🦉 Used in lowdb, steno and other awesome projects
    • 💖 GitHub Sponsors

    Install

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

    Usage

    xv is extremely simple, there's nothing else to learn.

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

    import { strict as assert } from 'assert' // Node <=16
    // import assert from 'assert/strict'     // Node >=16
    
    export function testAdd() {
      assert.equal(1 + 2, 3)
    }

    Edit package.json:

    // 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

    Convention

    When provided a directory, xv will look for files named *.test.js (or test.js) and run exported functions sequentially.

    TypeScript

    To 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.

    For example, assuming your compiled files are in lib/ :

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

    Edit package.json to run xv after tsc:

    // package.json
    {
      "scripts": {
        "build": "rm -rf lib && tsc",
        "test": "npm run build && xv lib" // run test files in lib/
      }
    }

    If you're publishing to npm, exclude test files:

    // package.json
    {
      "files": [
        "lib",
        // exclude compiled test files
        "!lib/**/*.test.js",
        "!lib/**/test.js"
      ]
    }

    You can run npm publish --dry to check that it's working (nothing is going to be published with the --dry option).

    Install

    npm i xv

    DownloadsWeekly Downloads

    93

    Version

    1.1.1

    License

    MIT

    Unpacked Size

    6.13 kB

    Total Files

    4

    Last publish

    Collaborators

    • typicode