tailwindcss/tests/plugins/fontFamily.test.js
Robin Malfait a4f1ff9052
Improve CSS output in tests to better reflect reality (#10454)
* 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!
2023-01-31 15:37:49 +01:00

101 lines
2.7 KiB
JavaScript

import { crosscheck, run, html, css } from '../util/run'
crosscheck(() => {
test('font-family utilities can be defined as a string', () => {
let config = {
content: [{ raw: html`<div class="font-sans"></div>` }],
theme: {
fontFamily: {
sans: 'Helvetica, Arial, sans-serif',
},
},
}
return run('@tailwind utilities', config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
.font-sans {
font-family: Helvetica, Arial, sans-serif;
}
`)
})
})
test('font-family utilities can be defined as an array', () => {
let config = {
content: [{ raw: html`<div class="font-sans"></div>` }],
theme: {
fontFamily: {
sans: ['Helvetica', 'Arial', 'sans-serif'],
},
},
}
return run('@tailwind utilities', config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
.font-sans {
font-family: Helvetica, Arial, sans-serif;
}
`)
})
})
test('font-family values are not automatically escaped', () => {
let config = {
content: [{ raw: html`<div class="font-sans"></div>` }],
theme: {
fontFamily: {
sans: ["'Exo 2'", 'sans-serif'],
},
},
}
return run('@tailwind utilities', config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
.font-sans {
font-family: 'Exo 2', sans-serif;
}
`)
})
})
test('font-feature-settings can be provided when families are defined as a string', () => {
let config = {
content: [{ raw: html`<div class="font-sans"></div>` }],
theme: {
fontFamily: {
sans: ['Helvetica, Arial, sans-serif', { fontFeatureSettings: '"cv11", "ss01"' }],
},
},
}
return run('@tailwind utilities', config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
.font-sans {
font-feature-settings: 'cv11', 'ss01';
font-family: Helvetica, Arial, sans-serif;
}
`)
})
})
test('font-feature-settings can be provided when families are defined as an array', () => {
let config = {
content: [{ raw: html`<div class="font-sans"></div>` }],
theme: {
fontFamily: {
sans: [['Helvetica', 'Arial', 'sans-serif'], { fontFeatureSettings: '"cv11", "ss01"' }],
},
},
}
return run('@tailwind utilities', config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
.font-sans {
font-feature-settings: 'cv11', 'ss01';
font-family: Helvetica, Arial, sans-serif;
}
`)
})
})
})