@@ -3,14 +3,18 @@ package transformer_test
3
3
import (
4
4
"testing"
5
5
6
+ "github.com/stephen/cssc/internal/ast"
6
7
"github.com/stephen/cssc/internal/parser"
8
+ "github.com/stephen/cssc/internal/printer"
7
9
"github.com/stephen/cssc/internal/sources"
8
10
"github.com/stephen/cssc/internal/transformer"
9
11
"github.com/stephen/cssc/transforms"
10
12
"github.com/stretchr/testify/assert"
13
+ "github.com/stretchr/testify/require"
11
14
)
12
15
13
16
func TestCustomMedia (t * testing.T ) {
17
+
14
18
assert .Equal (t , "@media (max-width:30em){.a{color:green}}@media (max-width:30em) and (script){.c{color:red}}" , Transform (t , func (o * transformer.Options ) {
15
19
o .CustomMediaQueries = transforms .CustomMediaQueriesTransform
16
20
}, `
@@ -55,3 +59,41 @@ func TestCustomMedia_Passthrough(t *testing.T) {
55
59
.c { color: red; }
56
60
}` ))
57
61
}
62
+
63
+ func TestCustomMediaViaImport (t * testing.T ) {
64
+ mainSource := & sources.Source {
65
+ Path : "main.css" ,
66
+ Content : `
67
+ @import "other.css";
68
+
69
+ @media (--narrow-window) {
70
+ .a { color: green; }
71
+ }
72
+
73
+ @media (--narrow-window) and (script) {
74
+ .c { color: red; }
75
+ }` ,
76
+ }
77
+ main , err := parser .Parse (mainSource )
78
+ other , err := parser .Parse (& sources.Source {
79
+ Path : "other.css" ,
80
+ Content : `@custom-media --narrow-window (max-width: 30em);` ,
81
+ })
82
+
83
+ require .NoError (t , err )
84
+ o := & transformer.Options {
85
+ OriginalSource : mainSource ,
86
+ Reporter : & reporter {},
87
+ ImportReplacements : map [* ast.AtRule ]* ast.Stylesheet {
88
+ main .Imports [0 ].AtRule : other ,
89
+ },
90
+ Options : transforms.Options {
91
+ CustomMediaQueries : transforms .CustomMediaQueriesTransform ,
92
+ },
93
+ }
94
+
95
+ out , err := printer .Print (transformer .Transform (main , * o ), printer.Options {})
96
+ assert .NoError (t , err )
97
+
98
+ assert .Equal (t , "@media (max-width:30em){.a{color:green}}@media (max-width:30em) and (script){.c{color:red}}" , out )
99
+ }
0 commit comments