Merge tailwindcss-plugin-jest/master

This commit is contained in:
Oliver Davies 2025-09-29 22:53:24 +01:00
commit 08aea61857
7 changed files with 141 additions and 0 deletions

2
tailwindcss-plugin-jest/.gitignore vendored Normal file
View file

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

View file

@ -0,0 +1,17 @@
language: node_js
node_js:
- '8'
cache:
directories:
- node_modules
before_install:
- npm update
install:
- npm install
script:
- npm test

View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019 Oliver Davies
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,15 @@
# Testing Tailwind CSS Plugins with Jest
An example of how to use [Jest][jest], a JavaScript testing framework, for testing [Tailwind CSS][tailwind] plugins.
## License
MIT
## Author
[Oliver Davies][website] - Full Stack Developer
[jest]: https://jestjs.io
[tailwind]: https://tailwindcss.com
[website]: https://www.oliverdavies.uk

View file

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

View file

@ -0,0 +1,26 @@
{
"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": {
"postcss": "^7.0.14",
"tailwindcss": "^1.0.1"
}
}

View file

@ -0,0 +1,53 @@
const cssMatcher = require('jest-matcher-css')
const defaultConfig = require('tailwindcss/defaultConfig')
const plugin = require('./index')
const postcss = require('postcss')
const tailwindcss = require('tailwindcss')
function run(options = {}) {
return postcss(
tailwindcss({
corePlugins: false,
plugins: [plugin(options)]
})
)
.process('@tailwind utilities;', {
from: undefined
})
}
expect.extend({
toMatchCss: cssMatcher
})
test('it generates the correct classes with no variants', () => {
const output = `
.test {
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)
})
})