Skip to content

Commit 3fda9a6

Browse files
committed
Add a few tests on consolidated CSS file
This adds tests to guarantee that entries are unique in the consolidated CSS file (they should be by construction, tests are meant to capture bugs that we might miss if we update the consolidation logic in Reffy). Consolidation amends syntaxes of some of the entries. Tests also make sure that syntaxes can be parsed with CSSTree.
1 parent 40da077 commit 3fda9a6

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

test/css/consolidated.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Test the consolidated css.json file in the curated view.
3+
*/
4+
5+
import { describe, it } from 'node:test';
6+
import { strict as assert } from 'node:assert';
7+
import consolidated from '../../curated/css.json' with { type: 'json' };
8+
import { definitionSyntax } from 'css-tree';
9+
10+
// Expected categories in the consolidated file
11+
const categories = {
12+
atrules: { singular: 'at-rule', plural: 'at-rules' },
13+
functions: { singular: 'function', plural: 'functions' },
14+
properties: { singular: 'property', plural: 'properties' },
15+
selectors: { singular: 'selector', plural: 'selectors' },
16+
types: { singular: 'type', plural: 'types' }
17+
};
18+
19+
describe(`The consolidated CSS file`, async () => {
20+
for (const [category, { singular, plural }] of Object.entries(categories)) {
21+
const list = consolidated[category];
22+
23+
it(`contains ${plural}`, () => {
24+
assert(list);
25+
assert(list.length > 0);
26+
});
27+
28+
it(`does not contain duplicated ${plural}`, () => {
29+
const keys = list.map(entry => entry.name +
30+
(entry.for ? ` for ${entry.for}` : ''));
31+
const duplicates = keys.filter((key, idx) =>
32+
keys.findIndex(k => k === key) !== idx);
33+
assert.deepEqual(duplicates, []);
34+
});
35+
36+
it(`contains valid ${singular} syntaxes`, () => {
37+
const invalid = list
38+
.filter(entry => entry.value)
39+
.filter(entry => {
40+
const ast = definitionSyntax.parse(entry.value);
41+
return !ast.type;
42+
});
43+
assert.deepEqual(invalid, []);
44+
});
45+
}
46+
});

0 commit comments

Comments
 (0)