|
| 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