From 28c54cc3b3ffef49f59d977748db198ea982ff1b Mon Sep 17 00:00:00 2001 From: Jermeiah S Date: Wed, 14 Aug 2024 17:36:27 -0400 Subject: [PATCH] rework testing --- tests/index.vitest.js | 68 +++++++++---------- tests/snapshots/color.css | 1 + tests/snapshots/{spacing.css => padding.css} | 0 tests/snapshots/section.css | 0 .../{colors.css => sectionPadding.css} | 0 5 files changed, 33 insertions(+), 36 deletions(-) create mode 100644 tests/snapshots/color.css rename tests/snapshots/{spacing.css => padding.css} (100%) delete mode 100644 tests/snapshots/section.css rename tests/snapshots/{colors.css => sectionPadding.css} (100%) diff --git a/tests/index.vitest.js b/tests/index.vitest.js index 087dbdf..0effb8f 100644 --- a/tests/index.vitest.js +++ b/tests/index.vitest.js @@ -1,55 +1,51 @@ const postcss = require("postcss"); -import { test, expect } from "vitest"; +import { test, expect, describe, it } from "vitest"; import tailwindcss from "tailwindcss"; import cssnanoPlugin from "cssnano"; import liftkittailwindcss from "../src"; -const generatePluginCSS = async (options = {}) => { - const { content = "" } = options; - +function generatePluginCSS({ content }) { return postcss([ cssnanoPlugin(), tailwindcss({ plugins: [liftkittailwindcss], content: [{ raw: content }] }), ]) .process("@tailwind utilities; @tailwind components;", { from: undefined }) .then((result) => result.css); -}; +} -test("fontsize", async () => { - const css = await generatePluginCSS({ +// Object of objects containing test cases +const testCases = { + fontsize: { content: "text-display-1 text-display-2 text-title-3 text-heading text-heading-sub text-body text-callout text-label text-caption text-overline", - }); - expect(css).toMatchFileSnapshot("./snapshots/fontsize.css"); -}); -test("shadows", async () => { - const css = await generatePluginCSS({ + }, + shadows: { + content: "shadow-sm shadow-md shadow-lg shadow-xl shadow-2xl", + }, + sectionPadding: { + content: "section-least", + }, + padding: { content: - "shadow-sm shadow-md shadow-lg shadow-xl shadow-2xl" - }); - expect(css).toMatchFileSnapshot("./snapshots/shadows.css"); -}); - -test("section padding", async () => { - const css = await generatePluginCSS({ + "p-lk-2xs p-sm p-lk-xs p-lk-sm p-lk-md p-lk-lg p-lk-xl p-lk-2xl p-mid", + }, + color: { content: - "section-least" - }); - expect(css).toMatchFileSnapshot("./snapshots/section.css"); -}); + "bg-lk-primary-light bg-lk-secondary-light bg-lk-secondary-dark", + }, +}; -test("padding", async () => { - const css = await generatePluginCSS({ - content: - "p-lk-2xs p-sm p-lk-xs p-lk-sm p-lk-md p-lk-lg p-lk-xl p-lk-2xl p-mid" +// Function to run tests for each attribute in the object of objects +function mapAndTest(attrSet) { + Object.entries(attrSet).forEach(([name, { content }]) => { + describe(`Tailwind CSS Plugin Test: ${name}`, () => { + it(`should generate the correct CSS for ${name}`, async () => { + const css = await generatePluginCSS({ content }); + expect(css).toMatchFileSnapshot(`./snapshots/${name}.css`); + }); + }); }); - expect(css).toMatchFileSnapshot("./snapshots/spacing.css"); -}); +} -test("color", async () => { - const css = await generatePluginCSS({ - content: - "bg-lk-on-primary-light bg-lk-on-secondary-dark" - }); - expect(css).toMatchFileSnapshot("./snapshots/colors.css"); -}); +// Run the tests +mapAndTest(testCases); diff --git a/tests/snapshots/color.css b/tests/snapshots/color.css new file mode 100644 index 0000000..eade2f2 --- /dev/null +++ b/tests/snapshots/color.css @@ -0,0 +1 @@ +.bg-lk-primary-light{--tw-bg-opacity:1;background-color:rgb(188 1 0/var(--tw-bg-opacity))}.bg-lk-secondary-dark{--tw-bg-opacity:1;background-color:rgb(255 180 168/var(--tw-bg-opacity))}.bg-lk-secondary-light{--tw-bg-opacity:1;background-color:rgb(183 33 20/var(--tw-bg-opacity))} \ No newline at end of file diff --git a/tests/snapshots/spacing.css b/tests/snapshots/padding.css similarity index 100% rename from tests/snapshots/spacing.css rename to tests/snapshots/padding.css diff --git a/tests/snapshots/section.css b/tests/snapshots/section.css deleted file mode 100644 index e69de29..0000000 diff --git a/tests/snapshots/colors.css b/tests/snapshots/sectionPadding.css similarity index 100% rename from tests/snapshots/colors.css rename to tests/snapshots/sectionPadding.css