@@ -7,19 +7,19 @@ import { glob } from 'glob';
7
7
* @param globPattern - The glob pattern to match JUnit XML files
8
8
* @returns Promise resolving to an array of all test cases from all matching files
9
9
*/
10
- export async function readJUnitReportsFromGlob ( globPattern : string ) : Promise < JUnitTestCase [ ] > {
11
- console . log ( 'Searching for JUnit reports matching pattern:' , globPattern ) ;
10
+ export async function readJUnitReportsFromGlob ( globPattern : string , options : { log ?: boolean } = { } ) : Promise < JUnitTestCase [ ] > {
11
+ if ( options . log ) console . log ( 'Searching for JUnit reports matching pattern:' , globPattern ) ;
12
12
13
13
const files = await glob ( globPattern ) ;
14
14
15
15
if ( files . length === 0 ) {
16
- console . warn ( 'No files found matching the pattern:' , globPattern ) ;
16
+ if ( options . log ) console . warn ( 'No files found matching the pattern:' , globPattern ) ;
17
17
return [ ] ;
18
18
}
19
19
20
- console . log ( `Found ${ files . length } JUnit report files` ) ;
20
+ if ( options . log ) console . log ( `Found ${ files . length } JUnit report files` ) ;
21
21
22
- const allTestCasesPromises = files . map ( file => parseJUnitReport ( file ) ) ;
22
+ const allTestCasesPromises = files . map ( file => parseJUnitReport ( file , options ) ) ;
23
23
const testCasesArrays = await Promise . all ( allTestCasesPromises ) ;
24
24
25
25
return testCasesArrays . flat ( ) ;
@@ -30,8 +30,8 @@ export async function readJUnitReportsFromGlob(globPattern: string): Promise<JUn
30
30
* @param filePath - Path to the JUnit XML file
31
31
* @returns Promise resolving to an array of test cases
32
32
*/
33
- export async function parseJUnitReport ( filePath : string ) : Promise < JUnitTestCase [ ] > {
34
- console . log ( 'Reading JUnit report file:' , filePath ) ;
33
+ export async function parseJUnitReport ( filePath : string , options : { log ?: boolean } = { } ) : Promise < JUnitTestCase [ ] > {
34
+ if ( options . log ) console . log ( 'Reading JUnit report file:' , filePath ) ;
35
35
const xml = await fs . readFile ( filePath , 'utf-8' ) ;
36
36
const result = await xml2js . parseStringPromise ( xml ) ;
37
37
const testCases : JUnitTestCase [ ] = [ ] ;
@@ -89,7 +89,7 @@ export async function parseJUnitReport(filePath: string): Promise<JUnitTestCase[
89
89
const suiteName = suite . $ . name ;
90
90
parseTestSuite ( suite , suiteName ) ;
91
91
} else {
92
- console . warn ( 'No test suites found in the provided file.' ) ;
92
+ if ( options . log ) console . warn ( 'No test suites found in the provided file.' ) ;
93
93
}
94
94
95
95
return testCases ;
0 commit comments