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

Add testsuites output to junit #864

Merged
merged 2 commits into from
Oct 23, 2018
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
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ language: node_js

node_js:
- "8"
- "9"
- "node"
- "10"

sudo: false
23 changes: 19 additions & 4 deletions lib/reporters/junit.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,37 @@ internals.Reporter.prototype.end = function (notebook) {
failures: notebook.failures,
errors: notebook.errors.length,
skipped: 0,
time: notebook.ms / 1000
time: notebook.ms / 1000,
testsuites: []
};

const tests = context.tests = [];

notebook.tests.forEach((nbtest) => {

const name = nbtest.path.join(' ');
let testsuite = context.testsuites.find((contextTestsuite) => {

return contextTestsuite.name === name;
});

if (!testsuite) {
testsuite = { name, tests: [], count: 0, skipped: 0, errors: 0, failures: 0, time: 0 };
context.testsuites.push(testsuite);
}

const test = {
title: nbtest.title,
path: nbtest.path.join(' '),
relativeTitle: nbtest.relativeTitle,
time: nbtest.duration / 1000
};

testsuite.time += test.time;

if (nbtest.skipped || nbtest.todo) {

test.skipped = true;
++context.skipped;
++testsuite.skipped;
}

if (nbtest.err) {
Expand All @@ -67,9 +80,11 @@ internals.Reporter.prototype.end = function (notebook) {
message: nbtest.err.message,
details: nbtest.err.stack
};
++testsuite.errors;
}

tests.push(test);
++testsuite.count;
testsuite.tests.push(test);
});

this.report(this.view(context));
Expand Down
8 changes: 6 additions & 2 deletions lib/reporters/junit/report.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<testsuite tests="{{this.count}}" skipped="{{this.skipped}}" errors="{{this.errors}}" failures="{{this.failures}}" time="{{this.time}}">
<testsuites tests="{{this.count}}" errors="{{this.errors}}" failures="{{this.failures}}" time="{{this.time}}">
{{#each this.testsuites~}}
<testsuite name="{{this.name}}" tests="{{this.count}}" skipped="{{this.skipped}}" errors="{{this.errors}}" time="{{this.time}}">
{{#each this.tests~}}
<testcase classname="{{this.title}}" name="{{this.title}}" time="{{this.time}}">
<testcase classname="{{this.path}}" name="{{this.relativeTitle}}" time="{{this.time}}">
{{#if this.err~}}
<failure message="{{this.err.message}}" type="{{this.err.name}}">
<![CDATA[{{this.err.details}}]]>
Expand All @@ -10,3 +12,5 @@
</testcase>
{{/each}}
</testsuite>
{{/each}}
</testsuites>
3 changes: 2 additions & 1 deletion test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,8 @@ describe('CLI', () => {

expect(result.errorOutput).to.equal('');
expect(result.code).to.equal(0);
expect(result.output).to.contain('<testsuite tests="2"');
expect(result.output).to.contain('<testsuites tests="2"');
expect(result.output).to.contain('<testsuite name="Test CLI" tests="2"');
});

it('outputs to file passed with -o argument', async () => {
Expand Down