Skip to content

Commit cec8c48

Browse files
committed
update tests
1 parent 5292156 commit cec8c48

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

scripts/test-hrefs.mjs

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,22 @@ const showErrorMsg = failedTest => {
109109
console.log(stderr);
110110
};
111111

112+
const createApiIndexModules = version => {
113+
const dir = path.join(__dirname, "..", "data", "api", version);
114+
const modules = fs.readdirSync(dir).filter(file => file !== "toc_tree.json");
115+
const paths = modules.reduce((acc, file) => {
116+
const json = JSON.parse(fs.readFileSync(path.join(dir, file)));
117+
const keys = Object.keys(json);
118+
119+
const paths = keys.map(modulePath => path.join(version, "api", modulePath));
120+
121+
return acc.concat(paths);
122+
}, []);
123+
return paths;
124+
};
125+
126+
const apiIndexModules = createApiIndexModules("latest")
127+
112128
const testFile = (pageMap, test) => {
113129
const filepath = test.filepath;
114130

@@ -161,11 +177,30 @@ const testFile = (pageMap, test) => {
161177
}
162178
}
163179

180+
if (resolved.startsWith("/pages/docs/manual/latest/api")) {
181+
const pathToModule = resolved.replace("/pages/docs/manual/", "");
182+
const pathExists = apiIndexModules.includes(pathToModule);
183+
184+
if (pathExists) {
185+
results.push({
186+
status: "ok",
187+
link
188+
});
189+
} else {
190+
const { line, column } = link.position.start;
191+
const stderr = `${filepath}: Unknown href '${url}' in line ${line}:${column}`;
192+
results.push({
193+
status: "failed",
194+
filepath,
195+
stderr,
196+
link
197+
});
198+
}
199+
return;
200+
}
201+
164202
// If there's no page stated the relative link
165203
if (!pageMap[resolved]) {
166-
if (url.includes("/docs/manual/latest/api") || url.includes("api")) {
167-
return;
168-
}
169204
const { line, column } = link.position.start;
170205
const stderr = `${filepath}: Unknown href '${url}' in line ${line}:${column}`;
171206
results.push({
@@ -225,8 +260,6 @@ const main = () => {
225260

226261
const pageMap = createPageIndex(allFiles);
227262

228-
//console.log(pageMap);
229-
//return;
230263
const processedFiles = files.map(processFile);
231264

232265
const allTested = processedFiles.map(file => testFile(pageMap, file));

0 commit comments

Comments
 (0)