Skip to content

Commit 0efa474

Browse files
committed
Consolidate skip logic and extend patterns to /express-checkout
1 parent 369d737 commit 0efa474

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/support/steps/broken-links.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,7 @@ Then('WP Rocket settings links are not broken', async function (this: ICustomWor
5757
}
5858

5959
// Normalize and filter URLs
60-
let normalizedUrls = normalizeUrls(allHrefs, basePageUrl);
61-
62-
// Exclude URLs that may trigger transactional side effects
63-
const skipPatterns = [/\/renew\//i, /\/upgrade\//i];
64-
normalizedUrls = new Set(
65-
Array.from(normalizedUrls).filter(url => !skipPatterns.some(pattern => pattern.test(url)))
66-
);
60+
const normalizedUrls = normalizeUrls(allHrefs, basePageUrl);
6761

6862
// Warn if no valid URLs found to validate
6963
if (normalizedUrls.size === 0) {
@@ -72,8 +66,9 @@ Then('WP Rocket settings links are not broken', async function (this: ICustomWor
7266
return;
7367
}
7468

75-
// Validate all collected URLs
76-
const brokenLinks = await validateLinks(this.page, normalizedUrls, currentHost);
69+
// Validate all collected URLs, excluding URLs that may trigger transactional side effects
70+
const skipPatterns = [/\/renew\//i, /\/upgrade\//i, /\/express-checkout/i];
71+
const brokenLinks = await validateLinks(this.page, normalizedUrls, currentHost, skipPatterns);
7772

7873
// Report all broken links at once
7974
expect(brokenLinks, 'Broken links detected').toHaveLength(0);

utils/helpers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ export const normalizeUrls = (
649649
* @param {Page} page - The Playwright page object
650650
* @param {Set<string>} urls - Set of URLs to validate
651651
* @param {string} currentHost - Current host to distinguish internal from external URLs
652+
* @param {RegExp[]} [skipPatterns=[]] - Optional array of regex patterns to skip URLs matching any pattern
652653
* @return {Promise<string[]>} - Array of broken link strings in format "STATUS: url"
653654
*/
654655
export const validateLinks = async (
@@ -658,12 +659,14 @@ export const validateLinks = async (
658659
skipPatterns: RegExp[] = []
659660
): Promise<string[]> => {
660661
const brokenLinks: string[] = [];
662+
const validatedUrls: string[] = [];
661663

662664
for (const url of urls) {
663665
// Skip URLs matching any skip pattern
664666
if (skipPatterns.some(pattern => pattern.test(url))) {
665667
continue;
666668
}
669+
validatedUrls.push(url);
667670
try {
668671
const response = await page.request.get(url, { maxRedirects: 5, timeout: 30000 });
669672
const status = response.status();

0 commit comments

Comments
 (0)