1
- import { runWithSourceMaps as run , html , css } from './util/run'
1
+ import postcss from 'postcss'
2
+ import { runWithSourceMaps as run , html , css , map } from './util/run'
2
3
import { parseSourceMaps } from './util/source-maps'
3
4
4
5
it ( 'apply generates source maps' , async ( ) => {
@@ -39,7 +40,6 @@ it('apply generates source maps', async () => {
39
40
expect ( sources ) . not . toContain ( '<no source>' )
40
41
expect ( sources . length ) . toBe ( 1 )
41
42
42
- // It would make the tests nicer to read and write
43
43
expect ( annotations ) . toMatchSnapshot ( )
44
44
} )
45
45
@@ -60,7 +60,6 @@ it('preflight + base have source maps', async () => {
60
60
expect ( sources ) . not . toContain ( '<no source>' )
61
61
expect ( sources . length ) . toBe ( 1 )
62
62
63
- // It would make the tests nicer to read and write
64
63
expect ( annotations ) . toMatchSnapshot ( )
65
64
} )
66
65
@@ -81,7 +80,6 @@ it('utilities have source maps', async () => {
81
80
expect ( sources ) . not . toContain ( '<no source>' )
82
81
expect ( sources . length ) . toBe ( 1 )
83
82
84
- // It would make the tests nicer to read and write
85
83
expect ( annotations ) . toStrictEqual ( [ '2:4 -> 1:0' , '2:4-23 -> 2:4-24' , '2:4 -> 3:4' , '2:23 -> 4:0' ] )
86
84
} )
87
85
@@ -102,6 +100,50 @@ it('components have source maps', async () => {
102
100
expect ( sources ) . not . toContain ( '<no source>' )
103
101
expect ( sources . length ) . toBe ( 1 )
104
102
105
- // It would make the tests nicer to read and write
103
+ expect ( annotations ) . toMatchSnapshot ( )
104
+ } )
105
+
106
+ it ( 'source maps for layer rules are not rewritten to point to @tailwind directives' , async ( ) => {
107
+ let config = {
108
+ content : [ { raw : `font-normal foo hover:foo` } ] ,
109
+ }
110
+
111
+ let utilitiesFile = postcss . parse (
112
+ css `
113
+ @tailwind utilities;
114
+ ` ,
115
+ { from : 'components.css' , map : { prev : map } }
116
+ )
117
+
118
+ let mainCssFile = postcss . parse (
119
+ css `
120
+ @layer utilities {
121
+ .foo {
122
+ background-color : red;
123
+ }
124
+ }
125
+ ` ,
126
+ { from : 'input.css' , map : { prev : map } }
127
+ )
128
+
129
+ // Just pretend that there's an @import in `mainCssFile` that imports the nodes from `utilitiesFile`
130
+ let input = postcss . root ( {
131
+ nodes : [ ...utilitiesFile . nodes , ...mainCssFile . nodes ] ,
132
+ source : mainCssFile . source ,
133
+ } )
134
+
135
+ let result = await run ( input , config )
136
+
137
+ let { sources, annotations } = parseSourceMaps ( result )
138
+
139
+ // All CSS generated by Tailwind CSS should be annotated with source maps
140
+ // And always be able to point to the original source file
141
+ expect ( sources ) . not . toContain ( '<no source>' )
142
+
143
+ // And we should see that the source map for the layer rule is not rewritten
144
+ // to point to the @tailwind directive but instead points to the original
145
+ expect ( sources . length ) . toBe ( 2 )
146
+ expect ( sources ) . toEqual ( [ 'components.css' , 'input.css' ] )
147
+
106
148
expect ( annotations ) . toMatchSnapshot ( )
107
149
} )
0 commit comments