Skip to content

Commit

Permalink
rework testing
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremiahSecrist committed Aug 14, 2024
1 parent 85c4c9f commit 28c54cc
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 36 deletions.
68 changes: 32 additions & 36 deletions tests/index.vitest.js
Original file line number Diff line number Diff line change
@@ -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);
1 change: 1 addition & 0 deletions tests/snapshots/color.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
Empty file removed tests/snapshots/section.css
Empty file.
File renamed without changes.

0 comments on commit 28c54cc

Please sign in to comment.