tailwindcss/__tests__/sanity.test.js

50 lines
1.3 KiB
JavaScript
Raw 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'
/**
* Tests
*/
it('generates the right CSS', () => {
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 })
2017-10-17 08:57:44 -04:00
.then(result => {
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
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 })
2017-11-03 20:52:16 +01:00
.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 })
2017-11-03 19:43:40 +01: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
})