sssg/src/plugins/__tests__/postcss.test.ts
yourfriendoss e183025a16
All checks were successful
/ build (node-16) (push) Successful in 19s
/ build (windows-node-iron) (push) Successful in 1m14s
buncha stuff
2025-12-12 18:36:31 +02:00

48 lines
1.4 KiB
TypeScript

import { expect, test } from "bun:test";
import PostCSS from "../postcss";
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, "test");
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, "test");
expect(output).toBe(input);
});
test("PostCSS handles multiple plugins", async () => {
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, "test");
expect(output).toContain("COLOR: GREEN;");
});