Skip to content

Commit 72c3ba6

Browse files
Handle passCalculationFormulae earlier.
1 parent 7bc9c16 commit 72c3ba6

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

src/client/testing/common/xUnitParser.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { inject, injectable } from 'inversify';
22
import { IFileSystem } from '../../common/platform/types';
3-
import { IXUnitParser, PassCalculationFormulae, Tests, TestStatus } from './types';
3+
import {
4+
IXUnitParser, PassCalculationFormulae, Tests, TestStatus, TestSummary
5+
} from './types';
46

57
type TestSuiteResult = {
68
$: {
@@ -55,6 +57,15 @@ export class XUnitParser implements IXUnitParser {
5557
outputXmlFile: string,
5658
passCalculationFormulae: PassCalculationFormulae
5759
) {
60+
switch (passCalculationFormulae) {
61+
case PassCalculationFormulae.pytest:
62+
case PassCalculationFormulae.nosetests:
63+
break;
64+
default: {
65+
throw new Error('Unknown Test Pass Calculation');
66+
}
67+
}
68+
5869
const data = await this.fs.readFile(outputXmlFile);
5970
// Un-comment this line to capture the results file for later use in tests:
6071
//await fs.writeFile('/tmp/results.xml', data);
@@ -68,7 +79,7 @@ export class XUnitParser implements IXUnitParser {
6879
return reject(error);
6980
}
7081
try {
71-
updateTests(tests, parserResult.testsuite, passCalculationFormulae);
82+
updateTests(tests, parserResult.testsuite);
7283
} catch (err) {
7384
return reject(err);
7485
}
@@ -78,30 +89,25 @@ export class XUnitParser implements IXUnitParser {
7889
}
7990
}
8091

92+
// Set the number of passing tests given the total number.
93+
function setPassing(
94+
summary: TestSummary,
95+
total: number
96+
) {
97+
summary.passed = total - summary.failures - summary.skipped - summary.errors;
98+
}
99+
81100
// Update "tests" with the given results.
82101
function updateTests(
83102
tests: Tests,
84-
testSuiteResult: TestSuiteResult,
85-
passCalculationFormulae: PassCalculationFormulae
103+
testSuiteResult: TestSuiteResult
86104
) {
87105
tests.summary.errors = getSafeInt(testSuiteResult.$.errors);
88106
tests.summary.failures = getSafeInt(testSuiteResult.$.failures);
89107
tests.summary.skipped = getSafeInt(testSuiteResult.$.skips ? testSuiteResult.$.skips : testSuiteResult.$.skip);
90108
const testCount = getSafeInt(testSuiteResult.$.tests);
91109

92-
switch (passCalculationFormulae) {
93-
case PassCalculationFormulae.pytest: {
94-
tests.summary.passed = testCount - tests.summary.failures - tests.summary.skipped - tests.summary.errors;
95-
break;
96-
}
97-
case PassCalculationFormulae.nosetests: {
98-
tests.summary.passed = testCount - tests.summary.failures - tests.summary.skipped - tests.summary.errors;
99-
break;
100-
}
101-
default: {
102-
throw new Error('Unknown Test Pass Calculation');
103-
}
104-
}
110+
setPassing(tests.summary, testCount);
105111

106112
if (!Array.isArray(testSuiteResult.testcase)) {
107113
return;

0 commit comments

Comments
 (0)