Skip to content

Commit

Permalink
Update allLinks.spec.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelvlach committed Jan 27, 2025
1 parent 7523a28 commit 2ecf866
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions agdb_web/e2e/allLinks.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { test, expect, Page } from "@playwright/test";

const validatedLinks: string[] = [];
const externalLinks: Map<Promise<Response>, string> = new Map();

const validateLinks = async (page: Page) => {
const links = await page
Expand All @@ -18,26 +19,25 @@ const validateLinks = async (page: Page) => {
!href.startsWith("javascript") &&
!href.startsWith("#")
) {
const error = `${sourcePageTitle} -> ${href}`;
await page.goto(href);

const pageTitle = await page.title();
expect(pageTitle.length, error).toBeGreaterThan(0);
expect(pageTitle, error).not.toContain("404");

validatedLinks.push(href);

if (!href.startsWith("http")) {
await page.goto(href);
await validateLinks(page);
} else {
externalLinks.set(fetch(href), `${sourcePageTitle} -> ${href}`);
}
}
}

for (const [f, error] of externalLinks) {
const r = await f;
expect(r.status, error).not.toBe(404);
}
};

test("should validate all links", async ({ page }) => {
test.setTimeout(300000);

await page.goto("http://localhost:5001/");

await validateLinks(page);
});

0 comments on commit 2ecf866

Please sign in to comment.