/
validate-links.js
57 lines (50 loc) · 1.46 KB
/
validate-links.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"use strict";
const path = require("path");
const TapRender = require("@munter/tap-render");
const spot = require("tap-spot");
const hyperlink = require("hyperlink");
const tapRenderInstance = new TapRender();
tapRenderInstance.pipe(spot()).pipe(process.stdout);
const skipPatterns = [
"https://",
"fragment-redirect",
"migrating-to",
"/blog",
"/play",
"/team",
"/donate",
"/docs/latest",
'src="null"'
];
/**
* Filter function to mark tests as skipped.
* Tests for which this function returns `true' are not considered failed.
* @param {Object} report hyperlink's test report for a link.
* @returns {boolean} `true` if the report contains any of `skipPatterns`.
*/
function skipFilter(report) {
return Object.values(report).some(value =>
skipPatterns.some(pattern => String(value).includes(pattern)));
}
(async () => {
try {
await hyperlink(
{
inputUrls: ["../_site/index.html"],
root: path.resolve(__dirname, "../_site"),
canonicalRoot: "https://eslint.org/docs/head/",
recursive: true,
internalOnly: true,
pretty: true,
concurrency: 25,
skipFilter
},
tapRenderInstance
);
} catch (err) {
console.log(err.stack);
process.exit(1);
}
const results = tapRenderInstance.close();
process.exit(results.fail ? 1 : 0);
})();