Patch java-junit to handle missing time field

Normally a <testsuites> element has a time field. In some JUnit implementations this field is missing. This issue was found in junit XML created in matlab.

At the moment I don't plan to explicitly support matlab - that would require to add more tests and documentation. However this patch should make it work with the existing java-junit parser.
This commit is contained in:
Michal Dorner 2021-05-13 22:39:52 +02:00
parent e873f73dd6
commit 72c193c336
No known key found for this signature in database
GPG key ID: 9EEE04B48DA36786
3 changed files with 6 additions and 3 deletions

4
dist/index.js generated vendored
View file

@ -888,6 +888,7 @@ class JavaJunitParser {
}
}
getTestRunResult(filePath, junit) {
var _a;
const suites = junit.testsuites.testsuite === undefined
? []
: junit.testsuites.testsuite.map(ts => {
@ -896,7 +897,8 @@ class JavaJunitParser {
const sr = new test_results_1.TestSuiteResult(name, this.getGroups(ts), time);
return sr;
});
const time = parseFloat(junit.testsuites.$.time) * 1000;
const seconds = parseFloat((_a = junit.testsuites.$) === null || _a === void 0 ? void 0 : _a.time);
const time = isNaN(seconds) ? undefined : seconds * 1000;
return new test_results_1.TestRunResult(filePath, suites, time);
}
getGroups(suite) {

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View file

@ -70,7 +70,8 @@ export class JavaJunitParser implements TestParser {
return sr
})
const time = parseFloat(junit.testsuites.$.time) * 1000
const seconds = parseFloat(junit.testsuites.$?.time)
const time = isNaN(seconds) ? undefined : seconds * 1000
return new TestRunResult(filePath, suites, time)
}