@@ -3,7 +3,7 @@ import { composeVisitors, transform } from 'lightningcss'
33import pxtorem from '../dist/index'
44
55describe ( 'pxtorem plugin' , ( ) => {
6- it ( 'should convert px to rem' , ( ) => {
6+ it ( 'should convert pixel to rem' , ( ) => {
77 const css = 'div { margin: 16px; }'
88
99 const output = transform ( {
@@ -38,7 +38,7 @@ describe('pxtorem plugin', () => {
3838 expect ( output ) . toMatchSnapshot ( )
3939 } )
4040
41- it ( 'should convert px to rem in media queries' , ( ) => {
41+ it ( 'should convert pixel to rem in media queries' , ( ) => {
4242 const css = '@media (min-width: 768px) { div { margin: 16px; } }'
4343
4444 const output = transform ( {
@@ -52,7 +52,7 @@ describe('pxtorem plugin', () => {
5252 expect ( output ) . toMatchSnapshot ( )
5353 } )
5454
55- it ( 'should convert px to rem in keyframes' , ( ) => {
55+ it ( 'should convert pixel to rem in keyframes' , ( ) => {
5656 const css = '@keyframes fadeIn { from { margin: 16px; } to { margin: 32px; } }'
5757
5858 const output = transform ( {
@@ -66,7 +66,7 @@ describe('pxtorem plugin', () => {
6666 expect ( output ) . toMatchSnapshot ( )
6767 } )
6868
69- it ( 'should convert px to rem in custom properties' , ( ) => {
69+ it ( 'should convert pixel to rem in custom properties' , ( ) => {
7070 const css = ':root { --margin: 16px; } div { margin: var(--margin); }'
7171
7272 const output = transform ( {
@@ -79,4 +79,74 @@ describe('pxtorem plugin', () => {
7979
8080 expect ( output ) . toMatchSnapshot ( )
8181 } )
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+ } )
82152} )
0 commit comments