From 6cd73524fb175e8a39b5de890a8764a5fd027cb9 Mon Sep 17 00:00:00 2001 From: Kyle June Date: Fri, 2 Oct 2026 00:44:35 -0400 Subject: [PATCH] test: scope tailwind class scanning --- __snapshots__/postcss.test.ts.snap | 252 +++++++++++++++++++++++++++++ postcss.test.ts | 9 +- 2 files changed, 255 insertions(+), 6 deletions(-) diff --git a/__snapshots__/postcss.test.ts.snap b/__snapshots__/postcss.test.ts.snap index b61c977..1aa5fbe 100644 --- a/__snapshots__/postcss.test.ts.snap +++ b/__snapshots__/postcss.test.ts.snap @@ -9,3 +9,255 @@ snapshot[`modules > isModule returning true 1`] = `'{"title":"_title_wsfbq_5 _ti snapshot[`modules > modules set to custom postcss-modules plugin configuration options 1`] = `'{"title":"custom-module__title___ticPp mixins__title___ymOTP","article":"custom-module__article___Z26ow"}'`; snapshot[`modules > ts entrypoint should output the module map and css to js 1`] = `'{"title":"_title_wsfbq_5 _title_3695r_1","article":"_article_wsfbq_10"}'`; + +snapshot[`plugins > tailwindcss 4 > should add tailwindcss to the css 1`] = ` +'/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */ +@layer properties; +@layer theme, base, components, utilities; +@layer theme { + :root, + :host { + --font-sans: + -apple-system, + BlinkMacSystemFont, + "Segoe UI", + Roboto, + "Helvetica Neue", + "Noto Sans", + Arial, + sans-serif, + "Apple Color Emoji", + "Segoe UI Emoji", + "Segoe UI Symbol", + "Noto Color Emoji"; + --font-mono: + ui-monospace, + SFMono-Regular, + Menlo, + Monaco, + Consolas, + "Liberation Mono", + "Courier New", + monospace; + --text-3xl: 1.875rem; + --text-3xl--line-height: calc(2.25 / 1.875); + --font-weight-bold: 700; + --default-font-family: var(--font-sans); + --default-mono-font-family: var(--font-mono); + } +} +@layer base { + *, + ::after, + ::before, + ::backdrop, + ::file-selector-button { + box-sizing: border-box; + margin: 0; + padding: 0; + border: 0 solid; + } + html, + :host { + line-height: 1.5; + -webkit-text-size-adjust: 100%; + tab-size: 4; + font-family: var(--default-font-family, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"); + font-feature-settings: var(--default-font-feature-settings, normal); + font-variation-settings: var(--default-font-variation-settings, normal); + -webkit-tap-highlight-color: transparent; + } + hr { + height: 0; + color: inherit; + border-top-width: 1px; + } + abbr:where([title]) { + -webkit-text-decoration: underline dotted; + text-decoration: underline dotted; + } + h1, + h2, + h3, + h4, + h5, + h6 { + font-size: inherit; + font-weight: inherit; + } + a { + color: inherit; + -webkit-text-decoration: inherit; + text-decoration: inherit; + } + b, + strong { + font-weight: bolder; + } + code, + kbd, + samp, + pre { + font-family: var(--default-mono-font-family, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace); + font-feature-settings: var(--default-mono-font-feature-settings, normal); + font-variation-settings: var(--default-mono-font-variation-settings, normal); + font-size: 1em; + } + small { + font-size: 80%; + } + sub, + sup { + font-size: 75%; + line-height: 0; + position: relative; + vertical-align: baseline; + } + sub { + bottom: -0.25em; + } + sup { + top: -0.5em; + } + table { + text-indent: 0; + border-color: inherit; + border-collapse: collapse; + } + :-moz-focusring:where(:not(iframe)) { + outline: auto; + } + progress { + vertical-align: baseline; + } + summary { + display: list-item; + } + ol, + ul, + menu { + list-style: none; + } + img, + svg, + video, + canvas, + audio, + iframe, + embed, + object { + display: block; + vertical-align: middle; + } + img, + video { + max-width: 100%; + height: auto; + } + button, + input, + select, + optgroup, + textarea, + ::file-selector-button { + font: inherit; + font-feature-settings: inherit; + font-variation-settings: inherit; + letter-spacing: inherit; + color: inherit; + border-radius: 0; + background-color: transparent; + opacity: 1; + } + :where(select:is([multiple], [size])) optgroup { + font-weight: bolder; + } + :where(select:is([multiple], [size])) optgroup option { + padding-inline-start: 20px; + } + ::file-selector-button { + margin-inline-end: 4px; + } + ::placeholder { + opacity: 1; + } + @supports (not (-webkit-appearance: -apple-pay-button)) or (contain-intrinsic-size: 1px) { + ::placeholder { + color: currentcolor; + @supports (color: color-mix(in lab, red, red)) { + color: color-mix(in oklab, currentcolor 50%, transparent); + } + } + } + textarea { + resize: vertical; + } + ::-webkit-search-decoration { + -webkit-appearance: none; + } + ::-webkit-date-and-time-value { + min-height: 1lh; + text-align: inherit; + } + ::-webkit-datetime-edit { + display: inline-flex; + } + ::-webkit-datetime-edit-fields-wrapper { + padding: 0; + } + ::-webkit-datetime-edit, + ::-webkit-datetime-edit-year-field, + ::-webkit-datetime-edit-month-field, + ::-webkit-datetime-edit-day-field, + ::-webkit-datetime-edit-hour-field, + ::-webkit-datetime-edit-minute-field, + ::-webkit-datetime-edit-second-field, + ::-webkit-datetime-edit-millisecond-field, + ::-webkit-datetime-edit-meridiem-field { + padding-block: 0; + } + ::-webkit-calendar-picker-indicator { + line-height: 1; + } + :-moz-ui-invalid { + box-shadow: none; + } + button, + input:where([type=button], [type=reset], [type=submit]), + ::file-selector-button { + appearance: button; + } + ::-webkit-inner-spin-button, + ::-webkit-outer-spin-button { + height: auto; + } + [hidden]:where(:not([hidden=until-found])) { + display: none !important; + } +} +@layer utilities { + .text-3xl { + font-size: var(--text-3xl); + line-height: var(--tw-leading, var(--text-3xl--line-height)); + } + .font-bold { + --tw-font-weight: var(--font-weight-bold); + font-weight: var(--font-weight-bold); + } + .underline { + text-decoration-line: underline; + } +} +@property --tw-font-weight { syntax: "*"; inherits: false; } +@layer properties { + @supports ((-webkit-hyphens: none) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color:rgb(from red r g b)))) { + *, + ::before, + ::after, + ::backdrop { + --tw-font-weight: initial; + } + } +} +' +`; diff --git a/postcss.test.ts b/postcss.test.ts index 59b1401..4c857d5 100644 --- a/postcss.test.ts +++ b/postcss.test.ts @@ -319,12 +319,12 @@ describe("plugins", () => { const rootDir = path.resolve("./examples/tailwindcss4"); const configPath = path.resolve(Deno.cwd(), "deno.json"); - it("should add tailwindcss to the css", async () => { + it("should add tailwindcss to the css", async (t) => { const result = await build("tailwindcss4", ["./main.css"], { plugins: [ postCSSPlugin({ plugins: [ - tailwindcss(), + tailwindcss({ base: rootDir }), ], }), denoPlugin({ configPath }), @@ -340,10 +340,7 @@ describe("plugins", () => { result.outputFiles[0].path, outFilePath, ); - assertEquals( - result.outputFiles[0].text, - await Deno.readTextFile(outFilePath), - ); + await assertSnapshot(t, result.outputFiles[0].text); assertEquals(result.outputFiles.length, 1); }); });