Skip to content

Commit 9349e89

Browse files
committed
exclude /renew and /upgrade URLs from broken link validation
1 parent 6a522c8 commit 9349e89

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/support/steps/broken-links.ts

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

5959
// Normalize and filter URLs
60-
const normalizedUrls = normalizeUrls(allHrefs, basePageUrl);
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+
);
6167

6268
// Warn if no valid URLs found to validate
6369
if (normalizedUrls.size === 0) {

utils/helpers.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,10 +651,19 @@ export const normalizeUrls = (
651651
* @param {string} currentHost - Current host to distinguish internal from external URLs
652652
* @return {Promise<string[]>} - Array of broken link strings in format "STATUS: url"
653653
*/
654-
export const validateLinks = async (page: Page, urls: Set<string>, currentHost: string): Promise<string[]> => {
654+
export const validateLinks = async (
655+
page: Page,
656+
urls: Set<string>,
657+
currentHost: string,
658+
skipPatterns: RegExp[] = []
659+
): Promise<string[]> => {
655660
const brokenLinks: string[] = [];
656661

657662
for (const url of urls) {
663+
// Skip URLs matching any skip pattern
664+
if (skipPatterns.some(pattern => pattern.test(url))) {
665+
continue;
666+
}
658667
try {
659668
const response = await page.request.get(url, { maxRedirects: 5, timeout: 30000 });
660669
const status = response.status();

0 commit comments

Comments
 (0)