summaryrefslogtreecommitdiff
path: root/dev/lint/html-scripts.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-11-07 11:30:21 -0500
committerGitHub <noreply@github.com>2020-11-07 11:30:21 -0500
commitca26c648c2a62bccefa0daba462b3c7780da75fe (patch)
tree05f624484a330aaa67480ecc630aa8e9a7da9a34 /dev/lint/html-scripts.js
parentf4325b7db9dcfc68daefab349ec70256e9a05bea (diff)
Test link hrefs (#999)
* Add validatePath function * Validate <link>s
Diffstat (limited to 'dev/lint/html-scripts.js')
-rw-r--r--dev/lint/html-scripts.js27
1 files changed, 16 insertions, 11 deletions
diff --git a/dev/lint/html-scripts.js b/dev/lint/html-scripts.js
index 5aef7599..ae518252 100644
--- a/dev/lint/html-scripts.js
+++ b/dev/lint/html-scripts.js
@@ -31,23 +31,28 @@ function lstatSyncSafe(fileName) {
}
}
+function validatePath(src, fileName, extDir) {
+ assert.ok(typeof src === 'string', `<script> missing src attribute in ${fileName}`);
+ assert.ok(src.startsWith('/'), `<script> src attribute is not absolute in ${fileName} (src=${JSON.stringify(src)})`);
+ const relativeSrc = src.substring(1);
+ assert.ok(!path.isAbsolute(relativeSrc), `<script> src attribute is invalid in ${fileName} (src=${JSON.stringify(src)})`);
+ const fullSrc = path.join(extDir, relativeSrc);
+ const stats = lstatSyncSafe(fullSrc);
+ assert.ok(stats !== null, `<script> src file not found in ${fileName} (src=${JSON.stringify(src)})`);
+ assert.ok(stats.isFile(), `<script> src file invalid in ${fileName} (src=${JSON.stringify(src)})`);
+}
+
function validateHtmlScripts(fileName, extDir) {
const domSource = fs.readFileSync(fileName, {encoding: 'utf8'});
const dom = new JSDOM(domSource);
const {window} = dom;
const {document} = window;
try {
- const scripts = document.querySelectorAll('script');
- for (const script of scripts) {
- const {src} = script;
- assert.ok(typeof src === 'string', `<script> missing src attribute in ${fileName}`);
- assert.ok(src.startsWith('/'), `<script> src attribute is not absolute in ${fileName} (src=${JSON.stringify(src)})`);
- const relativeSrc = src.substring(1);
- assert.ok(!path.isAbsolute(relativeSrc), `<script> src attribute is invalid in ${fileName} (src=${JSON.stringify(src)})`);
- const fullSrc = path.join(extDir, relativeSrc);
- const stats = lstatSyncSafe(fullSrc);
- assert.ok(stats !== null, `<script> src file not found in ${fileName} (src=${JSON.stringify(src)})`);
- assert.ok(stats.isFile(), `<script> src file invalid in ${fileName} (src=${JSON.stringify(src)})`);
+ for (const {src} of document.querySelectorAll('script')) {
+ validatePath(src, fileName, extDir);
+ }
+ for (const {href} of document.querySelectorAll('link')) {
+ validatePath(href, fileName, extDir);
}
} finally {
window.close();