Skip to content

Commit bd46766

Browse files
committed
feat: add package dependency file to each test suite
Signed-off-by: Saw-jan <[email protected]>
1 parent 62b986a commit bd46766

File tree

7 files changed

+93
-62
lines changed

7 files changed

+93
-62
lines changed

.drone.star

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -727,10 +727,8 @@ def e2eTests(ctx):
727727
"environment": environment,
728728
"commands": [
729729
"cat %s/tests/drone/suites.env" % dir["web"],
730-
"source %s/tests/drone/suites.env || true" % dir["web"],
730+
". %s/tests/drone/suites.env || true" % dir["web"],
731731
"cd tests/e2e",
732-
"echo $TEST_SUITES",
733-
"echo $FEATURE_FILES",
734732
"bash run-e2e.sh",
735733
],
736734
}] + \

tests/drone/filterTestSuitesToRun.js

Lines changed: 70 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -7,60 +7,68 @@ const targetBranch = process.env.DRONE_TARGET_BRANCH || 'master'
77
// INFO: 1 and 2 elements are node and script name respectively
88
const scriptDir = path.dirname(process.argv[1])
99
const suitesToCheck = process.argv[2]
10+
.split(',')
11+
.map((suite) => suite.trim())
12+
.filter((suite) => suite)
1013

11-
const pacToTests = {
12-
'web-app-activities': [],
13-
'web-app-admin-settings': ['admin-settings', 'keycloak', 'smoke', 'user-settings'],
14-
'web-app-app-store': ['app-store'],
15-
'web-app-epub-reader': [],
16-
'web-app-external': ['app-provider'],
17-
'web-app-files': [
18-
'a11y',
19-
'admin-settings',
20-
'app-provider',
21-
'app-store',
22-
'file-action',
23-
'journeys',
24-
'keycloak',
25-
'navigation',
26-
'ocm',
27-
'oidc',
28-
'search',
29-
'shares',
30-
'smoke',
31-
'spaces',
32-
'user-settings'
33-
],
34-
'web-app-ocm': ['ocm'],
35-
'web-app-password-protected-folders': ['file-action'],
36-
'web-app-pdf-viewer': [],
37-
'web-app-preview': ['spaces', 'shares', 'file-action', 'navigation', 'ocm'],
38-
'web-app-search': [
39-
'a11y',
40-
'admin-settings',
41-
'app-provider',
42-
'app-store',
43-
'file-action',
44-
'journeys',
45-
'keycloak',
46-
'navigation',
47-
'ocm',
48-
'oidc',
49-
'search',
50-
'shares',
51-
'smoke',
52-
'spaces',
53-
'user-settings'
54-
],
55-
'web-app-text-editor': ['keycloak', 'oidc'],
56-
'web-app-webfinger': []
57-
}
14+
// list of test suites with dependent packages
15+
// Example:
16+
// {
17+
// 'web-app-ocm': ['ocm'],
18+
// 'web-app-search': ['search']
19+
// }
20+
const packageToTestSuiteMap = {}
21+
22+
/*
23+
--------------------
24+
web packages
25+
--------------------
26+
*/
27+
const excludePackages = ['web-container', 'web-test-helpers']
28+
// default packages that affect all test suites
29+
const defaultPackages = ['web-client', 'web-runtime', 'web-pkg']
30+
const packagesDir = `${scriptDir}/../../packages`
31+
const allWebPackages = fs
32+
.readdirSync(packagesDir)
33+
.filter(
34+
(entry) =>
35+
entry.startsWith('web-') &&
36+
fs.statSync(path.join(packagesDir, entry)).isDirectory() &&
37+
!excludePackages.includes(entry)
38+
)
5839

59-
// get test suites
40+
/*
41+
--------------------
42+
test suites
43+
--------------------
44+
*/
6045
const testSuitesDir = `${scriptDir}/../e2e/cucumber/features`
61-
const testSuites = fs
62-
.readdirSync(testSuitesDir)
63-
.filter((entry) => fs.statSync(path.join(testSuitesDir, entry)).isDirectory())
46+
const testSuites = fs.readdirSync(testSuitesDir).filter((entry) => {
47+
if (!fs.statSync(path.join(testSuitesDir, entry)).isDirectory()) {
48+
return false
49+
}
50+
const webPackagesFile = path.join(testSuitesDir, entry, 'web-packages.txt')
51+
if (fs.existsSync(webPackagesFile)) {
52+
const content = fs.readFileSync(webPackagesFile, 'utf-8')
53+
const depPackages = content.split('\n').filter((line) => line && line.startsWith('web-'))
54+
if (depPackages.length) {
55+
depPackages.forEach((pkg) => {
56+
if (!(pkg in packageToTestSuiteMap)) {
57+
packageToTestSuiteMap[pkg] = []
58+
}
59+
!packageToTestSuiteMap[pkg].includes(entry) && packageToTestSuiteMap[pkg].push(entry)
60+
})
61+
return true
62+
}
63+
}
64+
allWebPackages.forEach((pkg) => {
65+
if (!(pkg in packageToTestSuiteMap)) {
66+
packageToTestSuiteMap[pkg] = []
67+
}
68+
!packageToTestSuiteMap[pkg].includes(entry) && packageToTestSuiteMap[pkg].push(entry)
69+
})
70+
return true
71+
})
6472

