2.0.16 • Published 1 month ago

@marianmeres/test-runner v2.0.16

Weekly downloads
-
License
WTFPL
Repository
github
Last release
1 month ago

Simple testing framework for node.js

Simple, sequential, exception based test runner for node js.

Features

  • usual test, skip, only, todo api
  • usual before, beforeEach, afterEach, after hooks
  • async support
  • speed
  • timeout checks

Intentionally absent features

  • parallel testing
  • assertions (tip)
  • CLI (read more below)

Installation

npm i -D @marianmeres/test-runner

Quick start

const suite = new TestRunner('My suite');

suite.test('My test', () => {
    if (false) {
        throw new Error('...')
    }
});

suite.run();

See examples for more.

CLI

npx test-runner [-d some-dir] [-d another-dir]

Or there is a TestRunner.runAll api, so something like this should work fine:

// tests/index.js
const args = process.argv.slice(2);
const verbose = args.includes('-v');
const whitelist = args.filter((v) => v !== '-v');

TestRunner.runAll([__dirname, '../src'], { verbose, whitelist });

runnable as

$ node tests [-v] [whitelist]

or also watchable as

$ nodemon -q tests -- [-v] [whitelist]

How to TestRunner.runAll([dirs], options) ?

The TestRunner.runAll looks by default for [<path>/]<file>.test.[tj]s. Each test file must have the suite instance "default exported":

// src/some.test.js
const suite = new TestRunner('My suite');

// tests definitions here...

export default suite;
// or depending on your env:
// module.exports = suite;

See examples for more.

Screenshots

Screenshots are taken from examples.

node examples (non verbose)

Non verbose mode

node examples -v (verbose)

Verbose mode

Limitations

This runner does not spawn the actual tests executions into separate child processes. This is an intentional choice, but it comes with the price of not beeing able to truly isolate/kill/cancel the test execution and its context (such as pending setTimeouts) which can sometimes lead to unexpected results.

Api

Check the definition files.

2.0.16

1 month ago

2.0.15

1 year ago

2.0.13

2 years ago

2.0.12

2 years ago

2.0.10

2 years ago

2.0.8

2 years ago