diff --git a/frontend/src/__tests__/cypress/cypress/tests/e2e/dashboardNavigation/testManifestLinks.cy.ts b/frontend/src/__tests__/cypress/cypress/tests/e2e/dashboardNavigation/testManifestLinks.cy.ts index 14317b3809..5d3d68cb85 100644 --- a/frontend/src/__tests__/cypress/cypress/tests/e2e/dashboardNavigation/testManifestLinks.cy.ts +++ b/frontend/src/__tests__/cypress/cypress/tests/e2e/dashboardNavigation/testManifestLinks.cy.ts @@ -2,10 +2,11 @@ import path from 'path'; describe('Verify that all the URLs referenced in the Manifest directory are operational', () => { it('Reads the manifest directory, filters out unwanted URLs, and validates the remaining URLs', () => { - //const baseDir = process.env.BASE_DIR || '/Users/acoughli'; - //const manifestsDir: string = path.resolve(baseDir, 'forked-odh-dashboard/odh-dashboard/manifests'); - // Use `__dirname` to determine the path relative to the current test file - const manifestsDir = path.resolve(__dirname, '../../../../../odh-dashboard/manifests'); + const baseDir = process.env.BASE_DIR || '/Users/acoughli'; + const manifestsDir: string = path.resolve( + baseDir, + 'forked-odh-dashboard/odh-dashboard/manifests', + ); cy.log('Resolved manifests directory:', manifestsDir); @@ -15,11 +16,19 @@ describe('Verify that all the URLs referenced in the Manifest directory are oper const filteredUrls = urls.filter( (url) => !url.includes('my-project-s2i-python-service') && + !url.includes('clusterip/') && + !url.includes('ClusterIP') && + !url.includes('s2i-python-service') && !url.includes('user-dev-rhoam-quarkus') && !url.includes('software.intel') && !url.includes('docs.openvino') && !url.includes('project-simple') && + !url.includes('example.apps') && + !url.includes('figma.com/figma/ns') && + !url.includes('localhost') && !url.includes('red_hat_3scale_api_management') && + !url.includes('anaconda.org/training/anaconda_introduction/notebook') && + !url.includes('scikit-learn.org/stable/tutorial/index.html') && !url.includes('console-openshift-console.apps.test-cluster.example.com/') && !url.includes('console-openshift-console.apps.test-cluster.example.com') && !url.includes('ibm.com/docs/SSQNUZ_latest/svc-welcome/watsonxai.html') && diff --git a/frontend/src/__tests__/cypress/cypress/utils/urlExtractor.ts b/frontend/src/__tests__/cypress/cypress/utils/urlExtractor.ts index a4c905b60e..2f9deda95a 100644 --- a/frontend/src/__tests__/cypress/cypress/utils/urlExtractor.ts +++ b/frontend/src/__tests__/cypress/cypress/utils/urlExtractor.ts @@ -21,12 +21,8 @@ export function extractLauncherUrls(): Cypress.Chainable { return extractedUrls; }); } - /** - * Extracts HTTPS URLs from YAML files in specified directories. - * - * @param {string} directory - The directory path to search for YAML files. - * @returns {string[]} An array of HTTPS URLs extracted from YAML files. + * Type definitions for YAML values. */ type YamlValue = string | number | boolean | null | YamlObject | YamlArray; interface YamlObject { @@ -34,27 +30,39 @@ interface YamlObject { } type YamlArray = YamlValue[]; -export function extractHttpsUrls(directory: string): string[] { - const httpsUrlSet = new Set(); - - function extractUrlsFromValue(value: YamlValue): void { - if (typeof value === 'string') { - const urlRegex = /https:\/\/[^\s\](),"'}*]*(?=[\s\](),"'}*]|$)/g; - const matches = value.match(urlRegex); - if (matches) { - matches.forEach((url) => { - const cleanUrl = url.replace(/\*+$/, ''); - httpsUrlSet.add(cleanUrl); - }); - } - } else if (typeof value === 'object' && value !== null) { - if (Array.isArray(value)) { - value.forEach(extractUrlsFromValue); - } else { - Object.values(value).forEach(extractUrlsFromValue); - } +/** + * Extracts URLs from a given value and adds them to the provided set. + * + * @param {YamlValue} value - The value to extract URLs from. + * @param {Set} urlSet - A set to store unique URLs. + */ +function extractUrlsFromValue(value: YamlValue, urlSet: Set): void { + if (typeof value === 'string') { + const urlRegex = /https?:\/\/[^\s\](),"'}*]*(?=[\s\](),"'}*]|$)/g; // Matches both HTTP and HTTPS + const matches = value.match(urlRegex); + if (matches) { + matches.forEach((url) => { + const cleanUrl = url.replace(/\*+$/, ''); // Remove trailing asterisks if any + urlSet.add(cleanUrl); // Add URL to the set for uniqueness + }); + } + } else if (typeof value === 'object' && value !== null) { + if (Array.isArray(value)) { + value.forEach((item) => extractUrlsFromValue(item, urlSet)); // Process array items + } else { + Object.values(value).forEach((val) => extractUrlsFromValue(val, urlSet)); // Process object values } } +} + +/** + * Extracts HTTPS URLs from YAML files in specified directories. + * + * @param {string} directory - The directory path to search for YAML files. + * @returns {string[]} An array of HTTPS URLs extracted from YAML files. + */ +export function extractHttpsUrls(directory: string): string[] { + const httpsUrlSet = new Set(); function walkDir(dir: string): void { const files = fs.readdirSync(dir); @@ -62,19 +70,41 @@ export function extractHttpsUrls(directory: string): string[] { const filePath = path.join(dir, file); const stat = fs.statSync(filePath); if (stat.isDirectory()) { - walkDir(filePath); + walkDir(filePath); // Recursively walk into subdirectories } else if (file.endsWith('.yaml') || file.endsWith('.yml')) { try { const content = fs.readFileSync(filePath, 'utf8'); - const yamlContent = yaml.load(content) as YamlValue; - extractUrlsFromValue(yamlContent); + const yamlDocuments = yaml.loadAll(content); // Load multiple YAML documents + + // Process each document + yamlDocuments.forEach((yamlContent) => { + // Check if yamlContent is an object or array and extract URLs + if (typeof yamlContent === 'object' && yamlContent !== null) { + // Check for 'spec' key and extract URL if it exists + if ( + 'spec' in yamlContent && + typeof yamlContent.spec === 'object' && + yamlContent.spec !== null + ) { + if ('url' in yamlContent.spec) { + // Use type assertion to specify that spec.url is a string or undefined + extractUrlsFromValue(yamlContent.spec.url as string, httpsUrlSet); + } + } + + // Process all other values to find additional URLs + Object.values(yamlContent).forEach((value) => + extractUrlsFromValue(value, httpsUrlSet), + ); + } + }); } catch (error) { - // Catches any file related errors + // Catches file reading errors } } }); } - walkDir(directory); - return Array.from(httpsUrlSet); + walkDir(directory); // Start walking the directory + return Array.from(httpsUrlSet); // Return the unique set of URLs as an array }