This commit is contained in:
Oliver Davies 2019-04-11 13:14:27 +01:00
commit 895b92a157
4 changed files with 76 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/node_modules/
/yarn.lock

9
index.js Normal file
View file

@ -0,0 +1,9 @@
module.exports = (variants) => {
return function ({ addUtilities }) {
addUtilities({
'.test': {
display: 'block'
},
}, variants)
}
}

24
package.json Normal file
View file

@ -0,0 +1,24 @@
{
"name": "tailwindcss-plugin-jest-example",
"version": "0.1.0",
"description": "An example showing how to write tests for for Tailwind CSS plugins.",
"main": "index.js",
"scripts": {
"test": "jest"
},
"keywords": ["tailwindcss", "jest"],
"author": {
"name": "Oliver Davies",
"url" : "https://www.oliverdavies.uk"
},
"license": "MIT",
"devDependencies": {
"jest": "^24.7.1",
"jest-matcher-css": "^1.0.3"
},
"dependencies": {
"lodash": "^4.17.11",
"postcss": "^7.0.14",
"tailwindcss": "^1.0.0-beta.4"
}
}

41
test.js Normal file
View file

@ -0,0 +1,41 @@
const _ = require('lodash')
const cssMatcher = require('jest-matcher-css')
const defaultConfig = require('tailwindcss/defaultConfig')
const plugin = require('./index.js')
const postcss = require('postcss')
const tailwindcss = require('tailwindcss')
const disableCorePlugins = () => {
return _.mapValues(defaultConfig.variants, plugin => {
return false
})
}
const generatePluginCss = () => {
return postcss(
tailwindcss({
corePlugins: disableCorePlugins(),
plugins: [plugin()]
})
)
.process('@tailwind utilities;', {
from: undefined
})
.then(result => {
return result.css
})
}
expect.extend({
toMatchCss: cssMatcher
})
test('it generates classes', () => {
return generatePluginCss().then(css => {
expect(css).toMatchCss(`
.test {
display: block;
}
`)
})
})