2019-03-04 16:19:07 -05:00
|
|
|
import fs from 'fs'
|
2017-11-24 12:34:21 -05:00
|
|
|
import path from 'path'
|
|
|
|
|
import postcss from 'postcss'
|
|
|
|
|
import tailwind from '../src/index'
|
2019-03-15 07:08:34 -05:00
|
|
|
import { defaultConfigFile } from '../src/constants'
|
2019-03-20 08:17:56 -05:00
|
|
|
import inTempDirectory from '../jest/runInTempDirectory'
|
2019-03-04 16:19:07 -05:00
|
|
|
|
2017-11-24 12:34:21 -05:00
|
|
|
test('it uses the values from the custom config file', () => {
|
2018-09-13 21:37:10 -05:00
|
|
|
return postcss([tailwind(path.resolve(`${__dirname}/fixtures/custom-config.js`))])
|
2017-11-24 12:39:27 -05:00
|
|
|
.process(
|
|
|
|
|
`
|
2018-03-06 14:07:27 -05:00
|
|
|
@responsive {
|
|
|
|
|
.foo {
|
|
|
|
|
color: blue;
|
|
|
|
|
}
|
2017-11-24 12:34:21 -05:00
|
|
|
}
|
2018-03-06 14:07:27 -05:00
|
|
|
`,
|
|
|
|
|
{ from: undefined }
|
2017-11-24 12:39:27 -05:00
|
|
|
)
|
2017-11-24 12:34:21 -05:00
|
|
|
.then(result => {
|
|
|
|
|
const expected = `
|
|
|
|
|
.foo {
|
|
|
|
|
color: blue;
|
|
|
|
|
}
|
|
|
|
|
@media (min-width: 400px) {
|
|
|
|
|
.mobile\\:foo {
|
|
|
|
|
color: blue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`
|
|
|
|
|
expect(result.css).toMatchCss(expected)
|
|
|
|
|
})
|
|
|
|
|
})
|
2018-06-25 08:35:01 -04:00
|
|
|
|
|
|
|
|
test('custom config can be passed as an object', () => {
|
2018-06-26 13:44:38 -04:00
|
|
|
return postcss([
|
|
|
|
|
tailwind({
|
2019-01-31 20:22:50 -05:00
|
|
|
theme: {
|
|
|
|
|
screens: {
|
|
|
|
|
mobile: '400px',
|
|
|
|
|
},
|
2018-06-26 13:44:38 -04:00
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
])
|
2018-06-25 08:35:01 -04:00
|
|
|
.process(
|
|
|
|
|
`
|
|
|
|
|
@responsive {
|
|
|
|
|
.foo {
|
|
|
|
|
color: blue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
{ from: undefined }
|
|
|
|
|
)
|
|
|
|
|
.then(result => {
|
|
|
|
|
const expected = `
|
|
|
|
|
.foo {
|
|
|
|
|
color: blue;
|
|
|
|
|
}
|
|
|
|
|
@media (min-width: 400px) {
|
|
|
|
|
.mobile\\:foo {
|
|
|
|
|
color: blue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
expect(result.css).toMatchCss(expected)
|
|
|
|
|
})
|
|
|
|
|
})
|
2019-03-04 16:19:07 -05:00
|
|
|
|
2019-08-02 08:07:42 -04:00
|
|
|
test('custom config path can be passed using `config` property in an object', () => {
|
|
|
|
|
return postcss([tailwind({ config: path.resolve(`${__dirname}/fixtures/custom-config.js`) })])
|
|
|
|
|
.process(
|
|
|
|
|
`
|
|
|
|
|
@responsive {
|
|
|
|
|
.foo {
|
|
|
|
|
color: blue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
{ from: undefined }
|
|
|
|
|
)
|
|
|
|
|
.then(result => {
|
|
|
|
|
const expected = `
|
|
|
|
|
.foo {
|
|
|
|
|
color: blue;
|
|
|
|
|
}
|
|
|
|
|
@media (min-width: 400px) {
|
|
|
|
|
.mobile\\:foo {
|
|
|
|
|
color: blue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`
|
|
|
|
|
expect(result.css).toMatchCss(expected)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-02 08:31:46 -04:00
|
|
|
test('custom config can be passed under the `config` property', () => {
|
|
|
|
|
return postcss([
|
|
|
|
|
tailwind({
|
|
|
|
|
config: {
|
|
|
|
|
theme: {
|
|
|
|
|
screens: {
|
|
|
|
|
mobile: '400px',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
])
|
|
|
|
|
.process(
|
|
|
|
|
`
|
|
|
|
|
@responsive {
|
|
|
|
|
.foo {
|
|
|
|
|
color: blue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
{ from: undefined }
|
|
|
|
|
)
|
|
|
|
|
.then(result => {
|
|
|
|
|
const expected = `
|
|
|
|
|
.foo {
|
|
|
|
|
color: blue;
|
|
|
|
|
}
|
|
|
|
|
@media (min-width: 400px) {
|
|
|
|
|
.mobile\\:foo {
|
|
|
|
|
color: blue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
expect(result.css).toMatchCss(expected)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-03-04 16:19:07 -05:00
|
|
|
test('tailwind.config.js is picked up by default', () => {
|
|
|
|
|
return inTempDirectory(() => {
|
|
|
|
|
fs.writeFileSync(
|
2019-03-15 07:08:34 -05:00
|
|
|
path.resolve(defaultConfigFile),
|
2019-03-04 16:19:07 -05:00
|
|
|
`module.exports = {
|
|
|
|
|
theme: {
|
|
|
|
|
screens: {
|
|
|
|
|
mobile: '400px',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}`
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return postcss([tailwind])
|
|
|
|
|
.process(
|
|
|
|
|
`
|
|
|
|
|
@responsive {
|
|
|
|
|
.foo {
|
|
|
|
|
color: blue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
{ from: undefined }
|
|
|
|
|
)
|
|
|
|
|
.then(result => {
|
|
|
|
|
expect(result.css).toMatchCss(`
|
|
|
|
|
.foo {
|
|
|
|
|
color: blue;
|
|
|
|
|
}
|
|
|
|
|
@media (min-width: 400px) {
|
|
|
|
|
.mobile\\:foo {
|
|
|
|
|
color: blue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
2019-08-02 08:14:07 -04:00
|
|
|
|
|
|
|
|
test('tailwind.config.js is picked up by default when passing an empty object', () => {
|
|
|
|
|
return inTempDirectory(() => {
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
|
path.resolve(defaultConfigFile),
|
|
|
|
|
`module.exports = {
|
|
|
|
|
theme: {
|
|
|
|
|
screens: {
|
|
|
|
|
mobile: '400px',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}`
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return postcss([tailwind({})])
|
|
|
|
|
.process(
|
|
|
|
|
`
|
|
|
|
|
@responsive {
|
|
|
|
|
.foo {
|
|
|
|
|
color: blue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
{ from: undefined }
|
|
|
|
|
)
|
|
|
|
|
.then(result => {
|
|
|
|
|
expect(result.css).toMatchCss(`
|
|
|
|
|
.foo {
|
|
|
|
|
color: blue;
|
|
|
|
|
}
|
|
|
|
|
@media (min-width: 400px) {
|
|
|
|
|
.mobile\\:foo {
|
|
|
|
|
color: blue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|