Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Make mocha-junit-reporter work with Mocha 6 #80

Merged
merged 4 commits into from
Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
language: node_js
node_js:
- '6'
- '8'
- '10'
- "6"
- "8"
- "10"
script: npm test
deploy:
provider: npm
email: $NPM_EMAIL
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,4 @@ output line 2
[travis-build]: https://travis-ci.org/michaelleeallen/mocha-junit-reporter
[npm-badge]: https://img.shields.io/npm/v/mocha-junit-reporter.svg?maxAge=2592000
[npm-listing]: https://www.npmjs.com/package/mocha-junit-reporter
[ant-schema]: http://windyroad.org/dl/Open%20Source/JUnit.xsd
[ant-schema]: http://windyroad.org/dl/Open%20Source/JUnit.xsd
20 changes: 20 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ var mkdirp = require('mkdirp');
var md5 = require('md5');
var stripAnsi = require('strip-ansi');

var createStatsCollector;
var mocha6plus;

try {
var json = JSON.parse(
fs.readFileSync("./node_modules/mocha/package.json", "utf8")
);
version = json.version;
if (version >= "6") {
createStatsCollector = require("mocha/lib/stats-collector");
mocha6plus = true;
} else {
mocha6plus = false;
}
} catch (e) {
console.warn("Couldn't determine Mocha version");
}
module.exports = MochaJUnitReporter;

// A subset of invalid characters as defined in http://www.w3.org/TR/xml/#charsets that can occur in e.g. stacktraces
Expand Down Expand Up @@ -155,6 +172,9 @@ function getJenkinsClassname (test) {
* @param {Object} options - mocha options
*/
function MochaJUnitReporter(runner, options) {
if (mocha6plus) {
createStatsCollector(runner);
}
this._options = configureDefaults(options);
this._runner = runner;
this._generateSuiteTitle = this._options.useFullSuiteTitle ? fullSuiteTitle : defaultSuiteTitle;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mocha-junit-reporter",
"version": "1.22.0",
"version": "1.23.0",
"description": "A JUnit reporter for mocha.",
"main": "index.js",
"scripts": {
Expand Down