Skip to content

Commit

Permalink
assume reporterOptions holds all options if configFile is !defined (#32)
Browse files Browse the repository at this point in the history
* assume reporterOptions holds all options if configFile is !defined
* updated doc to reflect calling mocha programmatically

* Clarification
  • Loading branch information
gjw authored and stanleyhlng committed Mar 9, 2017
1 parent 7d1ef64 commit 94a62a5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ $ ./node_modules/.bin/mocha --reporter mocha-multi-reporters
</testsuite>
```

### Advance
### Advanced

* Generate `spec` and `json` reports.

Expand Down Expand Up @@ -215,6 +215,28 @@ $ cat xunit-custom.xml
</testsuites>
```

* When calling Mocha programmatically

Note that when Mocha is called programmatically, it is passed an options object when created. This object is usually derived from a config file that your mocha test runner reads prior to instantiation. This is the object that must contain a key `reporter` with a value of `mocha-multi-reporters` for this plugin to be used. You can also pass the key `reporterOptions` with a value of any of the above listed config files (including the `reporterEnabled` subkey and any other plugin configuration information.) This removes the requirement to have an intermediate configuration file specifically for the multireporter configuration.

```js
var mocha = new Mocha({
reporter: "mocha-multi-reporters",
timeout: config.testTimeout || 60000,
slow: config.slow || 10000,
reporterOptions: {
"reporterEnabled": "mocha-junit-reporter, tap",
"mochaJunitReporterReporterOptions": {
"mochaFile": "junit-custom.xml"
}
}
});
mocha.addFile(...)
mocha.run(...)

```
Note that it will first check if reporterOptions contains a `configFile` key, and if it does, use that. That key must not exist in the `reporterOptions` object in order to pass these values in directly.

## License

The MIT License (MIT)
Expand Down
2 changes: 1 addition & 1 deletion lib/MultiReporters.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ MultiReporters.prototype.getCustomOptions = function (options) {
console.error(e);
throw e;
}
}
} else { customOptions = _.get(options, "reporterOptions"); }

return customOptions;
};
Expand Down

0 comments on commit 94a62a5

Please sign in to comment.