Skip to content

Commit

Permalink
split build and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
romainmenke committed Nov 1, 2024
1 parent 4b2fa2d commit f65c00c
Show file tree
Hide file tree
Showing 25 changed files with 219 additions and 132 deletions.
12 changes: 11 additions & 1 deletion packages/css-syntax-patches-for-csstree/dist/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,21 @@
"font-display": "auto | block | swap | fallback | optional"
}
},
"font-palette-values": {
"descriptors": {
"override-colors": "[ <integer [0,∞]> <color> ]#"
}
},
"function": {
"descriptors": {
"result": "<declaration-value>?"
}
},
"page": {
"descriptors": {
"size": "<length [0,∞]>{1,2} | auto | [ <page-size> || [ portrait | landscape ] ]"
}
},
"view-transition": {
"descriptors": {
"navigation": "auto | none",
Expand Down Expand Up @@ -666,4 +676,4 @@
"xyz-params": "<xyz> [ <number> | <percentage> | none ]{3}"
}
}
}
}
4 changes: 2 additions & 2 deletions packages/css-syntax-patches-for-csstree/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@
"prepublishOnly": "npm run build && npm run test",
"test": "node --test"
},
"homepage": "https://github.com/csstools/postcss-plugins/tree/main/packages/utilities#readme",
"homepage": "https://github.com/csstools/postcss-plugins/tree/main/packages/css-syntax-patches-for-csstree#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/csstools/postcss-plugins.git",
"directory": "packages/utilities"
"directory": "packages/css-syntax-patches-for-csstree"
},
"bugs": "https://github.com/csstools/postcss-plugins/issues",
"keywords": [
Expand Down
131 changes: 3 additions & 128 deletions packages/css-syntax-patches-for-csstree/scripts/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// - backwards compat
// given that syntaxes are extensive users might depend on a specific type. No types can be removed or altered in a breaking way in semver patches or minors

import { fork } from 'css-tree-3.0.0';

import { generate_csstree_sets } from './generate-csstree-sets.mjs';
import { generate_webref_sets } from './generate-webref-sets.mjs';
import { write_set_files } from './write-set-files.mjs';
Expand All @@ -27,15 +25,7 @@ const webref_over_csstree_sets = {
types: diff_sets(csstree_sets.types, webref_sets.types),
};

const SINGULAR = {
'atrules': 'atrule',
'properties': 'property',
'types': 'type',
};

let has_missing_patch_tests = false;
let has_invalid_items = false;
let has_failing_tests = false;
let flaws = 0;

const {
Expand All @@ -50,24 +40,6 @@ const {

flaws += patch_flaws;

const forkedLexer = fork({
atrules: atrule_patches,
properties: property_patches,
types: type_patches,
}).lexer;

const invalid = forkedLexer.validate();
if (invalid) {
for (const [kind, items] of Object.entries(invalid)) {
items.forEach((item) => {
// eslint-disable-next-line no-console
console.log(`Unexpected invalid ${SINGULAR[kind]} '${item}'`);
has_invalid_items = true;
flaws++;
});
}
}

// Atrules
for (const [name, atrule] of Object.entries(webref_over_csstree_sets.atrules)) {
for (const [descriptor_name] of Object.entries(atrule.descriptors)) {
Expand All @@ -84,35 +56,6 @@ for (const [name, atrule] of Object.entries(webref_over_csstree_sets.atrules)) {
has_missing_patch_tests = true;
continue;
}

for (const test of (patch.tests.passing ?? [])) {
try {
const result = forkedLexer.matchAtruleDescriptor(name, descriptor_name, test.value);
if (!result.error) {
continue;
}

} catch { }

// eslint-disable-next-line no-console
console.log(`Expected no error for '@${name}' and '${descriptor_name}: ${test.value}'`);
flaws++;
}

for (const test of (patch.tests.failing ?? [])) {
try {
const result = forkedLexer.matchAtruleDescriptor(name, descriptor_name, test.value);
if (result.error) {
continue;
}
} catch {
continue;
}

// eslint-disable-next-line no-console
console.log(`Expected an error for '@${name}' and '${descriptor_name}: ${test.value}'`);
flaws++;
}
}
}

Expand All @@ -131,35 +74,6 @@ for (const [name] of Object.entries(webref_over_csstree_sets.properties)) {
has_missing_patch_tests = true;
continue;
}

for (const test of (patch.tests.passing ?? [])) {
try {
const result = forkedLexer.matchProperty(name, test.value);
if (!result.error) {
continue;
}

} catch { }

// eslint-disable-next-line no-console
console.log(`Expected no error for '${name}: ${test.value}'`);
flaws++;
}

for (const test of (patch.tests.failing ?? [])) {
try {
const result = forkedLexer.matchProperty(name, test.value);
if (result.error) {
continue;
}
} catch {
continue;
}

// eslint-disable-next-line no-console
console.log(`Expected an error for '${name}: ${test.value}'`);
flaws++;
}
}

// Types
Expand All @@ -177,35 +91,6 @@ for (const [name] of Object.entries(webref_over_csstree_sets.types)) {
has_missing_patch_tests = true;
continue;
}

for (const test of (patch.tests.passing ?? [])) {
try {
const result = forkedLexer.matchProperty(test.property, test.value);
if (!result.error) {
continue;
}

} catch {}

// eslint-disable-next-line no-console
console.log(`Expected no error for '${test.property}: ${test.value}'`);
flaws++;
}

for (const test of (patch.tests.failing ?? [])) {
try {
const result = forkedLexer.matchProperty(test.property, test.value);
if (result.error) {
continue;
}
} catch {
continue;
}

// eslint-disable-next-line no-console
console.log(`Expected an error for '${test.property}: ${test.value}'`);
flaws++;
}
}

await write_set_files({
Expand All @@ -230,7 +115,7 @@ await write_final_file({
});

{
if (has_missing_patches || has_outdated_patches || has_unmerged_patches || has_missing_patch_tests || has_invalid_items || has_failing_tests) {
if (has_missing_patches || has_outdated_patches || has_unmerged_patches || has_missing_patch_tests) {
// eslint-disable-next-line no-console
console.log('-------------------');
}
Expand All @@ -255,20 +140,10 @@ await write_final_file({
console.warn('Not all patches have test coverage');
}

if (has_invalid_items) {
if (has_missing_patches || has_outdated_patches || has_unmerged_patches || has_missing_patch_tests) {
// eslint-disable-next-line no-console
console.warn('Not all types or properties are valid');
}

if (has_failing_tests) {
// eslint-disable-next-line no-console
console.warn('Not all tests passed');
}

// eslint-disable-next-line no-console
console.log(`${flaws} flaws to resolve`);
console.log(`${flaws} flaws to resolve`);

if (has_missing_patches || has_outdated_patches || has_unmerged_patches || has_missing_patch_tests || has_invalid_items || has_failing_tests) {
process.exit(1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ function contains_unsupported_function(cssTreeNode) {
);
}

const css_files = await get_files('tests');
const css_files = [
...await get_files(path.join('tests', 'community')),
...await get_files(path.join('tests', 'samples')),
];

const patches = JSON.parse(await fs.readFile(path.join('dist', 'index.json'), 'utf-8')).next;

Expand Down
Loading

0 comments on commit f65c00c

Please sign in to comment.