forked from chainlift/liftkit-css
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
85c4c9f
commit 28c54cc
Showing
5 changed files
with
33 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
Empty file.
File renamed without changes.