sssg/src/plugins/__tests__/postcss.test.ts
yourfriendoss 91f39a80a7
Some checks failed
/ build (node-16) (push) Failing after 33s
/ build (windows-node-iron) (push) Failing after 2m26s
add all of the testing
2025-10-20 01:23:51 +03:00

50 lines
1.4 KiB
TypeScript

import { expect, test } from "bun:test";
import PostCSS from "../postcss";
// Dummy PostCSS plugin that uppercases all CSS
function uppercasePlugin() {
return {
postcssPlugin: "uppercase",
Once(root: any) {
root.walkDecls((decl: any) => {
decl.value = decl.value.toUpperCase();
decl.prop = decl.prop.toUpperCase();
});
}
};
}
uppercasePlugin.postcss = true;
test("PostCSS applies plugins to CSS", async () => {
const plugin = new PostCSS([uppercasePlugin()]);
const input = "body { color: red; }";
const output = await plugin.rewriteFile(input);
expect(output).toContain("COLOR: RED;");
});
test("PostCSS returns unchanged CSS if no plugins", async () => {
const plugin = new PostCSS([]);
const input = "body { color: blue; }";
const output = await plugin.rewriteFile(input);
expect(output).toBe(input);
});
test("PostCSS handles multiple plugins", async () => {
// Plugin to replace 'red' with 'green'
function replaceRedPlugin() {
return {
postcssPlugin: "replace-red",
Once(root: any) {
root.walkDecls((decl: any) => {
decl.value = decl.value.replace(/red/g, "green");
});
}
};
}
replaceRedPlugin.postcss = true;
const plugin = new PostCSS([replaceRedPlugin(), uppercasePlugin()]);
const input = "body { color: red; }";
const output = await plugin.rewriteFile(input);
expect(output).toContain("COLOR: GREEN;");
});