Skip to content

mattriley/node-module-testrunner

Repository files navigation

Module Testrunner

44 sloc 3 files 0 deps 9 dev deps

Runs test files that export a top level function to enable initialisation.


Table of Contents

Install

npm install module-testrunner

Usage

CLI

npx test test_files

API

const { run } = require('module-testrunner');
const options = { ... };
run(options);

Options

  • files: Array of test file paths.
  • args: Array of custom test arguments. Default: Result of loading main from package.json or ./index.js.
  • test: Function that runs a test. Default: Result of loading node:test.
  • assert: Assertion library. Default: Result of loading node:assert.
  • context: Additional context object to make accessible to each test.

Example

Basic

module.exports = ({ test, assert }) => {

    test('it passes', () => {
        assert(true);
    });

};

Advanced

module.exports = ({ test, assert, context }) => args => {

    test('initialises the app', () => {
        const app = args.initialise();
        assert(context.helpers.appInitialised(app));
    });

};

About

Runs test files that export a top level function to enable initialisation.

Topics

Resources

Stars

Watchers

Forks