test-runner
Fully-featured, lightweight command-line test runner
Last updated 3 years ago by 75lb .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install test-runner 
SYNC missed versions from official npm registry.

view on npm npm module downloads Gihub repo dependents Gihub package dependents Node.js CI js-standard-style

test-runner

This project and documentation are a WIP

Fully-featured, lightweight command-line test runner. Part of a suite of tools to help the full-stack JavaScript engineer create and test modern, isomorphic code.

Synopsis

As input, test-runner takes one or more files each exporting a set of tests. The tests in each file are run with a controllable order and concurrency, a report is printed and the command exits with a non-zero code if anything failed.

This is the general syntax (see here for the full usage guide):

$ test-runner [<options>] <file> ...

Test file basics

A test file is a module (either CommonJS or ECMAScript) which must export a test object model instance. This test file can be run natively (no build or transpilation step required) in Node.js, the browser (in headless Chromium) or both (isomorphic).

Add tests to the model by invoking tom.test with a name and test function. Trivial example. If a test function throws or returns a rejected promise it is considered a fail, otherwise a pass.

const { Tom } = require('test-runner')

const tom = new Tom()

tom.test('A successful sync test', function () {
  return 'This passed'
})

tom.test('A failing sync test', function () {
  throw new Error('This failed')
})

tom.test('A successful async test', async function () {
  return 'This passed'
})

tom.test('A failing async test', async function () {
  throw new Error('This failed')
})

tom.test('Also a failing async test', async function () {
  return Promise.reject(new Error('This failed'))
})

module.exports = tom

Test CommonJS JavaScript using Node.js

In reality, a typical test suite might look more like this. Save this as 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 the test file using test-runner.

$ npx test-runner test.js

Start: 2 tests loaded

✓ synopsis Math.random() should return a number between 0 and 1
✓ synopsis REST API should return the current todo item

Completed in 199ms. Pass: 2, fail: 0, skip: 0.

More examples

Install

$ npm install --save-dev test-runner

Test-runner tool kit

Alternatively, you can run your tests with any of the following runners - each is compatible with test-object-model.

Environment Description Tool
Web Run your tests in a headless Chromium browser from the command line web-runner
Node.js Test ECMAScript modules natively in Node.js esm-runner

See also

Please see the wiki for more examples.


© 2016-21 Lloyd Brookes <75pound@gmail.com>.

Current Tags

  • 0.10.1                                ...           latest (3 years ago)

82 Versions

  • 0.10.1                                ...           3 years ago
  • 0.10.0                                ...           3 years ago
  • 0.9.8                                ...           3 years ago
  • 0.9.7                                ...           3 years ago
  • 0.9.6                                ...           3 years ago
  • 0.9.5                                ...           3 years ago
  • 0.9.4                                ...           3 years ago
  • 0.9.3                                ...           3 years ago
  • 0.9.2                                ...           4 years ago
  • 0.9.1                                ...           4 years ago
  • 0.9.0                                ...           4 years ago
  • 0.8.14                                ...           4 years ago
  • 0.8.13                                ...           5 years ago
  • 0.8.12                                ...           5 years ago
  • 0.8.11                                ...           5 years ago
  • 0.8.10                                ...           5 years ago
  • 0.8.9                                ...           5 years ago
  • 0.8.8                                ...           5 years ago
  • 0.8.7                                ...           5 years ago
  • 0.8.6                                ...           5 years ago
  • 0.8.5                                ...           5 years ago
  • 0.8.4                                ...           5 years ago
  • 0.8.3                                ...           5 years ago
  • 0.8.2                                ...           5 years ago
  • 0.8.1                                ...           5 years ago
  • 0.8.0                                ...           5 years ago
  • 0.7.7                                ...           5 years ago
  • 0.7.6                                ...           5 years ago
  • 0.7.5                                ...           5 years ago
  • 0.7.4                                ...           5 years ago
  • 0.7.3                                ...           5 years ago
  • 0.7.2                                ...           5 years ago
  • 0.7.1                                ...           5 years ago
  • 0.7.0                                ...           5 years ago
  • 0.6.3                                ...           5 years ago
  • 0.6.2                                ...           5 years ago
  • 0.6.1                                ...           5 years ago
  • 0.6.0                                ...           6 years ago
  • 0.6.0-15                                ...           6 years ago
  • 0.6.0-14                                ...           6 years ago
  • 0.6.0-13                                ...           6 years ago
  • 0.6.0-12                                ...           6 years ago
  • 0.6.0-11                                ...           6 years ago
  • 0.6.0-10                                ...           6 years ago
  • 0.6.0-9                                ...           6 years ago
  • 0.6.0-8                                ...           6 years ago
  • 0.6.0-7                                ...           6 years ago
  • 0.6.0-6                                ...           6 years ago
  • 0.6.0-5                                ...           6 years ago
  • 0.6.0-4                                ...           6 years ago
  • 0.6.0-3                                ...           6 years ago
  • 0.6.0-2                                ...           6 years ago
  • 0.5.1                                ...           6 years ago
  • 0.6.0-1                                ...           7 years ago
  • 0.6.0-0                                ...           7 years ago
  • 0.5.0                                ...           7 years ago
  • 0.5.0-1                                ...           7 years ago
  • 0.5.0-0                                ...           7 years ago
  • 0.4.1                                ...           7 years ago
  • 0.4.0                                ...           7 years ago
  • 0.3.0                                ...           8 years ago
  • 0.2.5                                ...           8 years ago
  • 0.2.4                                ...           8 years ago
  • 0.2.3                                ...           8 years ago
  • 0.2.2                                ...           8 years ago
  • 0.2.1                                ...           8 years ago
  • 0.2.0                                ...           8 years ago
  • 0.1.13                                ...           8 years ago
  • 0.1.12                                ...           8 years ago
  • 0.1.11                                ...           8 years ago
  • 0.1.10                                ...           8 years ago
  • 0.1.9                                ...           8 years ago
  • 0.1.8                                ...           8 years ago
  • 0.1.7                                ...           8 years ago
  • 0.1.6                                ...           8 years ago
  • 0.1.5                                ...           8 years ago
  • 0.1.4                                ...           8 years ago
  • 0.1.3                                ...           8 years ago
  • 0.1.2                                ...           8 years ago
  • 0.1.1                                ...           8 years ago
  • 0.1.0                                ...           8 years ago
  • 0.0.0                                ...           8 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dev Dependencies (3)

Copyright 2013 - present © cnpmjs.org | Home |