Compare commits
17 commits
add-licens
...
master
Author | SHA1 | Date | |
---|---|---|---|
9935d675e3 | |||
81e2052ca2 | |||
98021467bf | |||
388eb307ca | |||
00dc589c9c | |||
4fc24873ac | |||
166e4febfa | |||
fd3018d1e0 | |||
f0e56bf204 | |||
db8240c547 | |||
5195eb9040 | |||
6b11d05dfd | |||
068aecad52 | |||
6f66173812 | |||
c5387b099f | |||
73485e6d3d | |||
![]() |
8e4de76a01 |
4 changed files with 51 additions and 35 deletions
|
@ -1,6 +1,6 @@
|
||||||
# Testing Tailwind CSS Plugins with Jest
|
# Testing Tailwind CSS Plugins with Jest
|
||||||
|
|
||||||
WIP
|
An example of how to use [Jest][jest], a JavaScript testing framework, for testing [Tailwind CSS][tailwind] plugins.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
@ -8,4 +8,8 @@ MIT
|
||||||
|
|
||||||
## Author
|
## Author
|
||||||
|
|
||||||
[Oliver Davies](https://www.oliverdavies.uk) - Full Stack Developer
|
[Oliver Davies][website] - Full Stack Developer
|
||||||
|
|
||||||
|
[jest]: https://jestjs.io
|
||||||
|
[tailwind]: https://tailwindcss.com
|
||||||
|
[website]: https://www.oliverdavies.uk
|
||||||
|
|
14
index.js
14
index.js
|
@ -1,9 +1,7 @@
|
||||||
module.exports = (variants) => {
|
module.exports = (variants) => ({ addUtilities }) => {
|
||||||
return function ({ addUtilities }) {
|
addUtilities({
|
||||||
addUtilities({
|
'.test': {
|
||||||
'.test': {
|
display: 'block'
|
||||||
display: 'block'
|
}
|
||||||
}
|
}, variants)
|
||||||
}, variants)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
10
package.json
10
package.json
|
@ -6,10 +6,13 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "jest"
|
"test": "jest"
|
||||||
},
|
},
|
||||||
"keywords": ["tailwindcss", "jest"],
|
"keywords": [
|
||||||
|
"tailwindcss",
|
||||||
|
"jest"
|
||||||
|
],
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Oliver Davies",
|
"name": "Oliver Davies",
|
||||||
"url" : "https://www.oliverdavies.uk"
|
"url": "https://www.oliverdavies.uk"
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -17,8 +20,7 @@
|
||||||
"jest-matcher-css": "^1.0.3"
|
"jest-matcher-css": "^1.0.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lodash": "^4.17.11",
|
|
||||||
"postcss": "^7.0.14",
|
"postcss": "^7.0.14",
|
||||||
"tailwindcss": "^1.0.0-beta.4"
|
"tailwindcss": "^1.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
54
test.js
54
test.js
|
@ -1,41 +1,53 @@
|
||||||
const _ = require('lodash')
|
|
||||||
const cssMatcher = require('jest-matcher-css')
|
const cssMatcher = require('jest-matcher-css')
|
||||||
const defaultConfig = require('tailwindcss/defaultConfig')
|
const defaultConfig = require('tailwindcss/defaultConfig')
|
||||||
const plugin = require('./index.js')
|
const plugin = require('./index')
|
||||||
const postcss = require('postcss')
|
const postcss = require('postcss')
|
||||||
const tailwindcss = require('tailwindcss')
|
const tailwindcss = require('tailwindcss')
|
||||||
|
|
||||||
const disableCorePlugins = () => {
|
function run(options = {}) {
|
||||||
return _.mapValues(defaultConfig.variants, plugin => {
|
|
||||||
return false
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const generatePluginCss = () => {
|
|
||||||
return postcss(
|
return postcss(
|
||||||
tailwindcss({
|
tailwindcss({
|
||||||
corePlugins: disableCorePlugins(),
|
corePlugins: false,
|
||||||
plugins: [plugin()]
|
plugins: [plugin(options)]
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.process('@tailwind utilities;', {
|
.process('@tailwind utilities;', {
|
||||||
from: undefined
|
from: undefined
|
||||||
})
|
})
|
||||||
.then(result => {
|
|
||||||
return result.css
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
expect.extend({
|
expect.extend({
|
||||||
toMatchCss: cssMatcher
|
toMatchCss: cssMatcher
|
||||||
})
|
})
|
||||||
|
|
||||||
test('it generates classes', () => {
|
test('it generates the correct classes with no variants', () => {
|
||||||
return generatePluginCss().then(css => {
|
const output = `
|
||||||
expect(css).toMatchCss(`
|
.test {
|
||||||
.test {
|
display: block
|
||||||
display: block;
|
}
|
||||||
}
|
`
|
||||||
`)
|
|
||||||
|
run().then(result => {
|
||||||
|
expect(result.css).toMatchCss(output)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
test('it generates the correct classes with variants', () => {
|
||||||
|
const output = `
|
||||||
|
.test {
|
||||||
|
display: block
|
||||||
|
}
|
||||||
|
|
||||||
|
.hover\\:test:hover {
|
||||||
|
display: block
|
||||||
|
}
|
||||||
|
|
||||||
|
.focus\\:test:focus {
|
||||||
|
display: block
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
run({ variants: ['hover', 'focus'] }).then(result => {
|
||||||
|
expect(result.css).toMatchCss(output)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue