Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add failing test
  • Loading branch information
RobinMalfait committed Nov 28, 2024
commit b8e62ef7ddd5401ef89c708854708e828d3392f0
1 change: 1 addition & 0 deletions packages/@tailwindcss-postcss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"devDependencies": {
"@types/node": "catalog:",
"@types/postcss-import": "14.0.3",
"dedent": "1.5.3",
"internal-example-plugin": "workspace:*",
"postcss-import": "^16.1.0"
}
Expand Down
32 changes: 27 additions & 5 deletions packages/@tailwindcss-postcss/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import dedent from 'dedent'
import { unlink, writeFile } from 'node:fs/promises'
import postcss from 'postcss'
import { afterEach, beforeEach, describe, expect, test } from 'vitest'
Expand All @@ -11,7 +12,7 @@ import tailwindcss from './index'
// @import 'tailwindcss' to work.
const INPUT_CSS_PATH = `${__dirname}/fixtures/example-project/input.css`

const css = String.raw
const css = dedent

test("`@import 'tailwindcss'` is replaced with the generated CSS", async () => {
let processor = postcss([
Expand Down Expand Up @@ -49,8 +50,6 @@ test('output is optimized by Lightning CSS', async () => {
tailwindcss({ base: `${__dirname}/fixtures/example-project`, optimize: { minify: false } }),
])

// `@apply` is used because Lightning is skipped if neither `@tailwind` nor
// `@apply` is used.
let result = await processor.process(
css`
@layer utilities {
Expand Down Expand Up @@ -86,8 +85,6 @@ test('@apply can be used without emitting the theme in the CSS file', async () =
tailwindcss({ base: `${__dirname}/fixtures/example-project`, optimize: { minify: false } }),
])

// `@apply` is used because Lightning is skipped if neither `@tailwind` nor
// `@apply` is used.
let result = await processor.process(
css`
@import 'tailwindcss/theme.css' theme(reference);
Expand Down Expand Up @@ -222,3 +219,28 @@ describe('plugins', () => {
`)
})
})

test('bail early when Tailwind is not used', async () => {
let processor = postcss([
tailwindcss({ base: `${__dirname}/fixtures/example-project`, optimize: { minify: false } }),
])

let result = await processor.process(
css`
.custom-css {
color: red;
}
`,
{ from: INPUT_CSS_PATH },
)

// `fixtures/example-project` includes an `underline` candidate. But since we
// didn't use `@tailwind utilities` we didn't scan for utilities.
expect(result.css).not.toContain('.underline {')

expect(result.css.trim()).toMatchInlineSnapshot(`
".custom-css {
color: red;
}"
`)
})
42 changes: 30 additions & 12 deletions pnpm-lock.yaml

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