@@ -3,24 +3,65 @@ const junit = require('./junit');
33const xunit = require ( './xunit' ) ;
44const mocha = require ( './mocha' ) ;
55const cucumber = require ( './cucumber' ) ;
6+ const TestResult = require ( '../models/TestResult' ) ;
7+ const { getMatchingFilePaths } = require ( '../helpers/helper' ) ;
68
7- function parse ( options ) {
8- switch ( options . type ) {
9+ /**
10+ * @param {import('../models/TestResult')[] } results
11+ */
12+ function merge ( results ) {
13+ const main_result = new TestResult ( ) ;
14+ for ( let i = 0 ; i < results . length ; i ++ ) {
15+ const current_result = results [ i ] ;
16+ if ( ! main_result . name ) {
17+ main_result . name = current_result . name ;
18+ }
19+ main_result . total = main_result . total + current_result . total ;
20+ main_result . passed = main_result . passed + current_result . passed ;
21+ main_result . failed = main_result . failed + current_result . failed ;
22+ main_result . errors = main_result . errors + current_result . errors ;
23+ main_result . skipped = main_result . skipped + current_result . skipped ;
24+ main_result . retried = main_result . retried + current_result . retried ;
25+ main_result . duration = main_result . duration + current_result . duration ;
26+ main_result . suites = main_result . suites . concat ( ...current_result . suites ) ;
27+ }
28+ main_result . status = results . every ( _result => _result . status === 'PASS' ) ? 'PASS' : 'FAIL' ;
29+ return main_result ;
30+ }
31+
32+ function getParser ( type ) {
33+ switch ( type ) {
934 case 'testng' :
10- return testng . parse ( options ) ;
35+ return testng ;
1136 case 'junit' :
12- return junit . parse ( options ) ;
37+ return junit ;
1338 case 'xunit' :
14- return xunit . parse ( options ) ;
39+ return xunit ;
1540 case 'mocha' :
16- return mocha . parse ( options ) ;
41+ return mocha ;
1742 case 'cucumber' :
18- return cucumber . parse ( options ) ;
43+ return cucumber ;
1944 default :
2045 throw `UnSupported Result Type - ${ options . type } ` ;
2146 }
2247}
2348
49+ /**
50+ * @param {import('../index').ParseOptions } options
51+ */
52+ function parse ( options ) {
53+ const parser = getParser ( options . type ) ;
54+ const results = [ ] ;
55+ for ( let i = 0 ; i < options . files . length ; i ++ ) {
56+ const matched_files = getMatchingFilePaths ( options . files [ i ] ) ;
57+ for ( let j = 0 ; j < matched_files . length ; j ++ ) {
58+ const file = matched_files [ j ] ;
59+ results . push ( parser . parse ( file ) ) ;
60+ }
61+ }
62+ return merge ( results ) ;
63+ }
64+
2465module . exports = {
2566 parse
2667}
0 commit comments