mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2025-12-08 21:36:08 +00:00
* make `jit` mode the default when no mode is specified
* unify JIT and AOT codepaths
* ensure `Object.entries` on undefined doesn't break
It could be that sometimes you don't have values in your config (e.g.: `presets: []`), this in turn will break some plugins where we assume we have a value.
* drop AOT specific tests
These tests are all covered by JIT mode already and were AOT specific.
* simplify tests, and add a few
Some of the tests were written for AOT specifically, some were missing. We also updated the way we write those tests, essentially making Tailwind a blackbox, by testing against the final output.
Now that JIT mode is the default, this is super fast because we only generate what is used, instead of partially testing in a 3MB file or building it all, then purging.
* add some todo's to make sure we warn in a few cases
* make `darkMode: 'media'`, the default
This also includes moving dark mode tests to its own dedicated file.
* remove PostCSS 7 compat mode
* update CLI to be JIT-first
* fix integration tests
This is not a _real_ fix, but it does solve the broken test for now.
* warn when using @responsive or @variants
* remove the JIT preview warning
* remove AOT-only code paths
* remove all `mode: 'jit'` blocks
Also remove `variants: {}` since they are not useful in `JIT` mode
anymore.
* drop unused dependencies
* rename `purge` to `content`
* remove static CDN builds
* mark `--purge` as deprecated in the CLI
This will still work, but a warning will be printed and it won't show up
in the `--help` output.
* cleanup nesting plugin
We don't have to duplicate it anymore since there is no PostCSS 7
version anymore.
* make sure integration tests run in band
* cleanup folder structure
* make sure nesting folder is available
* simplify resolving of purge/content information
461 lines
9.9 KiB
JavaScript
461 lines
9.9 KiB
JavaScript
import fs from 'fs'
|
|
import path from 'path'
|
|
import postcss from 'postcss'
|
|
import tailwind from '../src/index'
|
|
import { cjsConfigFile, defaultConfigFile } from '../src/constants'
|
|
import inTempDirectory from '../jest/runInTempDirectory'
|
|
|
|
// NOTE: If we ever want to abstract this logic, then we have to watch out
|
|
// because in most tests we default to an empty object here. However, in this
|
|
// tests we do want to check the difference between no config (undefined) and a
|
|
// config (empty object or full object).
|
|
function run(input, config /* Undefined is important in this case */) {
|
|
return postcss(tailwind(config)).process(input, {
|
|
from: path.resolve(__filename),
|
|
})
|
|
}
|
|
|
|
function css(templates) {
|
|
return templates.join('')
|
|
}
|
|
|
|
function html(templates) {
|
|
return templates.join('')
|
|
}
|
|
|
|
function javascript(templates) {
|
|
return templates.join('')
|
|
}
|
|
|
|
test('it uses the values from the custom config file', () => {
|
|
let config = require(path.resolve(`${__dirname}/fixtures/custom-config.js`))
|
|
|
|
let content = css`
|
|
@tailwind utilities;
|
|
`
|
|
|
|
return run(content, 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',
|
|
},
|
|
},
|
|
}
|
|
|
|
let content = css`
|
|
@tailwind utilities;
|
|
`
|
|
|
|
return run(content, 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`),
|
|
}
|
|
|
|
let content = css`
|
|
@tailwind utilities;
|
|
`
|
|
|
|
return run(content, 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',
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
let content = css`
|
|
@tailwind utilities;
|
|
`
|
|
|
|
return run(content, 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',
|
|
},
|
|
},
|
|
}`
|
|
)
|
|
|
|
let content = css`
|
|
@tailwind utilities;
|
|
`
|
|
|
|
return run(content).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',
|
|
},
|
|
},
|
|
}`
|
|
)
|
|
|
|
let content = css`
|
|
@tailwind utilities;
|
|
`
|
|
|
|
return run(content).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',
|
|
},
|
|
},
|
|
}`
|
|
)
|
|
|
|
let content = css`
|
|
@tailwind utilities;
|
|
`
|
|
|
|
return run(content, {}).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',
|
|
},
|
|
},
|
|
}`
|
|
)
|
|
|
|
let content = css`
|
|
@tailwind utilities;
|
|
`
|
|
|
|
return run(content, {}).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' } },
|
|
},
|
|
}
|
|
|
|
let content = css`
|
|
@tailwind utilities;
|
|
`
|
|
|
|
return run(content, 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' } },
|
|
},
|
|
}
|
|
|
|
let content = css`
|
|
@tailwind utilities;
|
|
`
|
|
|
|
return run(content, 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' } },
|
|
},
|
|
}
|
|
|
|
let content = css`
|
|
@tailwind utilities;
|
|
`
|
|
|
|
return run(content, 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' } },
|
|
},
|
|
}
|
|
|
|
let content = css`
|
|
@tailwind utilities;
|
|
`
|
|
|
|
return run(content, 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' } },
|
|
},
|
|
}
|
|
|
|
let content = css`
|
|
@tailwind utilities;
|
|
`
|
|
|
|
return run(content, 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;
|
|
}
|
|
`)
|
|
})
|
|
})
|