Skip to content

Commit 2191591

Browse files
authored
Propose pages test changes (Copilot assisted) (#56568)
1 parent 458d7ae commit 2191591

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

src/frame/tests/pages.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,30 +50,42 @@ describe('pages module', () => {
5050
const englishPages = chain(pages)
5151
.filter(['languageCode', 'en'])
5252
.filter('redirect_from')
53-
.map((pages) => pick(pages, ['redirect_from', 'applicableVersions']))
53+
.map((pages) => pick(pages, ['redirect_from', 'applicableVersions', 'fullPath']))
5454
.value()
5555

56+
// Map from redirect path to Set of file paths
57+
const redirectToFiles = new Map()
5658
const versionedRedirects = []
5759

5860
englishPages.forEach((page) => {
5961
page.redirect_from.forEach((redirect) => {
6062
page.applicableVersions.forEach((version) => {
61-
versionedRedirects.push(removeFPTFromPath(path.posix.join('/', version, redirect)))
63+
const versioned = removeFPTFromPath(path.posix.join('/', version, redirect))
64+
versionedRedirects.push({ path: versioned, file: page.fullPath })
65+
if (!redirectToFiles.has(versioned)) {
66+
redirectToFiles.set(versioned, new Set())
67+
}
68+
redirectToFiles.get(versioned).add(page.fullPath)
6269
})
6370
})
6471
})
6572

66-
const duplicates = versionedRedirects.reduce((acc, el, i, arr) => {
67-
if (arr.indexOf(el) !== i && acc.indexOf(el) < 0) acc.push(el)
68-
return acc
69-
}, [])
70-
71-
const message = `Found ${duplicates.length} duplicate redirect_from ${
72-
duplicates.length === 1 ? 'path' : 'paths'
73-
}.
74-
Ensure that you don't define the same path more than once in the redirect_from property in a single file and across all English files.
75-
You may also receive this error if you have defined the same children property more than once.\n
76-
${duplicates.join('\n')}`
73+
// Only consider as duplicate if more than one unique file defines the same redirect
74+
const duplicates = Array.from(redirectToFiles.entries())
75+
.filter(([_, files]) => files.size > 1)
76+
.map(([path]) => path)
77+
78+
// Build a detailed message with sources for each duplicate
79+
const message =
80+
`Found ${duplicates.length} duplicate redirect_from path${duplicates.length === 1 ? '' : 's'}.
81+
Ensure that you don't define the same path more than once in the redirect_from property in a single file and across all English files.
82+
You may also receive this error if you have defined the same children property more than once.\n` +
83+
duplicates
84+
.map((dup) => {
85+
const files = Array.from(redirectToFiles.get(dup) || [])
86+
return `${dup}\n Defined in:\n ${files.join('\n ')}`
87+
})
88+
.join('\n\n')
7789
expect(duplicates.length, message).toBe(0)
7890
})
7991

0 commit comments

Comments
 (0)