@@ -3,7 +3,7 @@ import { composeVisitors, transform } from 'lightningcss'
3
3
import pxtorem from '../dist/index'
4
4
5
5
describe ( 'pxtorem plugin' , ( ) => {
6
- it ( 'should convert px to rem' , ( ) => {
6
+ it ( 'should convert pixel to rem' , ( ) => {
7
7
const css = 'div { margin: 16px; }'
8
8
9
9
const output = transform ( {
@@ -38,7 +38,7 @@ describe('pxtorem plugin', () => {
38
38
expect ( output ) . toMatchSnapshot ( )
39
39
} )
40
40
41
- it ( 'should convert px to rem in media queries' , ( ) => {
41
+ it ( 'should convert pixel to rem in media queries' , ( ) => {
42
42
const css = '@media (min-width: 768px) { div { margin: 16px; } }'
43
43
44
44
const output = transform ( {
@@ -52,7 +52,7 @@ describe('pxtorem plugin', () => {
52
52
expect ( output ) . toMatchSnapshot ( )
53
53
} )
54
54
55
- it ( 'should convert px to rem in keyframes' , ( ) => {
55
+ it ( 'should convert pixel to rem in keyframes' , ( ) => {
56
56
const css = '@keyframes fadeIn { from { margin: 16px; } to { margin: 32px; } }'
57
57
58
58
const output = transform ( {
@@ -66,7 +66,7 @@ describe('pxtorem plugin', () => {
66
66
expect ( output ) . toMatchSnapshot ( )
67
67
} )
68
68
69
- it ( 'should convert px to rem in custom properties' , ( ) => {
69
+ it ( 'should convert pixel to rem in custom properties' , ( ) => {
70
70
const css = ':root { --margin: 16px; } div { margin: var(--margin); }'
71
71
72
72
const output = transform ( {
@@ -79,4 +79,74 @@ describe('pxtorem plugin', () => {
79
79
80
80
expect ( output ) . toMatchSnapshot ( )
81
81
} )
82
+
83
+ it ( 'should handle multiple pixel values' , ( ) => {
84
+ const css = 'div { margin: 16px 32px; }'
85
+
86
+ const output = transform ( {
87
+ filename : 'input.css' ,
88
+ code : Buffer . from ( css ) ,
89
+ minify : true ,
90
+ sourceMap : false ,
91
+ visitor : composeVisitors ( [ pxtorem ( ) ] )
92
+ } ) . code . toString ( )
93
+
94
+ expect ( output ) . toMatchSnapshot ( )
95
+ } )
96
+
97
+ it ( 'should handle nested selectors' , ( ) => {
98
+ const css = 'div { & > span { margin: 16px; } }'
99
+
100
+ const output = transform ( {
101
+ filename : 'input.css' ,
102
+ code : Buffer . from ( css ) ,
103
+ minify : true ,
104
+ sourceMap : false ,
105
+ visitor : composeVisitors ( [ pxtorem ( ) ] )
106
+ } ) . code . toString ( )
107
+
108
+ expect ( output ) . toMatchSnapshot ( )
109
+ } )
110
+
111
+ it ( 'should handle float pixel units' , ( ) => {
112
+ const css = 'div { margin: 43.3398589px; }'
113
+
114
+ const output = transform ( {
115
+ filename : 'input.css' ,
116
+ code : Buffer . from ( css ) ,
117
+ minify : true ,
118
+ sourceMap : false ,
119
+ visitor : composeVisitors ( [ pxtorem ( ) ] )
120
+ } ) . code . toString ( )
121
+
122
+ expect ( output ) . toMatchSnapshot ( )
123
+ } )
124
+
125
+ it ( 'should handle custom configuration' , ( ) => {
126
+ const css = 'div { margin: 16px; }'
127
+
128
+ const output = transform ( {
129
+ filename : 'input.css' ,
130
+ code : Buffer . from ( css ) ,
131
+ minify : true ,
132
+ sourceMap : false ,
133
+ visitor : composeVisitors ( [ pxtorem ( { rootValue : 8 , unitPrecision : 2 } ) ] )
134
+ } ) . code . toString ( )
135
+
136
+ expect ( output ) . toMatchSnapshot ( )
137
+ } )
138
+
139
+ it ( 'should handle custom configuration with unitPrecision' , ( ) => {
140
+ const css = 'div { margin: 43.3398589px; }'
141
+
142
+ const output = transform ( {
143
+ filename : 'input.css' ,
144
+ code : Buffer . from ( css ) ,
145
+ minify : true ,
146
+ sourceMap : false ,
147
+ visitor : composeVisitors ( [ pxtorem ( { unitPrecision : 2 } ) ] )
148
+ } ) . code . toString ( )
149
+
150
+ expect ( output ) . toMatchSnapshot ( )
151
+ } )
82
152
} )
0 commit comments