Skip to content

Commit b28d669

Browse files
YOU54Fclayreimann
authored andcommitted
fix: Make mocha-junit-reporter work with Mocha 6 (#80)
This change is compatible with mocha 6+ and earlier versions
1 parent 74ca404 commit b28d669

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

.travis.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
language: node_js
22
node_js:
3-
- '6'
4-
- '8'
5-
- '10'
3+
- "6"
4+
- "8"
5+
- "10"
6+
script: npm test
67
deploy:
78
provider: npm
89
email: $NPM_EMAIL

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,4 @@ output line 2
200200
[travis-build]: https://travis-ci.org/michaelleeallen/mocha-junit-reporter
201201
[npm-badge]: https://img.shields.io/npm/v/mocha-junit-reporter.svg?maxAge=2592000
202202
[npm-listing]: https://www.npmjs.com/package/mocha-junit-reporter
203-
[ant-schema]: http://windyroad.org/dl/Open%20Source/JUnit.xsd
203+
[ant-schema]: http://windyroad.org/dl/Open%20Source/JUnit.xsd

index.js

+20
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,23 @@ var mkdirp = require('mkdirp');
99
var md5 = require('md5');
1010
var stripAnsi = require('strip-ansi');
1111

12+
var createStatsCollector;
13+
var mocha6plus;
14+
15+
try {
16+
var json = JSON.parse(
17+
fs.readFileSync("./node_modules/mocha/package.json", "utf8")
18+
);
19+
version = json.version;
20+
if (version >= "6") {
21+
createStatsCollector = require("mocha/lib/stats-collector");
22+
mocha6plus = true;
23+
} else {
24+
mocha6plus = false;
25+
}
26+
} catch (e) {
27+
console.warn("Couldn't determine Mocha version");
28+
}
1229
module.exports = MochaJUnitReporter;
1330

1431
// A subset of invalid characters as defined in http://www.w3.org/TR/xml/#charsets that can occur in e.g. stacktraces
@@ -155,6 +172,9 @@ function getJenkinsClassname (test) {
155172
* @param {Object} options - mocha options
156173
*/
157174
function MochaJUnitReporter(runner, options) {
175+
if (mocha6plus) {
176+
createStatsCollector(runner);
177+
}
158178
this._options = configureDefaults(options);
159179
this._runner = runner;
160180
this._generateSuiteTitle = this._options.useFullSuiteTitle ? fullSuiteTitle : defaultSuiteTitle;

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mocha-junit-reporter",
3-
"version": "1.22.0",
3+
"version": "1.23.0",
44
"description": "A JUnit reporter for mocha.",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)