mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2025-12-08 21:36:08 +00:00
* use String.raw for css escapes
This will allow us to write code like:
```css
.mobile\:font-bold {}
```
Instead of
```css
.mobile\\:font-bold {}
```
Which resembles "real" css way better in our tests.
* use String.raw in integration tests as well
387 lines
8.8 KiB
JavaScript
387 lines
8.8 KiB
JavaScript
import fs from 'fs'
|
|
import path from 'path'
|
|
import { cjsConfigFile, defaultConfigFile } from '../src/constants'
|
|
import inTempDirectory from '../jest/runInTempDirectory'
|
|
|
|
import { run, html, css, javascript } from './util/run'
|
|
|
|
test('it uses the values from the custom config file', () => {
|
|
let config = require(path.resolve(`${__dirname}/fixtures/custom-config.js`))
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
expect(result.css).toMatchFormattedCss(css`
|
|
@media (min-width: 400px) {
|
|
.mobile\:font-bold {
|
|
font-weight: 700;
|
|
}
|
|
}
|
|
`)
|
|
})
|
|
})
|
|
|
|
test('custom config can be passed as an object', () => {
|
|
let config = {
|
|
content: [{ raw: html`<div class="mobile:font-bold"></div>` }],
|
|
theme: {
|
|
screens: {
|
|
mobile: '400px',
|
|
},
|
|
},
|
|
}
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
expect(result.css).toMatchFormattedCss(css`
|
|
@media (min-width: 400px) {
|
|
.mobile\:font-bold {
|
|
font-weight: 700;
|
|
}
|
|
}
|
|
`)
|
|
})
|
|
})
|
|
|
|
test('custom config path can be passed using `config` property in an object', () => {
|
|
let config = {
|
|
config: path.resolve(`${__dirname}/fixtures/custom-config.js`),
|
|
}
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
expect(result.css).toMatchFormattedCss(css`
|
|
@media (min-width: 400px) {
|
|
.mobile\:font-bold {
|
|
font-weight: 700;
|
|
}
|
|
}
|
|
`)
|
|
})
|
|
})
|
|
|
|
test('custom config can be passed under the `config` property', () => {
|
|
let config = {
|
|
config: {
|
|
content: [{ raw: html`<div class="mobile:font-bold"></div>` }],
|
|
theme: {
|
|
screens: {
|
|
mobile: '400px',
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
expect(result.css).toMatchFormattedCss(css`
|
|
@media (min-width: 400px) {
|
|
.mobile\:font-bold {
|
|
font-weight: 700;
|
|
}
|
|
}
|
|
`)
|
|
})
|
|
})
|
|
|
|
test('tailwind.config.cjs is picked up by default', () => {
|
|
return inTempDirectory(() => {
|
|
fs.writeFileSync(
|
|
path.resolve(cjsConfigFile),
|
|
javascript`module.exports = {
|
|
content: [{ raw: '<div class="mobile:font-bold"></div>' }],
|
|
theme: {
|
|
screens: {
|
|
mobile: '400px',
|
|
},
|
|
},
|
|
}`
|
|
)
|
|
|
|
return run('@tailwind utilities').then((result) => {
|
|
expect(result.css).toMatchFormattedCss(css`
|
|
@media (min-width: 400px) {
|
|
.mobile\:font-bold {
|
|
font-weight: 700;
|
|
}
|
|
}
|
|
`)
|
|
})
|
|
})
|
|
})
|
|
|
|
test('tailwind.config.js is picked up by default', () => {
|
|
return inTempDirectory(() => {
|
|
fs.writeFileSync(
|
|
path.resolve(defaultConfigFile),
|
|
javascript`module.exports = {
|
|
content: [{ raw: '<div class="mobile:font-bold"></div>' }],
|
|
theme: {
|
|
screens: {
|
|
mobile: '400px',
|
|
},
|
|
},
|
|
}`
|
|
)
|
|
|
|
return run('@tailwind utilities').then((result) => {
|
|
expect(result.css).toMatchFormattedCss(css`
|
|
@media (min-width: 400px) {
|
|
.mobile\:font-bold {
|
|
font-weight: 700;
|
|
}
|
|
}
|
|
`)
|
|
})
|
|
})
|
|
})
|
|
|
|
test('tailwind.config.cjs is picked up by default when passing an empty object', () => {
|
|
return inTempDirectory(() => {
|
|
fs.writeFileSync(
|
|
path.resolve(cjsConfigFile),
|
|
javascript`module.exports = {
|
|
content: [{ raw: '<div class="mobile:font-bold"></div>' }],
|
|
theme: {
|
|
screens: {
|
|
mobile: '400px',
|
|
},
|
|
},
|
|
}`
|
|
)
|
|
|
|
return run('@tailwind utilities', {}).then((result) => {
|
|
expect(result.css).toMatchFormattedCss(css`
|
|
@media (min-width: 400px) {
|
|
.mobile\:font-bold {
|
|
font-weight: 700;
|
|
}
|
|
}
|
|
`)
|
|
})
|
|
})
|
|
})
|
|
|
|
test('tailwind.config.js is picked up by default when passing an empty object', () => {
|
|
return inTempDirectory(() => {
|
|
fs.writeFileSync(
|
|
path.resolve(defaultConfigFile),
|
|
javascript`module.exports = {
|
|
content: [{ raw: '<div class="mobile:font-bold"></div>' }],
|
|
theme: {
|
|
screens: {
|
|
mobile: '400px',
|
|
},
|
|
},
|
|
}`
|
|
)
|
|
|
|
return run('@tailwind utilities', {}).then((result) => {
|
|
expect(result.css).toMatchFormattedCss(css`
|
|
@media (min-width: 400px) {
|
|
.mobile\:font-bold {
|
|
font-weight: 700;
|
|
}
|
|
}
|
|
`)
|
|
})
|
|
})
|
|
})
|
|
|
|
test('the default config can be overridden using the presets key', () => {
|
|
let config = {
|
|
content: [{ raw: html`<div class="min-h-0 min-h-primary min-h-secondary"></div>` }],
|
|
presets: [
|
|
{
|
|
theme: {
|
|
extend: { minHeight: { secondary: '24px' } },
|
|
},
|
|
},
|
|
],
|
|
theme: {
|
|
extend: { minHeight: { primary: '48px' } },
|
|
},
|
|
}
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
expect(result.css).toMatchFormattedCss(css`
|
|
.min-h-0 {
|
|
min-height: 0px;
|
|
}
|
|
.min-h-primary {
|
|
min-height: 48px;
|
|
}
|
|
.min-h-secondary {
|
|
min-height: 24px;
|
|
}
|
|
`)
|
|
})
|
|
})
|
|
|
|
test('presets can be functions', () => {
|
|
let config = {
|
|
content: [{ raw: html`<div class="min-h-0 min-h-primary min-h-secondary"></div>` }],
|
|
presets: [
|
|
() => ({
|
|
theme: {
|
|
extend: { minHeight: { secondary: '24px' } },
|
|
},
|
|
}),
|
|
],
|
|
theme: {
|
|
extend: { minHeight: { primary: '48px' } },
|
|
},
|
|
}
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
expect(result.css).toMatchFormattedCss(css`
|
|
.min-h-0 {
|
|
min-height: 0px;
|
|
}
|
|
.min-h-primary {
|
|
min-height: 48px;
|
|
}
|
|
.min-h-secondary {
|
|
min-height: 24px;
|
|
}
|
|
`)
|
|
})
|
|
})
|
|
|
|
test('the default config can be removed by using an empty presets key in a preset', () => {
|
|
let config = {
|
|
content: [{ raw: html`<div class="min-h-0 min-h-primary min-h-secondary"></div>` }],
|
|
presets: [
|
|
{
|
|
presets: [],
|
|
theme: {
|
|
extend: { minHeight: { secondary: '24px' } },
|
|
},
|
|
},
|
|
],
|
|
theme: {
|
|
extend: { minHeight: { primary: '48px' } },
|
|
},
|
|
}
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
expect(result.css).toMatchFormattedCss(css`
|
|
.min-h-primary {
|
|
min-height: 48px;
|
|
}
|
|
.min-h-secondary {
|
|
min-height: 24px;
|
|
}
|
|
`)
|
|
})
|
|
})
|
|
|
|
test('presets can have their own presets', () => {
|
|
let config = {
|
|
content: [{ raw: html`<div class="bg-transparent bg-black bg-white bg-red"></div>` }],
|
|
presets: [
|
|
{
|
|
presets: [],
|
|
theme: {
|
|
colors: { red: '#dd0000' },
|
|
},
|
|
},
|
|
{
|
|
presets: [
|
|
{
|
|
presets: [],
|
|
theme: {
|
|
colors: {
|
|
transparent: 'transparent',
|
|
red: '#ff0000',
|
|
},
|
|
},
|
|
},
|
|
],
|
|
theme: {
|
|
extend: {
|
|
colors: {
|
|
black: 'black',
|
|
red: '#ee0000',
|
|
},
|
|
backgroundColor: (theme) => theme('colors'),
|
|
},
|
|
},
|
|
corePlugins: ['backgroundColor'],
|
|
},
|
|
],
|
|
theme: {
|
|
extend: { colors: { white: 'white' } },
|
|
},
|
|
}
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
expect(result.css).toMatchFormattedCss(css`
|
|
.bg-transparent {
|
|
background-color: transparent;
|
|
}
|
|
.bg-black {
|
|
background-color: black;
|
|
}
|
|
.bg-white {
|
|
background-color: white;
|
|
}
|
|
.bg-red {
|
|
background-color: #ee0000;
|
|
}
|
|
`)
|
|
})
|
|
})
|
|
|
|
test('function presets can be mixed with object presets', () => {
|
|
let config = {
|
|
content: [{ raw: html`<div class="bg-transparent bg-black bg-white bg-red"></div>` }],
|
|
presets: [
|
|
() => ({
|
|
presets: [],
|
|
theme: {
|
|
colors: { red: '#dd0000' },
|
|
},
|
|
}),
|
|
{
|
|
presets: [
|
|
() => ({
|
|
presets: [],
|
|
theme: {
|
|
colors: {
|
|
transparent: 'transparent',
|
|
red: '#ff0000',
|
|
},
|
|
},
|
|
}),
|
|
],
|
|
theme: {
|
|
extend: {
|
|
colors: {
|
|
black: 'black',
|
|
red: '#ee0000',
|
|
},
|
|
backgroundColor: (theme) => theme('colors'),
|
|
},
|
|
},
|
|
corePlugins: ['backgroundColor'],
|
|
},
|
|
],
|
|
theme: {
|
|
extend: { colors: { white: 'white' } },
|
|
},
|
|
}
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
expect(result.css).toMatchFormattedCss(css`
|
|
.bg-transparent {
|
|
background-color: transparent;
|
|
}
|
|
.bg-black {
|
|
background-color: black;
|
|
}
|
|
.bg-white {
|
|
background-color: white;
|
|
}
|
|
.bg-red {
|
|
background-color: #ee0000;
|
|
}
|
|
`)
|
|
})
|
|
})
|