@@ -48,22 +48,50 @@ test(
4848 target: document.body,
4949 })
5050 ` ,
51+ 'src/index.css' : css `
52+ @import 'tailwindcss/theme' theme(reference);
53+ @import 'tailwindcss/utilities';
54+ ` ,
5155 'src/App.svelte' : html `
5256 <script>
57+ import './index.css'
5358 let name = 'world'
5459 </script>
5560
56- <h1 class="foo underline">Hello {name}!</h1>
61+ <h1 class="global local underline">Hello {name}!</h1>
5762
58- <style global>
59- @import 'tailwindcss/utilities';
63+ <style>
6064 @import 'tailwindcss/theme' theme(reference);
61- @import './components .css';
65+ @import './other .css';
6266 </style>
6367 ` ,
64- 'src/components .css' : css `
65- .foo {
68+ 'src/other .css' : css `
69+ .local {
6670 @apply text-red-500;
71+ animation: 2s ease-in-out 0s infinite localKeyframes;
72+ }
73+
74+ :global(.global) {
75+ @apply text-green-500;
76+ animation: 2s ease-in-out 0s infinite globalKeyframes;
77+ }
78+
79+ @keyframes -global-globalKeyframes {
80+ 0% {
81+ opacity: 0;
82+ }
83+ 100% {
84+ opacity: 100%;
85+ }
86+ }
87+
88+ @keyframes localKeyframes {
89+ 0% {
90+ opacity: 0;
91+ }
92+ 100% {
93+ opacity: 100%;
94+ }
6795 }
6896 ` ,
6997 } ,
@@ -74,7 +102,13 @@ test(
74102 let files = await fs . glob ( 'dist/**/*.css' )
75103 expect ( files ) . toHaveLength ( 1 )
76104
77- await fs . expectFileToContain ( files [ 0 ] [ 0 ] , [ candidate `underline` , candidate `foo` ] )
105+ await fs . expectFileToContain ( files [ 0 ] [ 0 ] , [
106+ candidate `underline` ,
107+ '.global{color:var(--color-green-500);animation:2s ease-in-out 0s infinite globalKeyframes}' ,
108+ / \. l o c a l .s v e l t e - .* \{ c o l o r : v a r \( - - c o l o r - r e d - 5 0 0 \) ; a n i m a t i o n : 2 s e a s e - i n - o u t 0 s i n f i n i t e s v e l t e - .* - l o c a l K e y f r a m e s \} / ,
109+ / @ k e y f r a m e s g l o b a l K e y f r a m e s \{ / ,
110+ / @ k e y f r a m e s s v e l t e - .* - l o c a l K e y f r a m e s \{ / ,
111+ ] )
78112 } ,
79113)
80114
@@ -127,51 +161,94 @@ test(
127161 ` ,
128162 'src/App.svelte' : html `
129163 <script>
164+ import './index.css'
130165 let name = 'world'
131166 </script>
132167
133- <h1 class="foo underline">Hello {name}!</h1>
168+ <h1 class="local global underline">Hello {name}!</h1>
134169
135- <style global>
136- @import 'tailwindcss/utilities';
170+ <style>
137171 @import 'tailwindcss/theme' theme(reference);
138- @import './components .css';
172+ @import './other .css';
139173 </style>
140174 ` ,
141- 'src/components.css' : css `
142- .foo {
175+ 'src/index.css' : css `
176+ @import 'tailwindcss/theme' theme(reference);
177+ @import 'tailwindcss/utilities';
178+ ` ,
179+ 'src/other.css' : css `
180+ .local {
143181 @apply text-red-500;
182+ animation: 2s ease-in-out 0s infinite localKeyframes;
183+ }
184+
185+ :global(.global) {
186+ @apply text-green-500;
187+ animation: 2s ease-in-out 0s infinite globalKeyframes;
188+ }
189+
190+ @keyframes -global-globalKeyframes {
191+ 0% {
192+ opacity: 0;
193+ }
194+ 100% {
195+ opacity: 100%;
196+ }
197+ }
198+
199+ @keyframes localKeyframes {
200+ 0% {
201+ opacity: 0;
202+ }
203+ 100% {
204+ opacity: 100%;
205+ }
144206 }
145207 ` ,
146208 } ,
147209 } ,
148210 async ( { fs, spawn } ) => {
149211 await spawn ( `pnpm vite build --watch` )
150212
151- let filename = ''
152213 await retryAssertion ( async ( ) => {
153214 let files = await fs . glob ( 'dist/**/*.css' )
154215 expect ( files ) . toHaveLength ( 1 )
155- filename = files [ 0 ] [ 0 ]
216+ let [ , css ] = files [ 0 ]
217+ expect ( css ) . toContain ( candidate `underline` )
218+ expect ( css ) . toContain (
219+ '.global{color:var(--color-green-500);animation:2s ease-in-out 0s infinite globalKeyframes}' ,
220+ )
221+ expect ( css ) . toMatch (
222+ / \. l o c a l .s v e l t e - .* \{ c o l o r : v a r \( - - c o l o r - r e d - 5 0 0 \) ; a n i m a t i o n : 2 s e a s e - i n - o u t 0 s i n f i n i t e s v e l t e - .* - l o c a l K e y f r a m e s \} / ,
223+ )
224+ expect ( css ) . toMatch ( / @ k e y f r a m e s g l o b a l K e y f r a m e s \{ / )
225+ expect ( css ) . toMatch ( / @ k e y f r a m e s s v e l t e - .* - l o c a l K e y f r a m e s \{ / )
156226 } )
157227
158- await fs . expectFileToContain ( filename , [ candidate `foo` , candidate `underline` ] )
228+ await fs . write (
229+ 'src/App.svelte' ,
230+ ( await fs . read ( 'src/App.svelte' ) ) . replace ( 'underline' , 'font-bold bar' ) ,
231+ )
159232
160233 await fs . write (
161- 'src/components.css' ,
162- css `
163- .bar {
164- @apply text-green-500;
165- }
166- ` ,
234+ 'src/other.css' ,
235+ `${ await fs . read ( 'src/other.css' ) } \n.bar { @apply text-pink-500; }` ,
167236 )
237+
168238 await retryAssertion ( async ( ) => {
169239 let files = await fs . glob ( 'dist/**/*.css' )
170240 expect ( files ) . toHaveLength ( 1 )
171241 let [ , css ] = files [ 0 ]
172- expect ( css ) . toContain ( candidate `underline` )
173- expect ( css ) . toContain ( candidate `bar` )
174- expect ( css ) . not . toContain ( candidate `foo` )
242+ expect ( css ) . toContain ( candidate `font-bold` )
243+ expect ( css ) . toContain (
244+ '.global{color:var(--color-green-500);animation:2s ease-in-out 0s infinite globalKeyframes}' ,
245+ )
246+ expect ( css ) . toMatch (
247+ / \. l o c a l .s v e l t e - .* \{ c o l o r : v a r \( - - c o l o r - r e d - 5 0 0 \) ; a n i m a t i o n : 2 s e a s e - i n - o u t 0 s i n f i n i t e s v e l t e - .* - l o c a l K e y f r a m e s \} / ,
248+ )
249+ expect ( css ) . toMatch ( / @ k e y f r a m e s g l o b a l K e y f r a m e s \{ / )
250+ expect ( css ) . toMatch ( / @ k e y f r a m e s s v e l t e - .* - l o c a l K e y f r a m e s \{ / )
251+ expect ( css ) . toMatch ( / \. b a r .s v e l t e - .* \{ c o l o r : v a r \( - - c o l o r - p i n k - 5 0 0 \) \} / )
175252 } )
176253 } ,
177254)
0 commit comments