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

jenkinsClassnamePrefix option #94

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,10 @@ output line 2
| antMode | set to truthy value to return xml compatible with [Ant JUnit schema][ant-schema] |
| antHostname | hostname to use when running in `antMode` will default to environment `HOSTNAME` |
| jenkinsMode | if set to truthy value will return xml that will display nice results in Jenkins |
| jenkinsClassnamePrefix | adds a prefix to classname. Useful for grouping tests in packages. |

[travis-badge]: https://travis-ci.org/michaelleeallen/mocha-junit-reporter.svg?branch=master
[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
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function configureDefaults(options) {
options.toConsole = !!options.toConsole;
options.rootSuiteTitle = options.rootSuiteTitle || 'Root Suite';
options.testsuitesTitle = options.testsuitesTitle || 'Mocha Tests';
options.jenkinsClassnamePrefix = options.jenkinsClassnamePrefix || '';

if (options.antMode) {
updateOptionsForAntMode(options);
Expand Down Expand Up @@ -155,15 +156,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 options.jenkinsClassnamePrefix + titles.join('.');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to use options.suiteTitleSeparatedBy rather than having to explicitly add it in options.jenkinsClassnamePrefix

}

/**
Expand Down Expand Up @@ -273,7 +274,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