|
| 1 | +import { describe, expect, test } from "vitest" |
| 2 | + |
| 3 | +import { transformTailwindContent } from "../../../src/utils/updaters/update-tailwind-content" |
| 4 | + |
| 5 | +const SHARED_CONFIG = { |
| 6 | + $schema: "https://ui.shadcn.com/schema.json", |
| 7 | + style: "new-york", |
| 8 | + rsc: true, |
| 9 | + tsx: true, |
| 10 | + tailwind: { |
| 11 | + config: "tailwind.config.ts", |
| 12 | + css: "app/globals.css", |
| 13 | + baseColor: "slate", |
| 14 | + cssVariables: true, |
| 15 | + }, |
| 16 | + aliases: { |
| 17 | + components: "@/components", |
| 18 | + utils: "@/lib/utils", |
| 19 | + }, |
| 20 | + resolvedPaths: { |
| 21 | + cwd: ".", |
| 22 | + tailwindConfig: "tailwind.config.ts", |
| 23 | + tailwindCss: "app/globals.css", |
| 24 | + components: "./components", |
| 25 | + utils: "./lib/utils", |
| 26 | + ui: "./components/ui", |
| 27 | + }, |
| 28 | +} |
| 29 | + |
| 30 | +describe("transformTailwindContent -> content property", () => { |
| 31 | + test("should add content property if not in config", async () => { |
| 32 | + expect( |
| 33 | + await transformTailwindContent( |
| 34 | + `import type { Config } from 'tailwindcss' |
| 35 | +
|
| 36 | +const config: Config = { |
| 37 | + content: [ |
| 38 | + "./pages/**/*.{js,ts,jsx,tsx,mdx}", |
| 39 | + "./components/**/*.{js,ts,jsx,tsx,mdx}", |
| 40 | + "./app/**/*.{js,ts,jsx,tsx,mdx}", |
| 41 | + ], |
| 42 | + theme: { |
| 43 | + extend: { |
| 44 | + backgroundImage: { |
| 45 | + "gradient-radial": "radial-gradient(var(--tw-gradient-stops))", |
| 46 | + "gradient-conic": |
| 47 | + "conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))", |
| 48 | + }, |
| 49 | + }, |
| 50 | + }, |
| 51 | + plugins: [], |
| 52 | +} |
| 53 | +export default config |
| 54 | + `, |
| 55 | + ["./foo/**/*.{js,ts,jsx,tsx,mdx}", "./bar/**/*.{js,ts,jsx,tsx,mdx}"], |
| 56 | + { |
| 57 | + config: SHARED_CONFIG, |
| 58 | + } |
| 59 | + ) |
| 60 | + ).toMatchSnapshot() |
| 61 | + }) |
| 62 | + |
| 63 | + test("should NOT add content property if already in config", async () => { |
| 64 | + expect( |
| 65 | + await transformTailwindContent( |
| 66 | + `import type { Config } from 'tailwindcss' |
| 67 | +
|
| 68 | +const config: Config = { |
| 69 | + content: [ |
| 70 | + "./pages/**/*.{js,ts,jsx,tsx,mdx}", |
| 71 | + "./components/**/*.{js,ts,jsx,tsx,mdx}", |
| 72 | + "./app/**/*.{js,ts,jsx,tsx,mdx}", |
| 73 | + ], |
| 74 | + theme: { |
| 75 | + extend: { |
| 76 | + backgroundImage: { |
| 77 | + "gradient-radial": "radial-gradient(var(--tw-gradient-stops))", |
| 78 | + "gradient-conic": |
| 79 | + "conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))", |
| 80 | + }, |
| 81 | + }, |
| 82 | + }, |
| 83 | + plugins: [], |
| 84 | +} |
| 85 | +export default config |
| 86 | + `, |
| 87 | + ["./app/**/*.{js,ts,jsx,tsx,mdx}", "./bar/**/*.{js,ts,jsx,tsx,mdx}"], |
| 88 | + { |
| 89 | + config: SHARED_CONFIG, |
| 90 | + } |
| 91 | + ) |
| 92 | + ).toMatchSnapshot() |
| 93 | + }) |
| 94 | +}) |
0 commit comments