Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/support/steps/broken-links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ Then('WP Rocket settings links are not broken', async function (this: ICustomWor
}

// Normalize and filter URLs
const normalizedUrls = normalizeUrls(allHrefs, basePageUrl);
let normalizedUrls = normalizeUrls(allHrefs, basePageUrl);

// Exclude URLs that may trigger transactional side effects
const skipPatterns = [/\/renew\//i, /\/upgrade\//i];
normalizedUrls = new Set(
Array.from(normalizedUrls).filter(url => !skipPatterns.some(pattern => pattern.test(url)))
);
Comment on lines +60 to +66
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The URL skipping logic is duplicated: you filter normalizedUrls with skipPatterns here, but validateLinks also has built-in skipPatterns support (currently not used because it’s called without the 4th arg). Consider keeping the skip logic in one place by either (a) removing this manual filtering and passing skipPatterns into validateLinks, or (b) dropping the skipPatterns parameter from validateLinks if you want the step to own filtering.

Copilot uses AI. Check for mistakes.

// Warn if no valid URLs found to validate
if (normalizedUrls.size === 0) {
Expand Down
11 changes: 10 additions & 1 deletion utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,10 +651,19 @@ export const normalizeUrls = (
* @param {string} currentHost - Current host to distinguish internal from external URLs
* @return {Promise<string[]>} - Array of broken link strings in format "STATUS: url"
*/
export const validateLinks = async (page: Page, urls: Set<string>, currentHost: string): Promise<string[]> => {
export const validateLinks = async (
page: Page,
urls: Set<string>,
currentHost: string,
skipPatterns: RegExp[] = []
): Promise<string[]> => {
const brokenLinks: string[] = [];

for (const url of urls) {
// Skip URLs matching any skip pattern
if (skipPatterns.some(pattern => pattern.test(url))) {
continue;
}
try {
const response = await page.request.get(url, { maxRedirects: 5, timeout: 30000 });
const status = response.status();
Expand Down
Loading