@@ -2,21 +2,42 @@ const tailwind = require('tailwindcss')
22const snapshotDiff = require ( 'snapshot-diff' )
33const postcss = require ( 'postcss' )
44const path = require ( 'path' )
5+ const fs = require ( 'fs' )
6+ const atImport = require ( "postcss-import" )
57
68module . 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 , {
0 commit comments