Skip to content

Commit

Permalink
setup tests for @content support
Browse files Browse the repository at this point in the history
We also setup a sibling fixture project so that we can use `@content` to
include files that are not detected by the auto content detection.
  • Loading branch information
RobinMalfait committed Aug 2, 2024
1 parent 06f4d62 commit 9ba4a7d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const className = "content-['other-project']"
58 changes: 57 additions & 1 deletion packages/@tailwindcss-postcss/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const INPUT_CSS_PATH = `${__dirname}/fixtures/example-project/input.css`
const css = String.raw

beforeEach(async () => {
const { clearCache } = await import('@tailwindcss/oxide')
let { clearCache } = await import('@tailwindcss/oxide')
clearCache()
})

Expand Down Expand Up @@ -226,3 +226,59 @@ describe('plugins', () => {
`)
})
})

describe('@content', () => {
test('scans custom @content files', async () => {
let processor = postcss([
tailwindcss({ base: `${__dirname}/fixtures/example-project`, optimize: { minify: false } }),
])

let result = await processor.process(
css`
@import 'tailwindcss/utilities';
@content '../other-project/src/**/*.js';
`,
{ from: INPUT_CSS_PATH },
)

expect(result.css.trim()).toMatchInlineSnapshot(`
".underline {
text-decoration-line: underline;
}
.content-\\[\\'other-project\\'\\] {
--tw-content: "other-project";
content: var(--tw-content);
}
@supports (-moz-orient: inline) {
@layer base {
*, :before, :after, ::backdrop {
--tw-content: "";
}
}
}
@property --tw-content {
syntax: "*";
inherits: false;
initial-value: "";
}"
`)

expect(result.messages).toContainEqual({
type: 'dependency',
file: expect.stringMatching(/other-project\/src\/index.js$/g),
parent: expect.any(String),
plugin: '@tailwindcss/postcss',
})

expect(result.messages).toContainEqual({
type: 'dir-dependency',
dir: expect.stringMatching(/other-project\/src/),
glob: '**/*.js',
parent: expect.any(String),
plugin: '@tailwindcss/postcss',
})
})
})

0 comments on commit 9ba4a7d

Please sign in to comment.