test-runner

0.11.1 · active · verified Sun Apr 19

test-runner is a fully-featured, lightweight command-line test runner designed for full-stack JavaScript engineers to create and test modern, isomorphic code. It operates by taking one or more files, each exporting a `test object model` (TOM) instance, running the contained tests with controlled order and concurrency, and generating a report. Currently at version `0.11.1`, the project is explicitly marked as "Work In Progress," indicating an active development phase with potential for frequent, non-semver compliant breaking changes before a stable `1.0` release. Its key differentiators include native support for both CommonJS and ECMAScript modules, execution in Node.js and headless Chromium for isomorphic testing, and a unique `Tom` API for defining test suites, distinguishing it from runners relying on global functions or specific assertion libraries. It aims to be part of a broader suite of JavaScript testing tools.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up and run basic synchronous and asynchronous tests using `test-runner` in a Node.js CommonJS environment, including an external dependency (`node-fetch`) for API testing.

npm install --save-dev test-runner node-fetch

// test.js
const { Tom } = require('test-runner')
const assert = require('assert').strict
const fetch = require('node-fetch')

const tom = new Tom()

tom.test('Math.random() should return a number between 0 and 1', function () {
  const result = Math.random()
  assert.equal(typeof result, 'number')
  assert.ok(result >= 0 && result <= 1)
})

tom.test('REST API should return the current todo item', async function () {
  const response = await fetch('https://jsonplaceholder.typicode.com/todos/1')
  const todo = await response.json()
  assert.equal(todo.userId, 1)
  assert.equal(todo.title, 'delectus aut autem')
})

module.exports = tom;

// Run from your terminal
// $ npx test-runner test.js

view raw JSON →