Coder Social home page Coder Social logo

xv's Introduction

Node.js CI


xv

Features

  • Simple - zero-config, no API to learn, out of the box ESM/CJS support
  • Lightweight - 6kB and no dependencies
  • Magical - simply export test functions, that's all
  • Blazingly fast - with almost zero abstractions, xv is as fast as Node
  • Unix philosophy™ - do one thing well, xv is only a test runner

Used by lowdb (local JSON database), steno (fast file writer) and other awesome projects.

Install

npm install xv --save-dev

Usage

Create a test file and use Node's built-in assert module:

// src/add.test.js
import { strict as assert } from 'assert'
import add from './add.js'

// This is plain Node code, there's no xv API
export function testAdd() {
  assert.equal(add(1, 2), 3)
}

Edit package.json:

{
  "scripts": {
    "test": "xv src"
  }
}

Run all test files:

npm test

Run a single test file:

npx xv src/add.test.js 

Convention

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

TypeScript

To test TypeScript code, compile your .ts files and run xv on compiled .js files.

For example, assuming your compiled files are in lib/, edit package.json to run xv after tsc:

{
  "scripts": {
-   "test": "xv src"
+   "test": "tsc && xv lib"
  }
}

If you're publishing to npm, edit package.json to exclude compiled test files:

{
  "files": [
    "lib",
+   "!lib/**/*.test.js",
+   "!lib/**/test.js"
  ]
}

Common JS

xv can also test CJS code.

// src/add.test.js
const assert = require('assert').strict;
const add = require('./add')

// This is plain Node code, there's no xv API
exports.testAdd = function() {
  assert.equal(add(1, 2), 3)
}

Watch mode

xv doesn't integrate a watch mode. If the feature is needed, it's recommended to use tools like watchexec or chokidar-cli to re-run xv when there are changes.

Status

The project being very simple by design, there probably won't be frequent updates to the code (which is a good thing for you, unless you like Dependabot alerts and updating devDependencies). It will be updated to support latest Node releases and implement potential improvements.

tl;dr xv is maintained and used, even though code updates may not be recent.

xv's People

Contributors

typicode avatar zetaraku avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.