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
|
|
|
|
2020-10-16 10:24:16 -04:00
|
|
|
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 })
|
2020-10-16 15:39:44 -04:00
|
|
|
.then((result) => {
|
2017-11-04 00:35:59 -05:00
|
|
|
const expected = fs.readFileSync(
|
|
|
|
|
path.resolve(`${__dirname}/fixtures/tailwind-output.css`),
|
|
|
|
|
'utf8'
|
|
|
|
|
)
|
2017-10-17 08:57:44 -04:00
|
|
|
|
|
|
|
|
expect(result.css).toBe(expected)
|
|
|
|
|
})
|
|
|
|
|
})
|
2017-11-03 19:43:40 +01:00
|
|
|
|
2019-01-18 08:54:58 -05: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 })])
|
2019-01-18 08:54:58 -05:00
|
|
|
.process(input, { from: inputPath })
|
2020-10-16 15:39:44 -04:00
|
|
|
.then((result) => {
|
2019-01-18 08:54:58 -05:00
|
|
|
const expected = fs.readFileSync(
|
|
|
|
|
path.resolve(`${__dirname}/fixtures/tailwind-output-important.css`),
|
|
|
|
|
'utf8'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
expect(result.css).toBe(expected)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2020-01-25 12:14:01 -05:00
|
|
|
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 })
|
2020-10-16 15:39:44 -04:00
|
|
|
.then((result) => {
|
2020-01-25 12:14:01 -05:00
|
|
|
const expected = fs.readFileSync(
|
|
|
|
|
path.resolve(`${__dirname}/fixtures/tailwind-output.css`),
|
|
|
|
|
'utf8'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
expect(result.css).toBe(expected)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2020-08-05 13:59:59 -04:00
|
|
|
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({
|
2020-08-06 16:44:02 -04:00
|
|
|
future: 'all',
|
|
|
|
|
experimental: 'all',
|
2020-08-05 13:59:59 -04:00
|
|
|
}),
|
|
|
|
|
])
|
|
|
|
|
.process(input, { from: inputPath })
|
2020-10-16 15:39:44 -04:00
|
|
|
.then((result) => {
|
2020-08-05 13:59:59 -04:00
|
|
|
const expected = fs.readFileSync(
|
|
|
|
|
path.resolve(`${__dirname}/fixtures/tailwind-output-flagged.css`),
|
|
|
|
|
'utf8'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
expect(result.css).toBe(expected)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2020-05-01 15:04:40 -04:00
|
|
|
// 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 })
|
2020-10-16 15:39:44 -04:00
|
|
|
.then((result) => {
|
2020-05-01 15:04:40 -04:00
|
|
|
const expected = fs.readFileSync(
|
|
|
|
|
path.resolve(`${__dirname}/fixtures/tailwind-output-no-color-opacity.css`),
|
|
|
|
|
'utf8'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
expect(result.css).toBe(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 })
|
2020-10-16 15:39:44 -04:00
|
|
|
.then((result) => {
|
2018-01-19 14:40:43 -05:00
|
|
|
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-08 18:46:47 +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 })
|
2020-10-16 15:39:44 -04:00
|
|
|
.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
|
|
|
})
|
2020-04-27 13:07:27 -04: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 })
|
2020-10-16 15:39:44 -04:00
|
|
|
.then((result) => {
|
2020-04-27 13:07:27 -04:00
|
|
|
const expected = fs.readFileSync(
|
|
|
|
|
path.resolve(`${__dirname}/fixtures/tailwind-output-important.css`),
|
|
|
|
|
'utf8'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
expect(result.css).toBe(expected)
|
|
|
|
|
})
|
|
|
|
|
})
|