-
Notifications
You must be signed in to change notification settings - Fork 5
/
speccheck.js
48 lines (43 loc) · 1.4 KB
/
speccheck.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
/* eslint-disable no-restricted-syntax */
// eslint-disable-next-line import/no-extraneous-dependencies
const expect = require('expect');
const util = require('util');
const fs = require('fs');
const readFile = util.promisify(fs.readFile);
function normalize(text) {
return text.replace(/(\s+|\n)/gi, ' ');
}
function joinElements(list) {
return normalize(list.map((v) => {
if (typeof v === 'string') {
return v;
}
return v.text;
}).join(''));
}
(async function start() {
try {
const specContent = await readFile('./specindex.json');
const specJson = JSON.parse(specContent);
// eslint-disable-next-line no-restricted-syntax
for (const tag of Object.keys(specJson.index)) {
const { props } = specJson.index[tag];
for (const section of ['Categories', 'ContextsInWhichThisElementCanBeUsed', 'ContentModel']) {
props[section].forEach((o) => {
try {
expect(normalize(o.textContent)).toStrictEqual(joinElements(o.elements));
} catch (e) {
throw new Error(`The tag: "${tag}" has a problem in the section "${section}": ${e}`);
}
});
}
}
// eslint-disable-next-line no-console
console.log('[speccheck.js] [OK] specindex healthy!');
process.exit(0);
} catch (e) {
// eslint-disable-next-line no-console
console.error('[speccheck.js] [FAIL] ', e);
process.exit(1);
}
}());