mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2025-12-08 21:36:08 +00:00
* change specific selector to universal selector This is the commit that we could "undo" in the future if we need it again. * simplify `relative-purge-paths` test This test doesn't require the "reset" selector (whether it is super specific or universal) Simplified it so that it tests the relative purge config and nothing else. * added css tagged template literal helpers This allows prettier to format the string as CSS. This improves formatting and will improve future diffs. * drop tailwind headers in the sanity tests Every time we bump the Tailwind version, the sanity tests fail, because the current version is encoded in the fixture files. This will ensure that all of the contents is still checked and the header is skipped. The header will be tested against a regex to ensure that it is still there. This should be a small but nice QoL improvement, so that we don't have to think about updating those tests whenever we fix bugs or land new features.
155 lines
4.6 KiB
JavaScript
155 lines
4.6 KiB
JavaScript
import fs from 'fs'
|
|
import path from 'path'
|
|
import postcss from 'postcss'
|
|
import tailwind from '../src/index'
|
|
import config from '../stubs/defaultConfig.stub.js'
|
|
|
|
function dropTailwindHeader(css) {
|
|
let [header, ...lines] = css.split('\n')
|
|
|
|
expect(
|
|
/\/*! tailwindcss v\d*\.\d*\.\d* \| MIT License \| https:\/\/tailwindcss.com \*\//g.test(header)
|
|
).toBe(true)
|
|
|
|
return lines.join('\n')
|
|
}
|
|
|
|
it('generates the right CSS using the default settings', () => {
|
|
const inputPath = path.resolve(`${__dirname}/fixtures/tailwind-input.css`)
|
|
const input = fs.readFileSync(inputPath, 'utf8')
|
|
|
|
return postcss([tailwind()])
|
|
.process(input, { from: inputPath })
|
|
.then((result) => {
|
|
const expected = fs.readFileSync(
|
|
path.resolve(`${__dirname}/fixtures/tailwind-output.css`),
|
|
'utf8'
|
|
)
|
|
|
|
expect(dropTailwindHeader(result.css)).toBe(dropTailwindHeader(expected))
|
|
})
|
|
})
|
|
|
|
it('generates the right CSS when "important" is enabled', () => {
|
|
const inputPath = path.resolve(`${__dirname}/fixtures/tailwind-input.css`)
|
|
const input = fs.readFileSync(inputPath, 'utf8')
|
|
|
|
return postcss([tailwind({ ...config, important: true })])
|
|
.process(input, { from: inputPath })
|
|
.then((result) => {
|
|
const expected = fs.readFileSync(
|
|
path.resolve(`${__dirname}/fixtures/tailwind-output-important.css`),
|
|
'utf8'
|
|
)
|
|
|
|
expect(dropTailwindHeader(result.css)).toBe(dropTailwindHeader(expected))
|
|
})
|
|
})
|
|
|
|
it('generates the right CSS when using @import instead of @tailwind', () => {
|
|
const inputPath = path.resolve(`${__dirname}/fixtures/tailwind-input-import.css`)
|
|
const input = fs.readFileSync(inputPath, 'utf8')
|
|
|
|
return postcss([tailwind()])
|
|
.process(input, { from: inputPath })
|
|
.then((result) => {
|
|
const expected = fs.readFileSync(
|
|
path.resolve(`${__dirname}/fixtures/tailwind-output.css`),
|
|
'utf8'
|
|
)
|
|
|
|
expect(dropTailwindHeader(result.css)).toBe(dropTailwindHeader(expected))
|
|
})
|
|
})
|
|
|
|
it('generates the right CSS when enabling flagged features', () => {
|
|
const inputPath = path.resolve(`${__dirname}/fixtures/tailwind-input.css`)
|
|
const input = fs.readFileSync(inputPath, 'utf8')
|
|
|
|
return postcss([
|
|
tailwind({
|
|
future: 'all',
|
|
experimental: 'all',
|
|
}),
|
|
])
|
|
.process(input, { from: inputPath })
|
|
.then((result) => {
|
|
const expected = fs.readFileSync(
|
|
path.resolve(`${__dirname}/fixtures/tailwind-output-flagged.css`),
|
|
'utf8'
|
|
)
|
|
|
|
expect(dropTailwindHeader(result.css)).toBe(dropTailwindHeader(expected))
|
|
})
|
|
})
|
|
|
|
// TODO: Move to per plugin unit tests for this sort of thing
|
|
it('generates the right CSS when color opacity plugins are disabled', () => {
|
|
const inputPath = path.resolve(`${__dirname}/fixtures/tailwind-input.css`)
|
|
const input = fs.readFileSync(inputPath, 'utf8')
|
|
|
|
return postcss([
|
|
tailwind({
|
|
...config,
|
|
corePlugins: {
|
|
textOpacity: false,
|
|
backgroundOpacity: false,
|
|
borderOpacity: false,
|
|
placeholderOpacity: false,
|
|
divideOpacity: false,
|
|
},
|
|
}),
|
|
])
|
|
.process(input, { from: inputPath })
|
|
.then((result) => {
|
|
const expected = fs.readFileSync(
|
|
path.resolve(`${__dirname}/fixtures/tailwind-output-no-color-opacity.css`),
|
|
'utf8'
|
|
)
|
|
|
|
expect(dropTailwindHeader(result.css)).toBe(dropTailwindHeader(expected))
|
|
})
|
|
})
|
|
|
|
it('does not add any CSS if no Tailwind features are used', () => {
|
|
return postcss([tailwind()])
|
|
.process('.foo { color: blue; }', { from: undefined })
|
|
.then((result) => {
|
|
expect(result.css).toMatchCss('.foo { color: blue; }')
|
|
})
|
|
})
|
|
|
|
it('generates the right CSS with implicit screen utilities', () => {
|
|
const inputPath = path.resolve(
|
|
`${__dirname}/fixtures/tailwind-input-with-explicit-screen-utilities.css`
|
|
)
|
|
const input = fs.readFileSync(inputPath, 'utf8')
|
|
|
|
return postcss([tailwind()])
|
|
.process(input, { from: inputPath })
|
|
.then((result) => {
|
|
const expected = fs.readFileSync(
|
|
path.resolve(`${__dirname}/fixtures/tailwind-output-with-explicit-screen-utilities.css`),
|
|
'utf8'
|
|
)
|
|
|
|
expect(result.css).toBe(expected)
|
|
})
|
|
})
|
|
|
|
it('generates the right CSS when "important" is enabled', () => {
|
|
const inputPath = path.resolve(`${__dirname}/fixtures/tailwind-input.css`)
|
|
const input = fs.readFileSync(inputPath, 'utf8')
|
|
|
|
return postcss([tailwind({ ...config, important: true })])
|
|
.process(input, { from: inputPath })
|
|
.then((result) => {
|
|
const expected = fs.readFileSync(
|
|
path.resolve(`${__dirname}/fixtures/tailwind-output-important.css`),
|
|
'utf8'
|
|
)
|
|
|
|
expect(dropTailwindHeader(result.css)).toBe(dropTailwindHeader(expected))
|
|
})
|
|
})
|