mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2025-12-08 21:36:08 +00:00
100 lines
2.6 KiB
JavaScript
100 lines
2.6 KiB
JavaScript
import postcss from 'postcss'
|
|
import plugin from '../src/lib/substituteVariantsAtRules'
|
|
import config from '../defaultConfig.stub.js'
|
|
|
|
const separator = config.options.separator
|
|
|
|
function run(input, opts = () => config) {
|
|
return postcss([plugin(opts)]).process(input)
|
|
}
|
|
|
|
test('it can generate hover variants', () => {
|
|
const input = `
|
|
@variants hover {
|
|
.banana { color: yellow; }
|
|
.chocolate { color: brown; }
|
|
}
|
|
`
|
|
|
|
const output = `
|
|
.banana { color: yellow; }
|
|
.chocolate { color: brown; }
|
|
.hover${separator}banana:hover { color: yellow; }
|
|
.hover${separator}chocolate:hover { color: brown; }
|
|
`
|
|
|
|
return run(input).then(result => {
|
|
expect(result.css).toMatchCss(output)
|
|
expect(result.warnings().length).toBe(0)
|
|
})
|
|
})
|
|
|
|
test('it can generate focus variants', () => {
|
|
const input = `
|
|
@variants focus {
|
|
.banana { color: yellow; }
|
|
.chocolate { color: brown; }
|
|
}
|
|
`
|
|
|
|
const output = `
|
|
.banana { color: yellow; }
|
|
.chocolate { color: brown; }
|
|
.focus${separator}banana:focus { color: yellow; }
|
|
.focus${separator}chocolate:focus { color: brown; }
|
|
`
|
|
|
|
return run(input).then(result => {
|
|
expect(result.css).toMatchCss(output)
|
|
expect(result.warnings().length).toBe(0)
|
|
})
|
|
})
|
|
|
|
test('it can generate hover and focus variants', () => {
|
|
const input = `
|
|
@variants hover, focus {
|
|
.banana { color: yellow; }
|
|
.chocolate { color: brown; }
|
|
}
|
|
`
|
|
|
|
const output = `
|
|
.banana { color: yellow; }
|
|
.chocolate { color: brown; }
|
|
.focus${separator}banana:focus { color: yellow; }
|
|
.focus${separator}chocolate:focus { color: brown; }
|
|
.hover${separator}banana:hover { color: yellow; }
|
|
.hover${separator}chocolate:hover { color: brown; }
|
|
`
|
|
|
|
return run(input).then(result => {
|
|
expect(result.css).toMatchCss(output)
|
|
expect(result.warnings().length).toBe(0)
|
|
})
|
|
})
|
|
|
|
test('it wraps the output in a responsive at-rule if responsive is included as a variant', () => {
|
|
const input = `
|
|
@variants responsive, hover, focus {
|
|
.banana { color: yellow; }
|
|
.chocolate { color: brown; }
|
|
}
|
|
`
|
|
|
|
const output = `
|
|
@responsive {
|
|
.banana { color: yellow; }
|
|
.chocolate { color: brown; }
|
|
.focus${separator}banana:focus { color: yellow; }
|
|
.focus${separator}chocolate:focus { color: brown; }
|
|
.hover${separator}banana:hover { color: yellow; }
|
|
.hover${separator}chocolate:hover { color: brown; }
|
|
}
|
|
`
|
|
|
|
return run(input).then(result => {
|
|
expect(result.css).toMatchCss(output)
|
|
expect(result.warnings().length).toBe(0)
|
|
})
|
|
})
|