@@ -7,14 +7,17 @@ const targetBranch = process.env.DRONE_TARGET_BRANCH || 'master'
77// INFO: 1 and 2 elements are node and script name respectively
88const scriptDir = path . dirname ( process . argv [ 1 ] )
99const suitesToCheck = process . argv [ 2 ]
10+ . split ( ',' )
11+ . map ( ( suite ) => suite . trim ( ) )
12+ . filter ( ( suite ) => suite )
1013
1114// list of test suites with dependent packages
1215// Example:
1316// {
1417// 'ocm': ['web-app-ocm'],
1518// 'search': ['web-app-search']
1619// }
17- const testSuiteToPackageMap = { }
20+ const packageToTestSuiteMap = { }
1821
1922/*
2023--------------------
@@ -49,11 +52,21 @@ const testSuites = fs.readdirSync(testSuitesDir).filter((entry) => {
4952 const content = fs . readFileSync ( webPackagesFile , 'utf-8' )
5053 const depPackages = content . split ( '\n' ) . filter ( ( line ) => line && line . startsWith ( 'web-' ) )
5154 if ( depPackages . length ) {
52- testSuiteToPackageMap [ entry ] = [ ...new Set ( [ ...depPackages , ...defaultPackages ] ) ]
55+ depPackages . forEach ( ( pkg ) => {
56+ if ( ! ( pkg in packageToTestSuiteMap ) ) {
57+ packageToTestSuiteMap [ pkg ] = [ ]
58+ }
59+ ! packageToTestSuiteMap [ pkg ] . includes ( entry ) && packageToTestSuiteMap [ pkg ] . push ( entry )
60+ } )
5361 return true
5462 }
5563 }
56- testSuiteToPackageMap [ entry ] = allWebPackages
64+ allWebPackages . forEach ( ( pkg ) => {
65+ if ( ! ( pkg in packageToTestSuiteMap ) ) {
66+ packageToTestSuiteMap [ pkg ] = [ ]
67+ }
68+ ! packageToTestSuiteMap [ pkg ] . includes ( entry ) && packageToTestSuiteMap [ pkg ] . push ( entry )
69+ } )
5770 return true
5871} )
5972
@@ -67,7 +80,7 @@ function getPackageFromFile(file) {
6780 if ( ! file . startsWith ( 'packages/' ) ) {
6881 return
6982 }
70- const packages = Object . keys ( pacToTests )
83+ const packages = Object . keys ( packageToTestSuiteMap )
7184 for ( const pkg of packages ) {
7285 if ( file . startsWith ( `packages/${ pkg } ` ) ) {
7386 return pkg
@@ -89,14 +102,16 @@ function getAffectedTestSuites(changedFiles) {
89102 // return testSuites
90103 // }
91104 const packageName = getPackageFromFile ( file )
92- if ( packageName && packageName in pacToTests ) {
93- pacToTests [ packageName ] . forEach ( ( suite ) => affectedSuites . add ( suite ) )
105+ if ( packageName && packageName in packageToTestSuiteMap ) {
106+ packageToTestSuiteMap [ packageName ] . forEach ( ( suite ) => affectedSuites . add ( suite ) )
94107 }
95108 }
96109 return Array . from ( affectedSuites )
97110}
98111
99112function createSuitesToRunEnvFile ( suites = [ ] ) {
113+ console . log ( '[INFO] Provided test suites/scenarios:\n - ' + suitesToCheck . join ( '\n - ' ) )
114+ console . log ( '[INFO] Test suites/scenarios to run:\n - ' + suites . join ( '\n - ' ) )
100115 const envContent = [ 'TEST_SUITES' , suites . join ( ',' ) ]
101116 if ( suites [ 0 ] . startsWith ( 'cucumber/' ) ) {
102117 envContent [ 0 ] = [ 'FEATURE_FILES' ]
@@ -116,8 +131,8 @@ function main() {
116131 console . log ( '[INFO] No affected test suites to run.' )
117132 process . exit ( 78 ) // Skip the pipeline
118133 }
119- if ( suitesToCheck ) {
120- const suitesToRun = suitesToCheck . split ( ',' ) . filter ( ( suite ) => {
134+ if ( suitesToCheck . length ) {
135+ const suitesToRun = suitesToCheck . filter ( ( suite ) => {
121136 suite = suite . trim ( )
122137 if ( suite . startsWith ( 'cucumber/' ) ) {
123138 suite = suite . replace ( 'cucumber/features/' , '' ) . split ( '/' ) . shift ( )
@@ -127,7 +142,7 @@ function main() {
127142 if ( suitesToRun . length === 0 ) {
128143 console . log (
129144 '[INFO] The following test suites are not affected and will be skipped:' ,
130- suitesToCheck . split ( ',' ) . join ( '\n' )
145+ suitesToCheck . join ( '\n' )
131146 )
132147 process . exit ( 78 ) // Skip the pipeline
133148 }
0 commit comments