https://github.com/plasticrake/mocha-json-deserialize
A Mocha.js JSON deserializer
https://github.com/plasticrake/mocha-json-deserialize
json mocha
Last synced: 8 months ago
JSON representation
A Mocha.js JSON deserializer
- Host: GitHub
- URL: https://github.com/plasticrake/mocha-json-deserialize
- Owner: plasticrake
- Created: 2020-01-04T07:09:47.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-08-10T23:56:31.000Z (over 1 year ago)
- Last Synced: 2025-03-24T08:48:16.978Z (9 months ago)
- Topics: json, mocha
- Language: JavaScript
- Homepage:
- Size: 344 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# mocha-json-deserialize
[](https://www.npmjs.com/package/mocha-json-deserialize)
[](https://github.com/plasticrake/mocha-json-deserialize/actions/workflows/ci.yml?query=branch%3Amaster)
[](https://coveralls.io/github/plasticrake/mocha-json-deserialize?branch=master)
[](https://github.com/plasticrake/mocha-json-deserialize/actions/workflows/codeql.yml)
☕️ **A Mocha.js JSON deserializer** ☕️
Pairs well with [mocha-json-serialize-reporter](https://github.com/plasticrake/mocha-json-serialize-reporter)!
## What is this for?
This can be used to revive the JSON output from [mocha-json-serialize-reporter](https://github.com/plasticrake/mocha-json-serialize-reporter) back into a Mocha Suite.
- This package is used by [mocha-json-runner](https://github.com/plasticrake/mocha-json-runner) to "playback" a previously run mocha test suite that has been serialized to JSON. You could then run the JSON through another Mocha reporter such as Spec.
- The deserialized Mocha Suite could also be added to an existing mocha test suite.
## Example
See [Examples](https://github.com/plasticrake/mocha-json-deserialize/tree/master/examples)
```js
// Run this with mocha:
// mocha examples/mocha.js
const mochaJsonDeserialize = require('mocha-json-deserialize');
// stringify is optional, can take a JSON string or an Object
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 },
{
title: 'a slow test',
state: 'passed',
speed: 'slow',
duration: 5,
slow: 3,
},
],
},
});
const rootSuite = mochaJsonDeserialize(json);
rootSuite.title = 'A deserialized suite';
describe('A describe block', function() {
this.addSuite(rootSuite);
describe('A real suite', function() {
it('should have a passing test', function() {});
});
});
```
```shell
mocha examples/mocha.js
```
**Output:**
```text
A describe block
A deserialized suite
✓ passing test
1) failing test
- pending test
✓ a slow test (5ms)
A real suite
✓ should have a passing test
3 passing (7ms)
1 pending
1 failing
1) A describe block
A deserialized suite
failing test:
FAIL
```
## License
[MIT](LICENSE)