-
Notifications
You must be signed in to change notification settings - Fork 191
OCISDEV-220: run e2e test suites based on the changes in web packages #12865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
saw-jan
merged 3 commits into
master
from
tests/OCISDEV-220/run-e2e-tests-only-related-to-changed-packages
Nov 20, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| import { execSync } from 'child_process' | ||
| import fs from 'fs' | ||
| import path from 'path' | ||
|
|
||
| const targetBranch = process.env.DRONE_TARGET_BRANCH || 'master' | ||
|
|
||
| // paths that if changed will run all test suites | ||
| const mandatoryPaths = ['tests/e2e/', 'tests/drone/', '.drone.star', '.drone.env', 'package.json'] | ||
|
|
||
| // INFO: 1 and 2 elements are node and script name respectively | ||
| const scriptDir = path.dirname(process.argv[1]) | ||
| const suitesToCheck = process.argv[2] | ||
| .split(',') | ||
| .map((suite) => suite.trim()) | ||
| .filter((suite) => suite) | ||
|
|
||
| // list of test suites with dependent packages | ||
| // Example: | ||
| // { | ||
| // 'web-app-ocm': ['ocm'], | ||
| // 'web-app-search': ['search'] | ||
| // } | ||
| const packageToTestSuiteMap = {} | ||
|
|
||
| /* | ||
| -------------------- | ||
| web packages | ||
| -------------------- | ||
| */ | ||
| const excludePackages = ['web-container', 'web-test-helpers'] | ||
| // default packages that affect all test suites | ||
| const defaultDependentPackages = ['design-system', 'web-client', 'web-runtime', 'web-pkg'] | ||
| const packagesDir = `${scriptDir}/../../packages` | ||
| const allWebPackages = fs | ||
| .readdirSync(packagesDir) | ||
| .filter( | ||
| (entry) => | ||
| entry.startsWith('web-') && | ||
| !defaultDependentPackages.includes(entry) && | ||
| fs.statSync(path.join(packagesDir, entry)).isDirectory() && | ||
| !excludePackages.includes(entry) | ||
| ) | ||
|
|
||
| /* | ||
| -------------------- | ||
| test suites | ||
| -------------------- | ||
| */ | ||
| const testSuitesDir = `${scriptDir}/../e2e/cucumber/features` | ||
| const testSuites = fs.readdirSync(testSuitesDir).filter((entry) => { | ||
| if (!fs.statSync(path.join(testSuitesDir, entry)).isDirectory()) { | ||
| return false | ||
| } | ||
| const webPackagesFile = path.join(testSuitesDir, entry, 'web-packages.txt') | ||
| if (fs.existsSync(webPackagesFile)) { | ||
| const content = fs.readFileSync(webPackagesFile, 'utf-8') | ||
| const depPackages = content.split('\n').filter((line) => line && line.startsWith('web-')) | ||
| if (depPackages.length) { | ||
| mapDependentPackagesToTestSuite(entry, depPackages) | ||
| return | ||
| } | ||
| } | ||
| // make all packages as dependent | ||
| mapDependentPackagesToTestSuite(entry, allWebPackages) | ||
| return | ||
| }) | ||
|
|
||
| function mapDependentPackagesToTestSuite(testSuite, depPackages) { | ||
| depPackages.forEach((pkg) => { | ||
| if (!fs.existsSync(path.join(packagesDir, pkg))) { | ||
| throw new Error( | ||
| `Package "${pkg}" listed as dependent for test suite "${testSuite}" does not exist.\nPath: ${path.join(packagesDir, pkg)}` | ||
| ) | ||
| } | ||
|
|
||
| if (!(pkg in packageToTestSuiteMap)) { | ||
| packageToTestSuiteMap[pkg] = [] | ||
| } | ||
| !packageToTestSuiteMap[pkg].includes(testSuite) && packageToTestSuiteMap[pkg].push(testSuite) | ||
| }) | ||
| defaultDependentPackages.forEach((pkg) => { | ||
| if (!(pkg in packageToTestSuiteMap)) { | ||
| packageToTestSuiteMap[pkg] = [] | ||
| } | ||
| !packageToTestSuiteMap[pkg].includes(testSuite) && packageToTestSuiteMap[pkg].push(testSuite) | ||
| }) | ||
| } | ||
|
|
||
| function getChangedFiles() { | ||
| const changedFiles = execSync(`git diff --name-only origin/${targetBranch} HEAD`).toString() | ||
| console.log('[INFO] Changed files:\n', changedFiles) | ||
| return [...new Set([...changedFiles.split('\n')])].filter((file) => file) | ||
| } | ||
|
|
||
| function getPackageFromFile(file) { | ||
| if (!file.startsWith('packages/')) { | ||
| return | ||
| } | ||
| const packages = Object.keys(packageToTestSuiteMap) | ||
| for (const pkg of packages) { | ||
| if (file.startsWith(`packages/${pkg}`)) { | ||
| return pkg | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function getAffectedTestSuites(changedFiles) { | ||
| const affectedSuites = new Set() | ||
| for (const file of changedFiles) { | ||
| if (mandatoryPaths.some((mandatoryPath) => file.startsWith(mandatoryPath))) { | ||
| // run all test suites | ||
| return testSuites | ||
| } | ||
| const packageName = getPackageFromFile(file) | ||
| if (packageName && packageName in packageToTestSuiteMap) { | ||
| packageToTestSuiteMap[packageName].forEach((suite) => affectedSuites.add(suite)) | ||
| } | ||
| } | ||
| return Array.from(affectedSuites) | ||
| } | ||
|
|
||
| function createSuitesToRunEnvFile(suites = []) { | ||
| console.log('[INFO] Provided test suites/features:\n - ' + suitesToCheck.join('\n - ')) | ||
| console.log('[INFO] Test suites/features to run:\n - ' + suites.join('\n - ')) | ||
| const envContent = ['TEST_SUITES', suites.join(',')] | ||
| if (suites[0].startsWith('cucumber/')) { | ||
| envContent[0] = ['FEATURE_FILES'] | ||
| } | ||
| // create suites.env file in the same directory as the script | ||
| fs.writeFileSync(`${scriptDir}/suites.env`, envContent.join('=')) | ||
| } | ||
|
|
||
| function main() { | ||
| const changedFiles = getChangedFiles() | ||
| if (changedFiles.length === 0) { | ||
| console.log('[INFO] No changes detected.') | ||
| process.exit(78) // Skip the pipeline | ||
| } | ||
| const affectedTestSuites = getAffectedTestSuites(changedFiles) | ||
| if (affectedTestSuites.length === 0) { | ||
| console.log('[INFO] No affected test suites/features to run.') | ||
| process.exit(78) // Skip the pipeline | ||
| } | ||
| if (suitesToCheck.length) { | ||
| const suitesToRun = suitesToCheck.filter((suite) => { | ||
| suite = suite.trim() | ||
| if (suite.startsWith('cucumber/')) { | ||
| suite = suite.replace('cucumber/features/', '').split('/').shift() | ||
| } | ||
| return affectedTestSuites.includes(suite) | ||
| }) | ||
| if (suitesToRun.length === 0) { | ||
| console.log( | ||
| '[INFO] The following test suites/features are not affected and will be skipped:\n - ', | ||
| suitesToCheck.join('\n - ') | ||
| ) | ||
| process.exit(78) // Skip the pipeline | ||
| } | ||
| createSuitesToRunEnvFile(suitesToRun) | ||
| return | ||
| } | ||
| createSuitesToRunEnvFile(affectedTestSuites) | ||
| } | ||
|
|
||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| ###################################################################### | ||
| # USED FOR CI ONLY # | ||
| # Run the test suite only if the changes are in the listed packages. # | ||
| # # | ||
| # List of web packages that affect this test suite. # | ||
| ###################################################################### | ||
|
|
||
| web-app-admin-settings |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.