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!
178 lines
3.8 KiB
JavaScript
178 lines
3.8 KiB
JavaScript
import { crosscheck, run, html, css } from './util/run'
|
|
|
|
crosscheck(() => {
|
|
it('should collapse duplicate declarations with the same units (px)', () => {
|
|
let config = {
|
|
content: [{ raw: html`<div class="example"></div>` }],
|
|
corePlugins: { preflight: false },
|
|
plugins: [],
|
|
}
|
|
|
|
let input = css`
|
|
@tailwind utilities;
|
|
|
|
@layer utilities {
|
|
.example {
|
|
height: 100px;
|
|
height: 200px;
|
|
}
|
|
}
|
|
`
|
|
|
|
return run(input, config).then((result) => {
|
|
expect(result.css).toMatchFormattedCss(css`
|
|
.example {
|
|
height: 200px;
|
|
}
|
|
`)
|
|
})
|
|
})
|
|
|
|
it('should collapse duplicate declarations with the same units (no unit)', () => {
|
|
let config = {
|
|
content: [{ raw: html`<div class="example"></div>` }],
|
|
corePlugins: { preflight: false },
|
|
plugins: [],
|
|
}
|
|
|
|
let input = css`
|
|
@tailwind utilities;
|
|
|
|
@layer utilities {
|
|
.example {
|
|
line-height: 3;
|
|
line-height: 2;
|
|
}
|
|
}
|
|
`
|
|
|
|
return run(input, config).then((result) => {
|
|
expect(result.css).toMatchFormattedCss(css`
|
|
.example {
|
|
line-height: 2;
|
|
}
|
|
`)
|
|
})
|
|
})
|
|
|
|
it('should not collapse duplicate declarations with the different units', () => {
|
|
let config = {
|
|
content: [{ raw: html`<div class="example"></div>` }],
|
|
corePlugins: { preflight: false },
|
|
plugins: [],
|
|
}
|
|
|
|
let input = css`
|
|
@tailwind utilities;
|
|
|
|
@layer utilities {
|
|
.example {
|
|
height: 100px;
|
|
height: 50%;
|
|
}
|
|
}
|
|
`
|
|
|
|
return run(input, config).then((result) => {
|
|
expect(result.css).toMatchFormattedCss(css`
|
|
.example {
|
|
height: 100px;
|
|
height: 50%;
|
|
}
|
|
`)
|
|
})
|
|
})
|
|
|
|
it('should collapse the duplicate declarations with the same unit, but leave the ones with different units', () => {
|
|
let config = {
|
|
content: [{ raw: html`<div class="example"></div>` }],
|
|
corePlugins: { preflight: false },
|
|
plugins: [],
|
|
}
|
|
|
|
let input = css`
|
|
@tailwind utilities;
|
|
|
|
@layer utilities {
|
|
.example {
|
|
height: 100px;
|
|
height: 50%;
|
|
height: 20vh;
|
|
height: 200px;
|
|
height: 100%;
|
|
height: 30vh;
|
|
}
|
|
}
|
|
`
|
|
|
|
return run(input, config).then((result) => {
|
|
expect(result.css).toMatchFormattedCss(css`
|
|
.example {
|
|
height: 200px;
|
|
height: 100%;
|
|
height: 30vh;
|
|
}
|
|
`)
|
|
})
|
|
})
|
|
|
|
it('should collapse the duplicate declarations with the exact same value', () => {
|
|
let config = {
|
|
content: [{ raw: html`<div class="example"></div>` }],
|
|
corePlugins: { preflight: false },
|
|
plugins: [],
|
|
}
|
|
|
|
let input = css`
|
|
@tailwind utilities;
|
|
|
|
@layer utilities {
|
|
.example {
|
|
height: var(--value);
|
|
color: blue;
|
|
height: var(--value);
|
|
}
|
|
}
|
|
`
|
|
|
|
return run(input, config).then((result) => {
|
|
expect(result.css).toMatchFormattedCss(css`
|
|
.example {
|
|
color: #00f;
|
|
height: var(--value);
|
|
}
|
|
`)
|
|
})
|
|
})
|
|
|
|
it('should work on a real world example', () => {
|
|
let config = {
|
|
content: [{ raw: html`<div class="h-available"></div>` }],
|
|
corePlugins: { preflight: false },
|
|
plugins: [],
|
|
}
|
|
|
|
let input = css`
|
|
@tailwind utilities;
|
|
|
|
@layer utilities {
|
|
.h-available {
|
|
height: 100%;
|
|
height: 100vh;
|
|
height: -webkit-fill-available;
|
|
}
|
|
}
|
|
`
|
|
|
|
return run(input, config).then((result) => {
|
|
expect(result.css).toMatchFormattedCss(css`
|
|
.h-available {
|
|
height: 100%;
|
|
height: 100vh;
|
|
height: -webkit-fill-available;
|
|
}
|
|
`)
|
|
})
|
|
})
|
|
})
|