Skip to content

Commit

Permalink
Added classname attribute to junit report, based on nightwatchjs#1160
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfactor committed Mar 10, 2017
1 parent eeea684 commit 50a42c7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
16 changes: 10 additions & 6 deletions lib/runner/reporters/junit.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,28 @@ module.exports = new (function() {
var module = globalResults.modules[moduleKey];
var pathParts = moduleKey.split(path.sep);
var moduleName = pathParts.pop();
var className = moduleName;
var output_folder = opts.output_folder;

adaptAssertions(module);

if (pathParts.length) {
output_folder = path.join(output_folder, pathParts.join(path.sep));
mkpath.sync(output_folder);
className = pathParts.join('.') + '.' + moduleName;
}

var filename = path.join(output_folder, opts.filename_prefix + moduleName + '.xml');

var rendered = ejs.render(data, {
locals: {
module : module,
moduleName : moduleName,
className : className,
systemerr : globalResults.errmessages.join('\n')
}
});

if (pathParts.length) {
output_folder = path.join(output_folder, pathParts.join(path.sep));
mkpath.sync(output_folder);
}

var filename = path.join(output_folder, opts.filename_prefix + moduleName + '.xml');
fs.writeFile(filename, rendered, function(err) {
callback(err);
globalResults.errmessages.length = 0;
Expand Down
6 changes: 3 additions & 3 deletions lib/runner/reporters/junit.xml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
failures="<%= module.failures %>"
tests="<%= module.tests %>">

<testsuite name="<%= moduleName %>"
<testsuite name="<%= className %>"
errors="<%= module.errors %>" failures="<%= module.failures %>" hostname="" id="" package="<%= module.group || moduleName %>" skipped="<%= (Array.isArray(module.skipped)) ? module.skipped.length : 0 %>"
tests="<%= module.tests %>" time="<%= module.time %>" timestamp="<%= module.timestamp %>">
<% for (var item in module.completed) {
var testcase = module.completed[item];
var assertions = testcase.assertions %>
<testcase name="<%= item %>" time="<%= testcase.time %>" assertions="<%= assertions.length %>"><%
<testcase name="<%= item %>" classname="<%= className %>" time="<%= testcase.time %>" assertions="<%= assertions.length %>"><%
for (var i = 0; i < assertions.length; i++) { %><% if (assertions[i].failure) { %> <failure message="<%= assertions[i].message %>"><%= assertions[i].stackTrace %></failure><% } %>
<% if (assertions[i].screenshots && assertions[i].screenshots.length > 0) { %><system-out><% for (var j = 0; j < assertions[i].screenshots.length; j++) { %>[[ATTACHMENT|<%= assertions[i].screenshots[j] %>]]<% } %></system-out><% } %>
<% }
Expand All @@ -23,7 +23,7 @@
<% if (module.skipped && (module.skipped.length > 0)) { %>
<% for (var j = 0; j < module.skipped.length; j++) { %>
<testcase
name="<%= module.skipped[j] %>">
name="<%= module.skipped[j] %>" classname="<%= className %>">
<skipped />
</testcase>
<% } %>
Expand Down
16 changes: 15 additions & 1 deletion test/src/runner/testRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,21 @@ module.exports = {

assert.ok(fileExistsSync(simpleReportFile), 'The simple report file was not created.');
assert.ok(fileExistsSync(tagsReportFile), 'The tags report file was not created.');
done();

fs.readFile(simpleReportFile, function(err, data) {
if (err) {
return done(err);
}

var content = data.toString();
try {
assert.ok(/<testsuite[\s]+name="simple\.sample"[\s]+errors="0"[\s]+failures="0"[\s]+hostname=""[\s]+id=""[\s]+package="simple"[\s]+skipped="0"[\s]+tests="1"/.test(content), 'Report does not contain correct testsuite information.');
assert.ok(/<testcase[\s]+name="simpleDemoTest"[\s]+classname="simple\.sample"[\s]+time="[.\d]+"[\s]+assertions="1">/.test(content), 'Report does not contain the correct testcase element.');
done();
} catch (err) {
done(err);
}
});
} catch (err) {
done(err);
}
Expand Down

0 comments on commit 50a42c7

Please sign in to comment.