6573
function getChangedFiles() {
6674
const changedFiles = execSync(`git diff --name-only origin/${targetBranch} HEAD`).toString()
@@ -72,7 +80,7 @@ function getPackageFromFile(file) {
7280
if (!file.startsWith('packages/')) {
7381
return
7482
}
75-
const packages = Object.keys(pacToTests)
83+
const packages = Object.keys(packageToTestSuiteMap)
7684
for (const pkg of packages) {
7785
if (file.startsWith(`packages/${pkg}`)) {
7886
return pkg
@@ -83,6 +91,7 @@ function getPackageFromFile(file) {
8391
function getAffectedTestSuites(changedFiles) {
8492
const affectedSuites = new Set()
8593
for (const file of changedFiles) {
94+
// run all test suites if changes are in the following paths
8695
if (
8796
file.startsWith('tests/e2e/') ||
8897
file.startsWith('tests/drone/') ||
@@ -93,14 +102,16 @@ function getAffectedTestSuites(changedFiles) {
93102
return testSuites
94103
}
95104
const packageName = getPackageFromFile(file)
96-
if (packageName && packageName in pacToTests) {
97-
pacToTests[packageName].forEach((suite) => affectedSuites.add(suite))
105+
if (packageName && packageName in packageToTestSuiteMap) {
106+
packageToTestSuiteMap[packageName].forEach((suite) => affectedSuites.add(suite))
98107
}
99108
}
100109
return Array.from(affectedSuites)
101110
}
102111

103112
function createSuitesToRunEnvFile(suites = []) {
113+
console.log('[INFO] Provided test suites/features:\n - ' + suitesToCheck.join('\n - '))
114+
console.log('[INFO] Test suites/features to run:\n - ' + suites.join('\n - '))
104115
const envContent = ['TEST_SUITES', suites.join(',')]
105116
if (suites[0].startsWith('cucumber/')) {
106117
envContent[0] = ['FEATURE_FILES']
@@ -117,11 +128,11 @@ function main() {
117128
}
118129
const affectedTestSuites = getAffectedTestSuites(changedFiles)
119130
if (affectedTestSuites.length === 0) {
120-
console.log('[INFO] No affected test suites to run.')
131+
console.log('[INFO] No affected test suites/features to run.')
121132
process.exit(78) // Skip the pipeline
122133
}
123-
if (suitesToCheck) {
124-
const suitesToRun = suitesToCheck.split(',').filter((suite) => {
134+
if (suitesToCheck.length) {
135+
const suitesToRun = suitesToCheck.filter((suite) => {
125136
suite = suite.trim()
126137
if (suite.startsWith('cucumber/')) {
127138
suite = suite.replace('cucumber/features/', '').split('/').shift()
@@ -130,8 +141,8 @@ function main() {
130141
})
131142
if (suitesToRun.length === 0) {
132143
console.log(
133-
'[INFO] The following test suites are not affected and will be skipped:',
134-
suitesToCheck.split(',').join('\n')
144+
'[INFO] The following test suites/features are not affected and will be skipped:\n - ',
145+
suitesToCheck.join('\n - ')
135146
)
136147
process.exit(78) // Skip the pipeline
137148
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# FOR CI ONLY
2+
# Run the test suite only if the changes are in the following packages:
3+
4+
web-app-admin-settings
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# FOR CI ONLY
2+
# Run the test suite only if the changes are in the following packages:
3+
4+
web-app-external
5+
web-app-files
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# FOR CI ONLY
2+
# Run the test suite only if the changes are in the following packages:
3+
4+
web-app-app-store
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# FOR CI ONLY
2+
# Run the test suite only if the changes are in the following packages:
3+
4+
web-app-files
5+
web-app-preview
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# FOR CI ONLY
2+
# Run the test suite only if the changes are in the following packages:
3+
4+
web-app-ocm

0 commit comments

Comments
 (0)