add all of the testing
This commit is contained in:
parent
d5b4341487
commit
91f39a80a7
12 changed files with 485 additions and 69 deletions
50
src/plugins/__tests__/postcss.test.ts
Normal file
50
src/plugins/__tests__/postcss.test.ts
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
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;");
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue