A new zero-config test runner for the true minimalists

Overview


xv

Why

  • User-friendly - zero-config, no API to learn, simple conventions
  • Extremely lighweight - only 40 lines of code and no dependencies
  • Super fast - with almost zero abstractions, xv is as fast as Node
  • Stable - low maintenance and probably feature complete ;)

Used in lowdb, steno 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'

export function testAdd() {
  assert.equal(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 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/, edit package.json to run xv after tsc:

{
  "scripts": {
    "test": "tsc && xv lib"
  }
}

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

{
  "files": [
    "lib",
    "!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).

Comments
  • Is it possible to export run?

    Is it possible to export run?

    My scenario is like this: I need to run a mock server before the test starts. The port of this server will be returned randomly via a function, so I need to pass the port in as an environment variable when xv is run. This means I need to execute xv inside a file instead of the command line. So is it possible to export the run method to make this happen?

    opened by linbuxiao 6
  • ts-node `runTestFile` problem

    ts-node `runTestFile` problem

    Thanks for amazing library.

    I'm testing v2, the runTestFile() uses pathToFileURL(file).toString() which behave differently when running withts-node loader.

    {
    	"scripts": {
    		"test": "xv --loader=ts-node/esm ./src"
    	},
    	"devDependencies": {
    		"ts-node": "~10.9.0",
    		"typescript": "~4.9.0",
    		"xv": "~2.0.0"
    	}
    }
    
    // ./src/test.ts
    import assert from 'node:assert/strict';
    
    export function foo(): void {
    	assert.strictEqual(true, false)
    }
    

    I'm logging output of pathToFileURL(file).toString().

    xv --loader=ts-node/esm ./src
    

    Test wont run, if (typeof value === 'function') is skipped, there is only default export from pathToFileURL(file).toString().

    src/test.ts
    + [Module: null prototype] { default: { foo: [Function: foo] } }
    

    Compiled ts works.

    tsc && xv ./lib
    
    lib/test.js
    + [Module: null prototype] {
    +  __esModule: true,
    +  default: { foo: [Function: foo] },
    +  foo: [Function: foo]
    + }
    AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
    
    true !== false
    
    opened by xseman 5
  • Error handling in the pre-commit hook

    Error handling in the pre-commit hook

    Hello @typicode👋

    First of all, I appreciate your awesome work.

    Let me get to the point, I have one problem that related to pre-commit hook. That cannot stop commit when failed test at pre-commit. This reason is because xv uses console.error for error output, I am assuming.

    I would like to know a good solution to this problem, if any.

    thank you.

    opened by hikiroom 3
  • About dynamic runtime exports in CommonJS

    About dynamic runtime exports in CommonJS

    let testCases = [ /* ... */ ]
    
    /* works */
    exports.testAll = async () => {
      await Promise.all(testCases).map(async item => { /**/  })
    }
    
    /* runtime exports can't be recognized */
    testCases.forEach(item => {
      exports[item.xxx] = async () => { /* ... */ }
    })
    

    I'm consider a PR but not sure which would be the best approach:

    1. ignore this
    2. add a nextTick and display an explicit warning
    3. add a nextTick and recognize that for the user
    opened by fritx 1
  • Update README.md

    Update README.md

    The alternative import statement in the Usage section should be:

    import assert from 'assert/strict'  // Node >=16
    

    instead of:

    import { equal } from 'assert/strict'  // Node >=16
    

    For the following code to work:

    export function testAdd() {
      assert.equal(1 + 2, 3)
    }
    opened by zetaraku 1
  • export run method

    export run method

    #6

    package.json has exported index.js, but in fact the file does not exist. Adding this file makes xv available within the file.

    Usage

    xv(<PATH>)
    
    opened by linbuxiao 0
Releases(v2.1.1)
Owner
null
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
A low-feature, dependency-free and performant test runner inspired by Rust and Deno

minitest A low-feature, dependency-free and performant test runner inspired by Rust and Deno Simplicity: Use the mt test runner with the test function

Sondre Aasemoen 4 Nov 12, 2022
A leetcode workspace template with test case runner for JavaScript/TypeScript programmers.

leetcode-typescript-workspace English | 简体中文 A vscode workspace template with test case runner script for JavaScript/TypeScript programmers using exte

null 10 Dec 13, 2022
A simple tap test runner that can be used by any javascript interpreter.

just-tap A simple tap test runner that can be used in any client/server javascript app. Installation npm install --save-dev just-tap Usage import cre

Mark Wylde 58 Nov 7, 2022
True P2P concept for your p2p powered website/app/client. MSC/MEP (Multiple Strategy Concept/Multiple Entry Points)

TRUE P2P CONCEPT - Lets redecentralize the web This repo is just conceptual. Active development of the endproduct (TRUE P2P) happens here https://gith

Bo 6 Mar 29, 2022
RenderIf is a function that receives a validation as a parameter, and if that validation is true, the content passed as children will be displayed. Try it!

RenderIf RenderIf is a function that receives a validation as a parameter, and if that validation is true, the content passed as children will be disp

Oscar Cornejo Aguila 6 Jul 12, 2022
A custom element that helps save alienated player API's to bring back their true inner HTMLMediaElement API

A custom element that helps save alienated player API's to bring back their true inner HTMLMediaElement API

Wesley Luyten 5 Oct 14, 2022
📦 🍣 Zero-config JS bundler for ESM, CommonJS, and .d.ts outputs

pkgroll Write your code in ESM & TypeScript and bundle it to get ESM, CommonJS, and type declaration outputs with a single command! Features Zero conf

hiroki osame 153 Dec 23, 2022
📦 🍣 Zero-config JS bundler for ESM, CommonJS, and .d.ts outputs. (Forked from pkgroll)

?? ?? puild (A fork of pkgroll) Write your code in ESM & TypeScript and bundle it to get ESM, CommonJS, and type declaration outputs with a single com

ʀᴀʏ 6 Sep 6, 2022
Forked from hayes0724/shopify-packer Modern development tool for Shopify using Webpack 5. Easy to extend and customize, zero build config, compatible with Slate and existing websites.

Shopify Packer Modern development tool for Shopify using Webpack 5. Easy to extend and customize, zero build config, comes with starter themes and com

Web & Mobile | eCommerce | Full-Stack Developer 4 Nov 24, 2022
Zero-config PWA Plugin for VitePress

Zero-config PWA Plugin for VitePress ?? Features ?? Documentation & guides ?? Zero-Config: sensible built-in default configs for common use cases ?? E

Vite PWA 10 Dec 1, 2022
Vite plugin to client bundle i18next locales composited from one to many json/yaml files from one to many libraries. Zero config HMR support included.

vite-plugin-i18next-loader yarn add -D vite-plugin-i18next-loader Vite plugin to client bundle i18next locales composited from one to many json/yaml f

AlienFast 4 Nov 30, 2022
Zero Two Bot,A fully Modular Whatsapp Bot to do everything possible in WhatsApp by Team Zero Two

?? ???????? ?????? ???? ?? A Moduler WhatsApp Bot designed for both PM and Groups - To take your boring WhatsApp usage into a whole different level. T

Sam Pandey 69 Dec 25, 2022
Multiplies a number by zero. Useful for when you need to multiply a number by zero

multiply-by-zero Multiplies a number by zero. Useful for when you need to multiply a number by zero Please consider checking out the links of this pro

Dheirya Tyagi 2 Jul 3, 2022
🏆 2nd Runner Up 🏆 at Vividthata A Blend of ideas By NIT Hamirpur

Index Problem Statement Solution Proposed How it Works Challenges we faced Running Locally Demonstration Glimpse Problem Statement It is often the cas

null 3 Nov 22, 2022
A Jest runner that runs tests directly in bare Node.js, without virtualizing the environment.

jest-light-runner A Jest runner that runs tests directly in bare Node.js, without virtualizing the environment. Comparison with the default Jest runne

Nicolò Ribaudo 193 Dec 12, 2022
Jester is a test-generation tool to create integration test code.

Code Generator for Integration Tests Introduction Welcome to Jester: An easy-to-use web application that helps you create and implement integration te

OSLabs Beta 54 Dec 12, 2022