mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2025-12-08 21:36:08 +00:00
* drop empty lines when diffing output * replace expected css with optimized lightningcss output Lightning CSS generates a more optimal CSS output. Right now the tests are setup in a way that both the generated css and expected css are run through `lightningcss` to make sure that the output is concistent for the `stable` and `oxide` engines. But this also means that the expected output _could_ be larger (aka not optimized) and still matches (after it runs through lightningcss). By replacing this with the more optimal output we achieve a few things: 1. This better reflects reality since we will be using `lightningcss`. 2. This gets rid of unnecessary css. 3. Removed code!
139 lines
3.4 KiB
JavaScript
139 lines
3.4 KiB
JavaScript
import { crosscheck, run, html, css } from './util/run'
|
|
|
|
crosscheck(() => {
|
|
test('basic parallel variants', async () => {
|
|
let config = {
|
|
content: [
|
|
{
|
|
raw: html`<div
|
|
class="hover:test:font-black test:font-bold test:font-medium font-normal"
|
|
></div>`,
|
|
},
|
|
],
|
|
plugins: [
|
|
function test({ addVariant }) {
|
|
addVariant('test', ['& *::test', '&::test'])
|
|
},
|
|
],
|
|
}
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
expect(result.css).toMatchFormattedCss(css`
|
|
.font-normal {
|
|
font-weight: 400;
|
|
}
|
|
.test\:font-bold ::test {
|
|
font-weight: 700;
|
|
}
|
|
.test\:font-medium ::test {
|
|
font-weight: 500;
|
|
}
|
|
.hover\:test\:font-black :hover::test {
|
|
font-weight: 900;
|
|
}
|
|
.test\:font-bold::test {
|
|
font-weight: 700;
|
|
}
|
|
.test\:font-medium::test {
|
|
font-weight: 500;
|
|
}
|
|
.hover\:test\:font-black:hover::test {
|
|
font-weight: 900;
|
|
}
|
|
`)
|
|
})
|
|
})
|
|
|
|
test('parallel variants can be generated using a function that returns parallel variants', async () => {
|
|
let config = {
|
|
content: [
|
|
{
|
|
raw: html`<div
|
|
class="hover:test:font-black test:font-bold test:font-medium font-normal"
|
|
></div>`,
|
|
},
|
|
],
|
|
plugins: [
|
|
function test({ addVariant }) {
|
|
addVariant('test', () => ['& *::test', '&::test'])
|
|
},
|
|
],
|
|
}
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
expect(result.css).toMatchFormattedCss(css`
|
|
.font-normal {
|
|
font-weight: 400;
|
|
}
|
|
.test\:font-bold ::test {
|
|
font-weight: 700;
|
|
}
|
|
.test\:font-medium ::test {
|
|
font-weight: 500;
|
|
}
|
|
.test\:font-bold::test {
|
|
font-weight: 700;
|
|
}
|
|
.test\:font-medium::test {
|
|
font-weight: 500;
|
|
}
|
|
.hover\:test\:font-black :hover::test {
|
|
font-weight: 900;
|
|
}
|
|
.hover\:test\:font-black:hover::test {
|
|
font-weight: 900;
|
|
}
|
|
`)
|
|
})
|
|
})
|
|
|
|
test('a function that returns parallel variants can modify the container', async () => {
|
|
let config = {
|
|
content: [
|
|
{
|
|
raw: html`<div
|
|
class="hover:test:font-black test:font-bold test:font-medium font-normal"
|
|
></div>`,
|
|
},
|
|
],
|
|
plugins: [
|
|
function test({ addVariant }) {
|
|
addVariant('test', ({ container }) => {
|
|
container.walkDecls((decl) => {
|
|
decl.value = `calc(0 + ${decl.value})`
|
|
})
|
|
|
|
return ['& *::test', '&::test']
|
|
})
|
|
},
|
|
],
|
|
}
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
expect(result.css).toMatchFormattedCss(css`
|
|
.font-normal {
|
|
font-weight: 400;
|
|
}
|
|
.test\:font-bold ::test {
|
|
font-weight: 700;
|
|
}
|
|
.test\:font-medium ::test {
|
|
font-weight: 500;
|
|
}
|
|
.test\:font-bold::test {
|
|
font-weight: 700;
|
|
}
|
|
.test\:font-medium::test {
|
|
font-weight: 500;
|
|
}
|
|
.hover\:test\:font-black :hover::test {
|
|
font-weight: 900;
|
|
}
|
|
.hover\:test\:font-black:hover::test {
|
|
font-weight: 900;
|
|
}
|
|
`)
|
|
})
|
|
})
|
|
})
|