Skip to content

Commit

Permalink
Add CSS tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosgood committed Jan 8, 2024
1 parent d415849 commit cbee94e
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion tasks/test-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,23 @@ Object.keys(componentsWithJavaScript).forEach((component) => {

console.log("\n");

// TODO: Test CSS for contents
console.log(`Testing compiled CSS files`);
const cssAllPackage = fs
.readFileSync("package/nationalarchives/all.css")
.toString();
const checkForClasses = ["tna-template", "tna-template__body"];
checkForClasses.forEach((cssClass) => {
const escapedClass = cssClass.replace("-", "\\-");
const regExp = cssAllPackage.match(new RegExp(`.${escapedClass}\{`, "g"));
if (regExp) {
pass(
`${cssClass.replace(/`{$/, "")} selector occurs ${regExp.length} time${
regExp.length === 1 ? "" : "s"
} in compiled CSS`,
);
} else {
fail(`${cssClass.replace(/`{$/, "")} selector missing from compiled CSS`);
process.exitCode = 1;
throw new Error("CSS test failed");
}
});

0 comments on commit cbee94e

Please sign in to comment.