Skip to content

Commit bc8c442

Browse files
committed
fix code
1 parent 39981dd commit bc8c442

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

tests/playwright/link-checker.spec.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ test('crawl internal links: fail on non-2xx and not-found content', async ({ req
1313

1414
const toVisit: string[] = [`${BASE}/`]
1515
const visited = new Set<string>()
16+
const discovered = new Set<string>(toVisit)
1617
const errors: { url: string; status?: number; reason: string }[] = []
17-
const maxPages = 250
1818

19-
while (toVisit.length && visited.size < maxPages) {
19+
while (toVisit.length) {
2020
const url = toVisit.shift()!
2121
if (visited.has(url))
2222
continue
@@ -52,13 +52,17 @@ test('crawl internal links: fail on non-2xx and not-found content', async ({ req
5252
else {
5353
absolute = new URL(href, url).toString()
5454
}
55-
if (!visited.has(absolute))
55+
if (!visited.has(absolute)) {
56+
if (!discovered.has(absolute))
57+
discovered.add(absolute)
5658
toVisit.push(absolute)
59+
}
5760
}
5861
}
5962

6063
if (errors.length)
6164
console.error('Broken pages detected:', errors)
6265

63-
expect(errors.length).toBe(0)
66+
expect(errors.length, 'no broken pages detected').toBe(0)
67+
expect(visited.size, '100% internal-link coverage').toBe(discovered.size)
6468
})

0 commit comments

Comments
 (0)