This commit is contained in:
Alex
2024-04-06 15:28:43 -04:00
parent dbfdf67983
commit 1109ff0dea
7 changed files with 256 additions and 146 deletions

View File

@ -1,15 +1,14 @@
import { promises as fs } from "node:fs";
import { resolve } from "node:path";
import { build } from "esbuild";
import { build, transformSync } from "esbuild";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { OutputChunk, rollup } from "rollup";
import rollupBabel from "@rollup/plugin-babel";
import rollupCSS from "rollup-plugin-css-only";
import { name } from "../package.json" with { type: "json" };
import {
type TailwindPluginOptions,
babelPlugin,
getClassName,
getTailwindPlugins,
createPostCSS,
} from "./index";
const folder = resolve(import.meta.dirname, "temp");
@ -73,4 +72,30 @@ describe("babel-tailwind", () => {
expect(js.text).toContain(`className: "${clsName}"`);
expect(css.text).toMatch(`.${clsName} {\n text-align: center;\n}`);
});
const minCSS = (text: string) =>
transformSync(text, { minify: true, loader: "css" })!.code;
it("supports importing tailwind/base", async () => {
const postcss = createPostCSS({ tailwindConfig: {} });
const base = (await postcss("@tailwind base;")).css;
const outputFiles = await compileESBuild(
{
tailwindConfig: {},
clsx: "emotion",
},
/* tsx */ `
import "${name}/base";
`
);
expect(outputFiles).toHaveLength(2);
const js = outputFiles.find(file => file.path.endsWith(".js"))!;
const css = outputFiles.find(file => file.path.endsWith(".css"))!;
// expect(js.text).toContain(`import "./base.css";`);
expect(js.text).toBe("");
expect(minCSS(css.text)).toContain(minCSS(base));
});
});