48 lines
1.4 KiB
TypeScript
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;");
|
|
});
|