tailwindcss/tests/sanity.test.js

155 lines
4.6 KiB
JavaScript
Raw Permalink Normal View History

2017-10-17 08:57:44 -04:00
import fs from 'fs'
import path from 'path'
import postcss from 'postcss'
import tailwind from '../src/index'
2019-03-14 15:51:21 -05:00
import config from '../stubs/defaultConfig.stub.js'
2017-10-17 08:57:44 -04:00
function dropTailwindHeader(css) {
let [header, ...lines] = css.split('\n')
expect(
/\/*! tailwindcss v\d*\.\d*\.\d* \| MIT License \| https:\/\/tailwindcss.com \*\//g.test(header)
).toBe(true)
return lines.join('\n')
}
it('generates the right CSS using the default settings', () => {
2018-03-06 14:07:27 -05:00
const inputPath = path.resolve(`${__dirname}/fixtures/tailwind-input.css`)
const input = fs.readFileSync(inputPath, 'utf8')
2017-10-17 08:57:44 -04:00
return postcss([tailwind()])
2018-03-06 14:07:27 -05:00
.process(input, { from: inputPath })
.then((result) => {
const expected = fs.readFileSync(
path.resolve(`${__dirname}/fixtures/tailwind-output.css`),
'utf8'
)
2017-10-17 08:57:44 -04:00
expect(dropTailwindHeader(result.css)).toBe(dropTailwindHeader(expected))
2017-10-17 08:57:44 -04:00
})
})
2017-11-03 19:43:40 +01:00
it('generates the right CSS when "important" is enabled', () => {
const inputPath = path.resolve(`${__dirname}/fixtures/tailwind-input.css`)
const input = fs.readFileSync(inputPath, 'utf8')
2019-01-18 09:01:37 -05:00
return postcss([tailwind({ ...config, important: true })])
.process(input, { from: inputPath })
.then((result) => {
const expected = fs.readFileSync(
path.resolve(`${__dirname}/fixtures/tailwind-output-important.css`),
'utf8'
)
expect(dropTailwindHeader(result.css)).toBe(dropTailwindHeader(expected))
})
})
it('generates the right CSS when using @import instead of @tailwind', () => {
const inputPath = path.resolve(`${__dirname}/fixtures/tailwind-input-import.css`)
const input = fs.readFileSync(inputPath, 'utf8')
return postcss([tailwind()])
.process(input, { from: inputPath })
.then((result) => {
const expected = fs.readFileSync(
path.resolve(`${__dirname}/fixtures/tailwind-output.css`),
'utf8'
)
expect(dropTailwindHeader(result.css)).toBe(dropTailwindHeader(expected))
})
})
it('generates the right CSS when enabling flagged features', () => {
const inputPath = path.resolve(`${__dirname}/fixtures/tailwind-input.css`)
const input = fs.readFileSync(inputPath, 'utf8')
return postcss([
tailwind({
future: 'all',
experimental: 'all',
}),
])
.process(input, { from: inputPath })
.then((result) => {
const expected = fs.readFileSync(
path.resolve(`${__dirname}/fixtures/tailwind-output-flagged.css`),
'utf8'
)
expect(dropTailwindHeader(result.css)).toBe(dropTailwindHeader(expected))
})
})
// TODO: Move to per plugin unit tests for this sort of thing
it('generates the right CSS when color opacity plugins are disabled', () => {
const inputPath = path.resolve(`${__dirname}/fixtures/tailwind-input.css`)
const input = fs.readFileSync(inputPath, 'utf8')
return postcss([
tailwind({
...config,
corePlugins: {
textOpacity: false,
backgroundOpacity: false,
borderOpacity: false,
placeholderOpacity: false,
divideOpacity: false,
},
}),
])
.process(input, { from: inputPath })
.then((result) => {
const expected = fs.readFileSync(
path.resolve(`${__dirname}/fixtures/tailwind-output-no-color-opacity.css`),
'utf8'
)
expect(dropTailwindHeader(result.css)).toBe(dropTailwindHeader(expected))
})
})
2017-11-03 23:11:44 +01:00
it('does not add any CSS if no Tailwind features are used', () => {
2017-11-03 20:52:16 +01:00
return postcss([tailwind()])
2018-03-06 14:07:27 -05:00
.process('.foo { color: blue; }', { from: undefined })
.then((result) => {
expect(result.css).toMatchCss('.foo { color: blue; }')
2017-11-03 20:52:16 +01:00
})
2017-11-03 23:09:59 +01:00
})
2017-11-03 19:43:40 +01:00
it('generates the right CSS with implicit screen utilities', () => {
2018-03-06 14:07:27 -05:00
const inputPath = path.resolve(
`${__dirname}/fixtures/tailwind-input-with-explicit-screen-utilities.css`
2017-11-08 18:48:48 +01:00
)
2018-03-06 14:07:27 -05:00
const input = fs.readFileSync(inputPath, 'utf8')
2017-11-03 19:43:40 +01:00
return postcss([tailwind()])
2018-03-06 14:07:27 -05:00
.process(input, { from: inputPath })
.then((result) => {
2017-11-08 18:48:48 +01:00
const expected = fs.readFileSync(
path.resolve(`${__dirname}/fixtures/tailwind-output-with-explicit-screen-utilities.css`),
'utf8'
)
2017-11-03 19:43:40 +01:00
expect(result.css).toBe(expected)
})
2017-11-08 18:48:48 +01:00
})
it('generates the right CSS when "important" is enabled', () => {
const inputPath = path.resolve(`${__dirname}/fixtures/tailwind-input.css`)
const input = fs.readFileSync(inputPath, 'utf8')
return postcss([tailwind({ ...config, important: true })])
.process(input, { from: inputPath })
.then((result) => {
const expected = fs.readFileSync(
path.resolve(`${__dirname}/fixtures/tailwind-output-important.css`),
'utf8'
)
expect(dropTailwindHeader(result.css)).toBe(dropTailwindHeader(expected))
})
})