Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions test/css/consolidated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Test the consolidated css.json file in the curated view.
*/

import { describe, it } from 'node:test';
import { strict as assert } from 'node:assert';
import consolidated from '../../curated/css.json' with { type: 'json' };
import { definitionSyntax } from 'css-tree';

// Expected categories in the consolidated file
const categories = {
atrules: 'at-rule',
functions: 'function',
properties: 'property',
selectors: 'selector',
types: 'type'
};

// Quick and dirty function to pluralize category labels
function pluralize(word) {
if (word === 'property') {
return 'properties';
}
else {
return word + 's';
}
}

describe(`The consolidated CSS file`, async () => {
for (const [category, label] of Object.entries(categories)) {
const list = consolidated[category];

it(`contains ${pluralize(label)}`, () => {
assert(list);
assert(list.length > 0);
});

it(`does not contain duplicated ${pluralize(label)}`, () => {
const keys = list.map(entry => entry.name +
(entry.for ? ` for ${entry.for}` : ''));
const duplicates = keys.filter((key, idx) =>
keys.findIndex(k => k === key) !== idx);
assert.deepEqual(duplicates, []);
});

it(`contains valid ${label} syntaxes`, () => {
const invalid = list
.filter(entry => entry.value)
.filter(entry => {
const ast = definitionSyntax.parse(entry.value);
return !ast.type;
});
assert.deepEqual(invalid, []);
});
}
});