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

feature | allow to add jenkinsClassnamePrefix #138

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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ output line 2
| antMode | `false` | set to truthy value to return xml compatible with [Ant JUnit schema][ant-schema] |
| antHostname | `process.env.HOSTNAME` | hostname to use when running in `antMode` will default to environment `HOSTNAME` |
| jenkinsMode | `false` | if set to truthy value will return xml that will display nice results in Jenkins |
| jenkinsClassnamePrefix | `undefined` | adds a prefix to a classname when running in `jenkinsMode` |

[travis-badge]: https://travis-ci.org/michaelleeallen/mocha-junit-reporter.svg?branch=master
[travis-build]: https://travis-ci.org/michaelleeallen/mocha-junit-reporter
Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ function getJenkinsClassname (test, options) {
parent.title && titles.unshift(parent.title);
parent = parent.parent;
}
if (options.jenkinsClassnamePrefix) {
titles.unshift(options.jenkinsClassnamePrefix);
}
return titles.join(options.suiteTitleSeparatedBy);
}

Expand Down
23 changes: 23 additions & 0 deletions test/mocha-junit-reporter-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,29 @@ describe('mocha-junit-reporter', function() {
expect(reporter._testsuites[2].testsuite[1].testcase[0]._attr.name).to.equal('fail test');
expect(reporter._testsuites[2].testsuite[1].testcase[0]._attr.classname).to.equal('Inner Suite.Another Suite');

done();
});
});
it('prefix is added to a classname when jenkinsClassnamePrefix is specified', function(done) {
var reporter = createReporter({jenkinsMode: true, jenkinsClassnamePrefix: "Added Prefix"});
var rootSuite = reporter.runner.suite;

var suite1 = Suite.create(rootSuite, 'Inner Suite');
suite1.addTest(createTest('test'));

var suite2 = Suite.create(suite1, 'Another Suite');
suite2.addTest(createTest('fail test', function(done) {
done(new Error('failed test'));
}));

runRunner(reporter.runner, function() {
expect(reporter._testsuites[0].testsuite[0]._attr.name).to.equal('');
expect(reporter._testsuites[1].testsuite[1].testcase[0]._attr.name).to.equal('test');
expect(reporter._testsuites[1].testsuite[1].testcase[0]._attr.classname).to.equal('Added Prefix.Inner Suite');
expect(reporter._testsuites[2].testsuite[0]._attr.name).to.equal('Root Suite.Inner Suite.Another Suite');
expect(reporter._testsuites[2].testsuite[1].testcase[0]._attr.name).to.equal('fail test');
expect(reporter._testsuites[2].testsuite[1].testcase[0]._attr.classname).to.equal('Added Prefix.Inner Suite.Another Suite');

done();
});
});
Expand Down