From 895b92a157d4a4bddc967f168056db4f719328be Mon Sep 17 00:00:00 2001
From: Oliver Davies <oliver@oliverdavies.uk>
Date: Thu, 11 Apr 2019 13:14:27 +0100
Subject: [PATCH] init

---
 .gitignore   |  2 ++
 index.js     |  9 +++++++++
 package.json | 24 ++++++++++++++++++++++++
 test.js      | 41 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 76 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 index.js
 create mode 100644 package.json
 create mode 100644 test.js

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5e760f6
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+/node_modules/
+/yarn.lock
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..ab13eac
--- /dev/null
+++ b/index.js
@@ -0,0 +1,9 @@
+module.exports = (variants) => {
+  return function ({ addUtilities }) {
+    addUtilities({
+      '.test': {
+        display: 'block'
+      },
+    }, variants)
+  }
+}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..671566a
--- /dev/null
+++ b/package.json
@@ -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"
+  }
+}
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..fb41ce2
--- /dev/null
+++ b/test.js
@@ -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;
+      }
+    `)
+  })
+})