@@ -68,6 +68,51 @@ test('purges unused classes', () => {
6868 } )
6969} )
7070
71+ test ( 'does not purge components' , ( ) => {
72+ const OLD_NODE_ENV = process . env . NODE_ENV
73+ process . env . NODE_ENV = 'production'
74+ const inputPath = path . resolve ( `${ __dirname } /fixtures/tailwind-input.css` )
75+ const input = fs . readFileSync ( inputPath , 'utf8' )
76+
77+ return postcss ( [
78+ tailwind ( {
79+ ...config ,
80+ purge : [ path . resolve ( `${ __dirname } /fixtures/**/*.html` ) ] ,
81+ } ) ,
82+ ] )
83+ . process ( input , { from : inputPath } )
84+ . then ( result => {
85+ process . env . NODE_ENV = OLD_NODE_ENV
86+
87+ expect ( result . css ) . toContain ( '.container' )
88+
89+ expect ( result . css ) . not . toContain ( '.bg-red-600' )
90+ expect ( result . css ) . not . toContain ( '.w-1\\/3' )
91+ expect ( result . css ) . not . toContain ( '.flex' )
92+ expect ( result . css ) . not . toContain ( '.font-sans' )
93+ expect ( result . css ) . not . toContain ( '.text-right' )
94+ expect ( result . css ) . not . toContain ( '.px-4' )
95+ expect ( result . css ) . not . toContain ( '.h-full' )
96+
97+ expect ( result . css ) . toContain ( '.bg-red-500' )
98+ expect ( result . css ) . toContain ( '.md\\:bg-blue-300' )
99+ expect ( result . css ) . toContain ( '.w-1\\/2' )
100+ expect ( result . css ) . toContain ( '.block' )
101+ expect ( result . css ) . toContain ( '.md\\:flow-root' )
102+ expect ( result . css ) . toContain ( '.h-screen' )
103+ expect ( result . css ) . toContain ( '.min-h-\\(screen-4\\)' )
104+ expect ( result . css ) . toContain ( '.bg-black\\!' )
105+ expect ( result . css ) . toContain ( '.font-\\%\\#\\$\\@' )
106+ expect ( result . css ) . toContain ( '.w-\\(1\\/2\\+8\\)' )
107+ expect ( result . css ) . toContain ( '.inline-grid' )
108+ expect ( result . css ) . toContain ( '.grid-cols-3' )
109+ expect ( result . css ) . toContain ( '.px-1\\.5' )
110+ expect ( result . css ) . toContain ( '.col-span-2' )
111+ expect ( result . css ) . toContain ( '.col-span-1' )
112+ expect ( result . css ) . toContain ( '.text-center' )
113+ } )
114+ } )
115+
71116test ( 'does not purge except in production' , ( ) => {
72117 const OLD_NODE_ENV = process . env . NODE_ENV
73118 process . env . NODE_ENV = 'development'
@@ -92,6 +137,30 @@ test('does not purge except in production', () => {
92137 } )
93138} )
94139
140+ test ( 'does not purge if the array is empty' , ( ) => {
141+ const OLD_NODE_ENV = process . env . NODE_ENV
142+ process . env . NODE_ENV = 'production'
143+ const inputPath = path . resolve ( `${ __dirname } /fixtures/tailwind-input.css` )
144+ const input = fs . readFileSync ( inputPath , 'utf8' )
145+
146+ return postcss ( [
147+ tailwind ( {
148+ ...defaultConfig ,
149+ purge : [ ] ,
150+ } ) ,
151+ ] )
152+ . process ( input , { from : inputPath } )
153+ . then ( result => {
154+ process . env . NODE_ENV = OLD_NODE_ENV
155+ const expected = fs . readFileSync (
156+ path . resolve ( `${ __dirname } /fixtures/tailwind-output.css` ) ,
157+ 'utf8'
158+ )
159+
160+ expect ( result . css ) . toBe ( expected )
161+ } )
162+ } )
163+
95164test ( 'purges outside of production if explicitly enabled' , ( ) => {
96165 const OLD_NODE_ENV = process . env . NODE_ENV
97166 process . env . NODE_ENV = 'development'
0 commit comments