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

WIP: Add support for multiple browsers, logging skipped, and grouping by test suite #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
75 changes: 59 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ class GitLabJUnitReporter {
this.out = out || process.stdout;
this.silent = silent;

this.results = [];
this.results = {};
}

report(launcher, data) {
this.results.push({ launcher, data });
if (!this.results[launcher]) {
this.results[launcher] = [];
}

this.results[launcher].push({ data });
}

finish() {
Expand All @@ -23,25 +27,64 @@ class GitLabJUnitReporter {
}

_formatOutput() {
let root = builder.create('testsuite');
let root = builder.create('testsuites');

root.attribute('tests', this.results.filter(it => !it.data.skipped).length);
root.attribute('failures', this.results.filter(it => it.data.failed).length);
var totals = Object.keys(this.results).reduce((previous, browser) => {
let suite = root.element('testsuite');
suite.attribute('name', browser);
var result = this.results[browser];

for (let { data } of this.results) {
if (data.skipped) {
continue;
}
suite.attribute('tests', result.length);
suite.attribute('failures', result.filter(it => it.data.failed).length);
suite.attribute('skipped', result.filter(it => it.data.skipped).length);

for (let { data } of result) {
let el = suite.element('testcase');

let name = data.name;
let className = name;

const firstColon = name.indexOf(':');

if (firstColon !== -1) {
className = className.substring(0, firstColon);
name = name.substring(firstColon + 2);
}

let el = root.element('testcase');
el.attribute('name', data.name);
el.attribute('time', durationFromMs(data.runDuration));
el.attribute('name', name);
el.attribute('classname', `[${browser}] ${className}`);

if (data.error) {
let failure = el.element('failure');
failure.text(data.error.message);
if (data.skipped) {
let skipped = el.element('skipped');
continue;
}

el.attribute('time', durationFromMs(data.runDuration));

if (data.logs && data.logs.length) {
let output = el.element('system-out');
output.text(JSON.stringify(data.logs, null, '\t'));
}

if (data.error) {
let failure = el.element('failure');
failure.text(data.error.message);

let stderr = el.element('system-err');
stderr.text(JSON.stringify(data.error, null, '\t'));
}
}
}

return {
failures: previous.failures + result.filter(it => it.data.failed).length,
skipped: previous.skipped + result.filter(it => it.data.skipped).length,
tests: previous.tests + result.length,
};
}, {
tests: 0,
failures: 0,
skipped: 0
});

return root.end({ pretty: true });
}
Expand Down