Skip to content
Merged
Changes from 1 commit
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
46 changes: 46 additions & 0 deletions test/css/consolidated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* 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: { singular: 'at-rule', plural: 'at-rules' },
functions: { singular: 'function', plural: 'functions' },
properties: { singular: 'property', plural: 'properties' },
selectors: { singular: 'selector', plural: 'selectors' },
types: { singular: 'type', plural: 'types' }
};

describe(`The consolidated CSS file`, async () => {
for (const [category, { singular, plural }] of Object.entries(categories)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
atrules: { singular: 'at-rule', plural: 'at-rules' },
functions: { singular: 'function', plural: 'functions' },
properties: { singular: 'property', plural: 'properties' },
selectors: { singular: 'selector', plural: 'selectors' },
types: { singular: 'type', plural: 'types' }
};
describe(`The consolidated CSS file`, async () => {
for (const [category, { singular, plural }] of Object.entries(categories)) {
```suggestion
atrules: { singular: 'at-rule' },
functions: { singular: 'function' },
properties: { singular: 'property', plural: 'properties' },
selectors: { singular: 'selector' },
types: { singular: 'type' }
};
describe(`The consolidated CSS file`, async () => {
for (const [category, { singular, plural = singular + 's' }] of Object.entries(categories)) {

if we're being pedantic, let's at least be lazy about it :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a lazier version that avoids the destructuring syntax with a default value, which always makes me pose. Coz' DRY is fine but KISS too!

const list = consolidated[category];

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

it(`does not contain duplicated ${plural}`, () => {
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 ${singular} syntaxes`, () => {
const invalid = list
.filter(entry => entry.value)
.filter(entry => {
const ast = definitionSyntax.parse(entry.value);
return !ast.type;
});
assert.deepEqual(invalid, []);
});
}
});