mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-17 06:47:09 +01:00
Added null checks
This commit is contained in:
parent
9d8b7fea15
commit
3b382097a6
3 changed files with 52 additions and 21 deletions
28
dist/index.js
generated
vendored
28
dist/index.js
generated
vendored
|
|
@ -1151,21 +1151,30 @@ class JestJunitParser {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
getTestRunResult(path, junit) {
|
getTestRunResult(path, junit) {
|
||||||
var _a;
|
var _a, _b, _c, _d;
|
||||||
|
const checkNonNull = (value) => {
|
||||||
|
return value != null;
|
||||||
|
};
|
||||||
const suites = ((_a = junit.testsuites) === null || _a === void 0 ? void 0 : _a.testsuite) == null
|
const suites = ((_a = junit.testsuites) === null || _a === void 0 ? void 0 : _a.testsuite) == null
|
||||||
? []
|
? []
|
||||||
: junit.testsuites.testsuite.map(ts => {
|
: junit.testsuites.testsuite
|
||||||
|
.map(ts => {
|
||||||
|
if (ts == null)
|
||||||
|
return null;
|
||||||
const name = ts.$.name.trim();
|
const name = ts.$.name.trim();
|
||||||
const time = parseFloat(ts.$.time) * 1000;
|
const time = parseFloat(ts.$.time) * 1000;
|
||||||
const sr = new test_results_1.TestSuiteResult(name, this.getGroups(ts), time);
|
const sr = new test_results_1.TestSuiteResult(name, this.getGroups(ts), time);
|
||||||
return sr;
|
return sr;
|
||||||
});
|
})
|
||||||
const time = parseFloat(junit.testsuites.$.time) * 1000;
|
.filter(checkNonNull);
|
||||||
|
const time = parseFloat((_d = (_c = (_b = junit.testsuites) === null || _b === void 0 ? void 0 : _b.$) === null || _c === void 0 ? void 0 : _c.time) !== null && _d !== void 0 ? _d : 0) * 1000;
|
||||||
return new test_results_1.TestRunResult(path, suites, time);
|
return new test_results_1.TestRunResult(path, suites, time);
|
||||||
}
|
}
|
||||||
getGroups(suite) {
|
getGroups(suite) {
|
||||||
const groups = [];
|
const groups = [];
|
||||||
for (const tc of suite.testcase) {
|
for (const tc of suite.testcase) {
|
||||||
|
if ((tc === null || tc === void 0 ? void 0 : tc.$) == null)
|
||||||
|
continue;
|
||||||
let grp = groups.find(g => g.describe === tc.$.classname);
|
let grp = groups.find(g => g.describe === tc.$.classname);
|
||||||
if (grp === undefined) {
|
if (grp === undefined) {
|
||||||
grp = { describe: tc.$.classname, tests: [] };
|
grp = { describe: tc.$.classname, tests: [] };
|
||||||
|
|
@ -1173,14 +1182,21 @@ class JestJunitParser {
|
||||||
}
|
}
|
||||||
grp.tests.push(tc);
|
grp.tests.push(tc);
|
||||||
}
|
}
|
||||||
|
const checkNonNull = (value) => {
|
||||||
|
return value != null;
|
||||||
|
};
|
||||||
return groups.map(grp => {
|
return groups.map(grp => {
|
||||||
const tests = grp.tests.map(tc => {
|
const tests = grp.tests
|
||||||
|
.map(tc => {
|
||||||
|
if ((tc === null || tc === void 0 ? void 0 : tc.$) == null)
|
||||||
|
return null;
|
||||||
const name = tc.$.name.trim();
|
const name = tc.$.name.trim();
|
||||||
const result = this.getTestCaseResult(tc);
|
const result = this.getTestCaseResult(tc);
|
||||||
const time = parseFloat(tc.$.time) * 1000;
|
const time = parseFloat(tc.$.time) * 1000;
|
||||||
const error = this.getTestCaseError(tc);
|
const error = this.getTestCaseError(tc);
|
||||||
return new test_results_1.TestCaseResult(name, result, time, error);
|
return new test_results_1.TestCaseResult(name, result, time, error);
|
||||||
});
|
})
|
||||||
|
.filter(checkNonNull);
|
||||||
return new test_results_1.TestGroupResult(grp.describe, tests);
|
return new test_results_1.TestGroupResult(grp.describe, tests);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
|
|
@ -33,23 +33,31 @@ export class JestJunitParser implements TestParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
private getTestRunResult(path: string, junit: JunitReport): TestRunResult {
|
private getTestRunResult(path: string, junit: JunitReport): TestRunResult {
|
||||||
|
const checkNonNull = (value: TestSuiteResult | undefined | null): value is TestSuiteResult => {
|
||||||
|
return value != null
|
||||||
|
}
|
||||||
|
|
||||||
const suites =
|
const suites =
|
||||||
junit.testsuites?.testsuite == null
|
junit.testsuites?.testsuite == null
|
||||||
? []
|
? []
|
||||||
: junit.testsuites.testsuite.map(ts => {
|
: junit.testsuites.testsuite
|
||||||
|
.map(ts => {
|
||||||
|
if (ts == null) return null
|
||||||
const name = ts.$.name.trim()
|
const name = ts.$.name.trim()
|
||||||
const time = parseFloat(ts.$.time) * 1000
|
const time = parseFloat(ts.$.time) * 1000
|
||||||
const sr = new TestSuiteResult(name, this.getGroups(ts), time)
|
const sr = new TestSuiteResult(name, this.getGroups(ts), time)
|
||||||
return sr
|
return sr
|
||||||
})
|
})
|
||||||
|
.filter(checkNonNull)
|
||||||
|
|
||||||
const time = parseFloat(junit.testsuites.$.time) * 1000
|
const time = parseFloat(junit.testsuites?.$?.time ?? 0) * 1000
|
||||||
return new TestRunResult(path, suites, time)
|
return new TestRunResult(path, suites, time)
|
||||||
}
|
}
|
||||||
|
|
||||||
private getGroups(suite: TestSuite): TestGroupResult[] {
|
private getGroups(suite: TestSuite): TestGroupResult[] {
|
||||||
const groups: {describe: string; tests: TestCase[]}[] = []
|
const groups: {describe: string; tests: TestCase[]}[] = []
|
||||||
for (const tc of suite.testcase) {
|
for (const tc of suite.testcase) {
|
||||||
|
if (tc?.$ == null) continue
|
||||||
let grp = groups.find(g => g.describe === tc.$.classname)
|
let grp = groups.find(g => g.describe === tc.$.classname)
|
||||||
if (grp === undefined) {
|
if (grp === undefined) {
|
||||||
grp = {describe: tc.$.classname, tests: []}
|
grp = {describe: tc.$.classname, tests: []}
|
||||||
|
|
@ -58,14 +66,21 @@ export class JestJunitParser implements TestParser {
|
||||||
grp.tests.push(tc)
|
grp.tests.push(tc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const checkNonNull = (value: TestCaseResult | undefined | null): value is TestCaseResult => {
|
||||||
|
return value != null
|
||||||
|
}
|
||||||
|
|
||||||
return groups.map(grp => {
|
return groups.map(grp => {
|
||||||
const tests = grp.tests.map(tc => {
|
const tests = grp.tests
|
||||||
|
.map(tc => {
|
||||||
|
if (tc?.$ == null) return null
|
||||||
const name = tc.$.name.trim()
|
const name = tc.$.name.trim()
|
||||||
const result = this.getTestCaseResult(tc)
|
const result = this.getTestCaseResult(tc)
|
||||||
const time = parseFloat(tc.$.time) * 1000
|
const time = parseFloat(tc.$.time) * 1000
|
||||||
const error = this.getTestCaseError(tc)
|
const error = this.getTestCaseError(tc)
|
||||||
return new TestCaseResult(name, result, time, error)
|
return new TestCaseResult(name, result, time, error)
|
||||||
})
|
})
|
||||||
|
.filter(checkNonNull)
|
||||||
return new TestGroupResult(grp.describe, tests)
|
return new TestGroupResult(grp.describe, tests)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue