Skip to content

Commit

Permalink
Update jenkins mode to use suiteTitleSeparatedBy and update documenta…
Browse files Browse the repository at this point in the history
…tion (#123)

* Update jenkins mode to use suiteTitleSeparatedBy and update documentation
* Update docs
  • Loading branch information
hmafzal committed May 25, 2020
1 parent 3824381 commit 671bc9e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -86,7 +86,7 @@ var mocha = new Mocha({
reporter: 'mocha-junit-reporter',
reporterOptions: {
testsuitesTitle: true,
suiteTitleSeparatedBy: '.' // suites separator, default is space (' ')
suiteTitleSeparatedBy: '.' // suites separator, default is space (' '), or period ('.') in jenkins mode
}
});
```
Expand Down Expand Up @@ -186,7 +186,8 @@ output line 2
| properties | `null` | a hash of additional properties to add to each test suite |
| toConsole | `false` | if set to a truthy value the produced XML will be logged to the console |
| useFullSuiteTitle | `false` | if set to a truthy value nested suites' titles will show the suite lineage |
| suiteTitleSeparedBy | ` ` (space) | the character to use to separate nested suite titles. (defaults to ' ') |
| suiteTitleSeparatedBy | ` ` (space) | the character to use to separate nested suite titles. (defaults to ' ', '.' if in jenkins mode) |
| suiteTitleSeparedBy | ` ` (space) | deprecated. use `suiteTitleSeparatedBy` |
| testCaseSwitchClassnameAndName | `false` | set to a truthy value to switch name and classname values |
| rootSuiteTitle | `Root Suite` | the name for the root suite. (defaults to 'Root Suite') |
| testsuitesTitle | `Mocha Tests` | the name for the `testsuites` tag (defaults to 'Mocha Tests') |
Expand Down
13 changes: 6 additions & 7 deletions index.js
Expand Up @@ -76,8 +76,7 @@ function configureDefaults(options) {
updateOptionsForJenkinsMode(config);
}

config.suiteTitleSeparedBy = config.suiteTitleSeparedBy || ' ';
config.suiteTitleSeparatedBy = config.suiteTitleSeparatedBy || config.suiteTitleSeparedBy;
config.suiteTitleSeparatedBy = config.suiteTitleSeparatedBy || config.suiteTitleSeparedBy || ' ';

return config;
}
Expand All @@ -98,8 +97,8 @@ function updateOptionsForJenkinsMode(options) {
if (options.testCaseSwitchClassnameAndName === undefined) {
options.testCaseSwitchClassnameAndName = true;
}
if (options.suiteTitleSeparedBy === undefined) {
options.suiteTitleSeparedBy = '.';
if (options.suiteTitleSeparatedBy === undefined) {
options.suiteTitleSeparatedBy = '.';
}
}

Expand Down Expand Up @@ -177,15 +176,15 @@ function generateProperties(options) {
}, []);
}

function getJenkinsClassname (test) {
function getJenkinsClassname (test, options) {
debug('Building jenkins classname for', test);
var parent = test.parent;
var titles = [];
while (parent) {
parent.title && titles.unshift(parent.title);
parent = parent.parent;
}
return titles.join('.');
return titles.join(options.suiteTitleSeparatedBy);
}

/**
Expand Down Expand Up @@ -295,7 +294,7 @@ MochaJUnitReporter.prototype.getTestsuiteData = function(suite) {
MochaJUnitReporter.prototype.getTestcaseData = function(test, err) {
var jenkinsMode = this._options.jenkinsMode;
var flipClassAndName = this._options.testCaseSwitchClassnameAndName;
var name = stripAnsi(jenkinsMode ? getJenkinsClassname(test) : test.fullTitle());
var name = stripAnsi(jenkinsMode ? getJenkinsClassname(test, this._options) : test.fullTitle());
var classname = stripAnsi(test.title);
var testcase = {
testcase: [{
Expand Down

0 comments on commit 671bc9e

Please sign in to comment.