Skip to content

Commit

Permalink
feature: Strip ANSI sequences from all titles (#60)
Browse files Browse the repository at this point in the history
* Stripped ANSI sequences from all titles
* dependencies: Added strip-ansi v4.X
  • Loading branch information
Romain GAGNAIRE authored and clayreimann committed Jan 25, 2018
1 parent ac563a7 commit c55dc22
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
11 changes: 6 additions & 5 deletions index.js
Expand Up @@ -7,6 +7,7 @@ var path = require('path');
var debug = require('debug')('mocha-junit-reporter');
var mkdirp = require('mkdirp');
var md5 = require('md5');
var stripAnsi = require('strip-ansi');

module.exports = MochaJUnitReporter;

Expand All @@ -31,9 +32,9 @@ function configureDefaults(options) {

function defaultSuiteTitle(suite) {
if (suite.root && suite.title === '') {
return this._options.rootSuiteTitle;
return stripAnsi(this._options.rootSuiteTitle);
}
return suite.title;
return stripAnsi(suite.title);
}

function fullSuiteTitle(suite) {
Expand All @@ -49,7 +50,7 @@ function fullSuiteTitle(suite) {
parent = parent.parent;
}

return title.join(this._options.suiteTitleSeparatedBy);
return stripAnsi(title.join(this._options.suiteTitleSeparatedBy));
}

function isInvalidSuite(suite) {
Expand Down Expand Up @@ -186,9 +187,9 @@ MochaJUnitReporter.prototype.getTestcaseData = function(test, err) {
var config = {
testcase: [{
_attr: {
name: this._options.testCaseSwitchClassnameAndName ? test.title : test.fullTitle(),
name: this._options.testCaseSwitchClassnameAndName ? stripAnsi(test.title) : stripAnsi(test.fullTitle()),
time: (typeof test.duration === 'undefined') ? 0 : test.duration / 1000,
classname: this._options.testCaseSwitchClassnameAndName ? test.fullTitle() : test.title
classname: this._options.testCaseSwitchClassnameAndName ? stripAnsi(test.fullTitle()) : stripAnsi(test.title)
}
}]
};
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -33,6 +33,7 @@
"debug": "^2.2.0",
"md5": "^2.1.0",
"mkdirp": "~0.5.1",
"strip-ansi": "^4.0.0",
"xml": "^1.0.0"
},
"peerDependencies": {
Expand Down
7 changes: 7 additions & 0 deletions test/mocha-junit-reporter-spec.js
Expand Up @@ -189,6 +189,13 @@ describe('mocha-junit-reporter', function() {
verifyMochaFile(filePath);
});

it('creates valid XML report even if title contain ANSI character sequences', function() {
createReporter({mochaFile: 'test/mocha.xml'});
executeTestRunner({title: 'Foo Bar module'});

verifyMochaFile(filePath);
});

it('outputs pending tests if "includePending" is specified', function() {
createReporter({mochaFile: 'test/mocha.xml', includePending: true});
executeTestRunner({includePending: true});
Expand Down

0 comments on commit c55dc22

Please sign in to comment.