mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2025-12-08 21:36:08 +00:00
Also refactor to only detect `@tailwind` directives once per build to improve performance.
102 lines
2.0 KiB
JavaScript
102 lines
2.0 KiB
JavaScript
import postcss from 'postcss'
|
|
import path from 'path'
|
|
import tailwind from '../../src/jit/index.js'
|
|
|
|
function run(input, config = {}) {
|
|
const { currentTestName } = expect.getState()
|
|
|
|
return postcss(tailwind(config)).process(input, {
|
|
from: `${path.resolve(__filename)}?test=${currentTestName}`,
|
|
})
|
|
}
|
|
|
|
test('using @layer without @tailwind', async () => {
|
|
let config = {
|
|
purge: [path.resolve(__dirname, './layer-without-tailwind.test.html')],
|
|
mode: 'jit',
|
|
theme: {},
|
|
plugins: [],
|
|
}
|
|
|
|
let css = `
|
|
@layer components {
|
|
.foo {
|
|
color: black;
|
|
}
|
|
}
|
|
`
|
|
|
|
await expect(run(css, config)).rejects.toThrowError(
|
|
'`@layer components` is used but no matching `@tailwind components` directive is present.'
|
|
)
|
|
})
|
|
|
|
test('using @responsive without @tailwind', async () => {
|
|
let config = {
|
|
purge: [path.resolve(__dirname, './layer-without-tailwind.test.html')],
|
|
mode: 'jit',
|
|
theme: {},
|
|
plugins: [],
|
|
}
|
|
|
|
let css = `
|
|
@responsive {
|
|
.foo {
|
|
color: black;
|
|
}
|
|
}
|
|
`
|
|
|
|
await expect(run(css, config)).rejects.toThrowError(
|
|
'`@responsive` is used but `@tailwind utilities` is missing.'
|
|
)
|
|
})
|
|
|
|
test('using @variants without @tailwind', async () => {
|
|
let config = {
|
|
purge: [path.resolve(__dirname, './layer-without-tailwind.test.html')],
|
|
mode: 'jit',
|
|
theme: {},
|
|
plugins: [],
|
|
}
|
|
|
|
let css = `
|
|
@variants hover {
|
|
.foo {
|
|
color: black;
|
|
}
|
|
}
|
|
`
|
|
|
|
await expect(run(css, config)).rejects.toThrowError(
|
|
'`@variants` is used but `@tailwind utilities` is missing.'
|
|
)
|
|
})
|
|
|
|
test('non-Tailwind @layer rules are okay', async () => {
|
|
let config = {
|
|
purge: [path.resolve(__dirname, './layer-without-tailwind.test.html')],
|
|
mode: 'jit',
|
|
theme: {},
|
|
plugins: [],
|
|
}
|
|
|
|
let css = `
|
|
@layer custom {
|
|
.foo {
|
|
color: black;
|
|
}
|
|
}
|
|
`
|
|
|
|
return run(css, config).then((result) => {
|
|
expect(result.css).toMatchFormattedCss(`
|
|
@layer custom {
|
|
.foo {
|
|
color: black;
|
|
}
|
|
}
|
|
`)
|
|
})
|
|
})
|