Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/plasticrake/mocha-json-runner

A Mocha.js runner that replays from JSON input
https://github.com/plasticrake/mocha-json-runner

json mocha mocha-runner

Last synced: 23 days ago
JSON representation

A Mocha.js runner that replays from JSON input

Awesome Lists containing this project

README

        

# Mocha.js JSON Runner

[![NPM Version](https://img.shields.io/npm/v/mocha-json-runner.svg)](https://www.npmjs.com/package/mocha-json-runner)
[![Build Status](https://github.com/plasticrake/mocha-json-runner/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/plasticrake/mocha-json-runner/actions/workflows/ci.yml?query=branch%3Amaster)
[![Coverage Status](https://coveralls.io/repos/github/plasticrake/mocha-json-runner/badge.svg?branch=master)](https://coveralls.io/github/plasticrake/mocha-json-runner?branch=master)

**A [Mocha.js](https://mochajs.org/) runner that replays from JSON input**

Pairs well with [mocha-json-serialize-reporter](https://github.com/plasticrake/mocha-json-serialize-reporter)!

## Usage

### Command-line

```shell
npm install --global mocha-json-runner
```

```shell
mocha-json-runner ./path/to/input.json
```

```shell
mocha-json-runner --help
```

```text
mocha-json-runner

Playback JSON test results with Mocha

Reporting & Output
-c, --color, --colors Force-enable color output [boolean]
--diff Show diff on failure
[boolean] [default: true]
--full-trace Display full stack traces [boolean]
-G, --growl Enable Growl notifications [boolean]
--inline-diffs Display actual/expected differences
inline within each string [boolean]
-R, --reporter Specify reporter to use
[string] [default: "spec"]
-O, --reporter-option, Reporter-specific options
--reporter-options () [array]
--warn-on-missing-state Warn when test is missing `state`.
Outputs to stderr. If mocha was run
with `--grep` this would produce
warnings for tests not matching.

File Handling
-r, --require Require module [array] [default: (none)]

Positional Arguments
json One file to load and playback

Other Options
-h, --help Show usage information & exit [boolean]
-V, --version Show version number & exit [boolean]
--reporters List built-in reporters & exit [boolean]
```

### Programmatically

```shell
npm install --save-dev mocha-json-runner
```

```js
import Mocha from 'mocha';
import MochaJsonRunner from 'mocha-json-runner';

const json = JSON.stringify({
suite: {
title: '',
tests: [
{ title: 'passing test', state: 'passed' },
{ title: 'failing test', state: 'failed', err: { message: 'FAIL' } },
{ title: 'pending test', pending: true },
],
},
});

const runner = new MochaJsonRunner(json);
new Mocha.reporters.Spec(runner);
runner.run();
```

**Output:**



passing test
1) failing test
- pending test

1 passing (0ms)
1 pending
1 failing

1) failing test:
FAIL

## License

[MIT](LICENSE)