@@ -10,7 +10,7 @@ function run(input, output, opts) {
1010 equal ( result . warnings ( ) . length , 0 )
1111}
1212
13- test ( 'replaces selectors' , ( ) => {
13+ test ( 'replaces selectors - dark scheme ' , ( ) => {
1414 run (
1515 `@media (prefers-color-scheme:dark) {
1616 html.is-a,
@@ -31,7 +31,65 @@ test('replaces selectors', () => {
3131 )
3232} )
3333
34- test ( 'disables :where() of request' , ( ) => {
34+ test ( 'replaces selectors - light scheme' , ( ) => {
35+ run (
36+ `@media (prefers-color-scheme:light) {
37+ html.is-a,
38+ html,
39+ :root,
40+ a { }
41+ }` ,
42+ `@media (prefers-color-scheme:light) {
43+ html:where(:not(.is-dark)).is-a,
44+ html:where(:not(.is-dark)),
45+ :root:where(:not(.is-dark)),
46+ :where(html:not(.is-dark)) a { }
47+ }
48+ html:where(.is-light).is-a,
49+ html:where(.is-light),
50+ :root:where(.is-light),
51+ :where(html.is-light) a { }`
52+ )
53+ } )
54+
55+ test ( 'replaces selectors - dark and light schemes' , ( ) => {
56+ run (
57+ `@media (prefers-color-scheme:dark) {
58+ html.is-a,
59+ html,
60+ :root,
61+ a { }
62+ }
63+ @media (prefers-color-scheme:light) {
64+ html.is-a,
65+ html,
66+ :root,
67+ a { }
68+ }` ,
69+ `@media (prefers-color-scheme:dark) {
70+ html:where(:not(.is-light)).is-a,
71+ html:where(:not(.is-light)),
72+ :root:where(:not(.is-light)),
73+ :where(html:not(.is-light)) a { }
74+ }
75+ html:where(.is-dark).is-a,
76+ html:where(.is-dark),
77+ :root:where(.is-dark),
78+ :where(html.is-dark) a { }
79+ @media (prefers-color-scheme:light) {
80+ html:where(:not(.is-dark)).is-a,
81+ html:where(:not(.is-dark)),
82+ :root:where(:not(.is-dark)),
83+ :where(html:not(.is-dark)) a { }
84+ }
85+ html:where(.is-light).is-a,
86+ html:where(.is-light),
87+ :root:where(.is-light),
88+ :where(html.is-light) a { }`
89+ )
90+ } )
91+
92+ test ( 'disables :where() of request - dark scheme' , ( ) => {
3593 run (
3694 `@media (prefers-color-scheme:dark) {
3795 html.is-a,
@@ -53,7 +111,29 @@ test('disables :where() of request', () => {
53111 )
54112} )
55113
56- test ( 'processes inner at-rules' , ( ) => {
114+ test ( 'disables :where() of request - light scheme' , ( ) => {
115+ run (
116+ `@media (prefers-color-scheme:light) {
117+ html.is-a,
118+ html,
119+ :root,
120+ a { }
121+ }` ,
122+ `@media (prefers-color-scheme:light) {
123+ html:not(.is-dark).is-a,
124+ html:not(.is-dark),
125+ :root:not(.is-dark),
126+ html:not(.is-dark) a { }
127+ }
128+ html.is-light.is-a,
129+ html.is-light,
130+ :root.is-light,
131+ html.is-light a { }` ,
132+ { useWhere : false }
133+ )
134+ } )
135+
136+ test ( 'processes inner at-rules - dark scheme' , ( ) => {
57137 run (
58138 `@media (prefers-color-scheme: dark) {
59139 @media (min-width: 500px) {
@@ -86,6 +166,39 @@ test('processes inner at-rules', () => {
86166 )
87167} )
88168
169+ test ( 'processes inner at-rules - light scheme' , ( ) => {
170+ run (
171+ `@media (prefers-color-scheme: light) {
172+ @media (min-width: 500px) {
173+ a { }
174+ }
175+ @media (min-width: 500px) {
176+ @media (print) {
177+ a { }
178+ }
179+ }
180+ }` ,
181+ `@media (prefers-color-scheme: light) {
182+ @media (min-width: 500px) {
183+ :where(html:not(.is-dark)) a { }
184+ }
185+ @media (min-width: 500px) {
186+ @media (print) {
187+ :where(html:not(.is-dark)) a { }
188+ }
189+ }
190+ }
191+ @media (min-width: 500px) {
192+ :where(html.is-light) a { }
193+ }
194+ @media (min-width: 500px) {
195+ @media (print) {
196+ :where(html.is-light) a { }
197+ }
198+ }`
199+ )
200+ } )
201+
89202test ( 'checks media params deeply' , ( ) => {
90203 run (
91204 `@media (x-dark: true) {
@@ -133,7 +246,7 @@ test('reserve comments', () => {
133246 )
134247} )
135248
136- test ( 'supports combined queries' , ( ) => {
249+ test ( 'supports combined queries - dark scheme ' , ( ) => {
137250 run (
138251 `@media (min-width: 60px) and (prefers-color-scheme: dark) {
139252 a { color: white }
@@ -146,7 +259,20 @@ test('supports combined queries', () => {
146259 )
147260} )
148261
149- test ( 'supports combined queries in the middle' , ( ) => {
262+ test ( 'supports combined queries - light scheme' , ( ) => {
263+ run (
264+ `@media (min-width: 60px) and (prefers-color-scheme: light) {
265+ a { color: white }
266+ }` ,
267+ `@media (min-width: 60px) and (prefers-color-scheme: light) {
268+ :where(html:not(.is-dark)) a { color: white }
269+ }@media (min-width: 60px) {
270+ :where(html.is-light) a { color: white }
271+ }`
272+ )
273+ } )
274+
275+ test ( 'supports combined queries in the middle - dark scheme' , ( ) => {
150276 run (
151277 `@media (width > 0) and (prefers-color-scheme: dark) and (width > 0) {
152278 a { color: white }
@@ -159,6 +285,19 @@ test('supports combined queries in the middle', () => {
159285 )
160286} )
161287
288+ test ( 'supports combined queries in the middle - light scheme' , ( ) => {
289+ run (
290+ `@media (width > 0) and (prefers-color-scheme: light) and (width > 0) {
291+ a { color: white }
292+ }` ,
293+ `@media (width > 0) and (prefers-color-scheme: light) and (width > 0) {
294+ :where(html:not(.is-dark)) a { color: white }
295+ }@media (width > 0) and (width > 0) {
296+ :where(html.is-light) a { color: white }
297+ }`
298+ )
299+ } )
300+
162301test ( 'allows to change class' , ( ) => {
163302 run (
164303 `@media (prefers-color-scheme: dark) {
@@ -212,7 +351,7 @@ test('changes root selector', () => {
212351 )
213352} )
214353
215- test ( 'ignores already transformed rules' , ( ) => {
354+ test ( 'ignores already transformed rules - dark scheme ' , ( ) => {
216355 run (
217356 `@media (prefers-color-scheme: dark) {
218357 :root:not(.is-light) { --bg: black }
@@ -228,4 +367,20 @@ test('ignores already transformed rules', () => {
228367 )
229368} )
230369
370+ test ( 'ignores already transformed rules - light scheme' , ( ) => {
371+ run (
372+ `@media (prefers-color-scheme: light) {
373+ :root:not(.is-dark) { --bg: black }
374+ p { color: white }
375+ }
376+ :root { --bg: white }` ,
377+ `@media (prefers-color-scheme: light) {
378+ :root:not(.is-dark) { --bg: black }
379+ :where(html:not(.is-dark)) p { color: white }
380+ }
381+ :where(html.is-light) p { color: white }
382+ :root { --bg: white }`
383+ )
384+ } )
385+
231386test . run ( )
0 commit comments