penpot/frontend/packages/ui/tests/copy-css-plugin.test.ts
Andrey Antukh eddb824ca7 🐛 Resolve UI CSS copy paths during bundle builds
Resolve the UI CSS source and destination from the package directory so
Vite works when launched outside that directory. Add a regression test and
quiet the bundle's rsync output.

AI-assisted-by: gpt-6-luna
2026-11-18 15:56:07 +01:00

50 lines
1.2 KiB
TypeScript

import {
mkdtempSync,
mkdirSync,
readFileSync,
rmSync,
writeFileSync,
} from "node:fs";
import os from "node:os";
import path from "node:path";
import { afterEach, expect, it } from "vitest";
import { copyCssPlugin } from "../vite.config.mts";
const temporaryDirectories: string[] = [];
afterEach(() => {
for (const directory of temporaryDirectories.splice(0)) {
rmSync(directory, { recursive: true, force: true });
}
});
it("copies the generated CSS using paths based on the package directory", () => {
const temporaryDirectory = mkdtempSync(
path.join(os.tmpdir(), "penpot-ui-css-copy-"),
);
temporaryDirectories.push(temporaryDirectory);
const packageDirectory = path.join(
temporaryDirectory,
"frontend",
"packages",
"ui",
);
const cssPath = path.join(packageDirectory, "dist", "ui.css");
const destinationPath = path.join(
temporaryDirectory,
"frontend",
"resources",
"public",
"css",
"ui.css",
);
mkdirSync(path.dirname(cssPath), { recursive: true });
writeFileSync(cssPath, ".ui { color: red; }");
copyCssPlugin(packageDirectory).closeBundle();
expect(readFileSync(destinationPath, "utf8")).toBe(".ui { color: red; }");
});