1
1
import { inject , injectable } from 'inversify' ;
2
2
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' ;
4
6
5
7
type TestSuiteResult = {
6
8
$ : {
@@ -55,6 +57,15 @@ export class XUnitParser implements IXUnitParser {
55
57
outputXmlFile : string ,
56
58
passCalculationFormulae : PassCalculationFormulae
57
59
) {
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
+
58
69
const data = await this . fs . readFile ( outputXmlFile ) ;
59
70
// Un-comment this line to capture the results file for later use in tests:
60
71
//await fs.writeFile('/tmp/results.xml', data);
@@ -68,7 +79,7 @@ export class XUnitParser implements IXUnitParser {
68
79
return reject ( error ) ;
69
80
}
70
81
try {
71
- updateTests ( tests , parserResult . testsuite , passCalculationFormulae ) ;
82
+ updateTests ( tests , parserResult . testsuite ) ;
72
83
} catch ( err ) {
73
84
return reject ( err ) ;
74
85
}
@@ -78,30 +89,25 @@ export class XUnitParser implements IXUnitParser {
78
89
}
79
90
}
80
91
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
+
81
100
// Update "tests" with the given results.
82
101
function updateTests (
83
102
tests : Tests ,
84
- testSuiteResult : TestSuiteResult ,
85
- passCalculationFormulae : PassCalculationFormulae
103
+ testSuiteResult : TestSuiteResult
86
104
) {
87
105
tests . summary . errors = getSafeInt ( testSuiteResult . $ . errors ) ;
88
106
tests . summary . failures = getSafeInt ( testSuiteResult . $ . failures ) ;
89
107
tests . summary . skipped = getSafeInt ( testSuiteResult . $ . skips ? testSuiteResult . $ . skips : testSuiteResult . $ . skip ) ;
90
108
const testCount = getSafeInt ( testSuiteResult . $ . tests ) ;
91
109
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 ) ;
105
111
106
112
if ( ! Array . isArray ( testSuiteResult . testcase ) ) {
107
113
return ;
0 commit comments