Skip to content

Commit 22ce041

Browse files
committed
improvements for testing
1 parent 7c941a3 commit 22ce041

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

__tests__/util/_utils.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,42 @@ const tailwind = require('tailwindcss')
22
const snapshotDiff = require('snapshot-diff')
33
const postcss = require('postcss')
44
const path = require('path')
5+
const fs = require('fs')
6+
const atImport = require("postcss-import")
57

68
module.exports = (contentFile) => {
79
let utils = {}
810

911
utils.run = function(config = {}) {
10-
let { currentTestName } = expect.getState();
12+
let { currentTestName } = expect.getState()
13+
let filename = currentTestName + '.test.css'
14+
if (fs.existsSync(path.resolve(__dirname, '../' + filename))) {
15+
return this.runFromFile(filename, config)
16+
}
17+
18+
return this.runInline(config)
19+
}
20+
21+
utils.runInline = (config) => {
1122
return postcss([tailwind({ corePlugins: [], ...config })])
1223
.process(['@tailwind base;', '@tailwind components;', '@tailwind utilities;'].join('\n'), {
13-
// from: `${path.resolve(__filename)}?test=${currentTestName}`
14-
from: undefined
24+
from: undefined,
25+
})
26+
.then((result) => result.css)
27+
}
28+
29+
utils.runFromFile = (filename, config) => {
30+
31+
const css = fs.readFileSync(path.resolve(__dirname, '../' + filename), 'utf8')
32+
return postcss([tailwind({ corePlugins: [], ...config })])
33+
.use(atImport())
34+
.process(css, {
35+
from: path.resolve(__dirname, '../' + filename),
1536
})
1637
.then((result) => result.css)
1738
}
1839

19-
utils.diffOnly = async function (options = {}) {
40+
utils.diffOnly = async function(options = {}) {
2041
const [before, after] = await Promise.all([utils.run(), utils.run(options)])
2142

2243
return `\n\n${snapshotDiff(before, after, {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"fs-extra": "^10.0.0",
4545
"jest": "^27.4.3",
4646
"postcss": "^8.4.4",
47+
"postcss-import": "^14.1.0",
4748
"prettier": "^2.5.0",
4849
"snapshot-diff": "^0.9.0",
4950
"tailwindcss": "^3.0.0"

0 commit comments

Comments
 (0)