@@ -2,6 +2,9 @@ import { resolve } from 'path'
22import { describe , expect , test , vi } from 'vitest'
33import * as csstree from 'css-tree'
44import { transformSymbol } from '@unplugin-vue-cssvars/utils'
5+ import less from 'less'
6+ import sass from 'sass'
7+ import stylus from 'stylus'
58import {
69 generateCSSCode ,
710 getCSSVarsCode ,
@@ -182,7 +185,13 @@ describe('pre process css', () => {
182185 } )
183186
184187 test ( 'preProcessCSS: basic' , ( ) => {
185- const res = preProcessCSS ( { rootDir : resolve ( 'packages' ) } )
188+ const res = preProcessCSS (
189+ {
190+ rootDir : resolve ( 'packages' ) ,
191+ preprocessor : { } ,
192+ includeCompile : [ '**/**.css' ] ,
193+ } ,
194+ )
186195 const mockPathTest1 = transformSymbol ( `${ resolve ( ) } /core/runtime/__test__/style/test.css` )
187196 const mockPathTest2 = transformSymbol ( `${ resolve ( ) } /core/runtime/__test__/style/test2.css` )
188197 const resTest1 = res . get ( mockPathTest1 )
@@ -200,7 +209,13 @@ describe('pre process css', () => {
200209 } )
201210
202211 test ( 'preProcessCSS: map path scss -> css or scss' , ( ) => {
203- const res = preProcessCSS ( { rootDir : resolve ( 'packages' ) } )
212+ const res = preProcessCSS (
213+ {
214+ rootDir : resolve ( 'packages' ) ,
215+ preprocessor : { sass } ,
216+ includeCompile : [ '**/**.css' , '**/**.scss' ] ,
217+ } ,
218+ )
204219 const mockPathFooSCSS = transformSymbol ( `${ resolve ( ) } /core/runtime/__test__/style/foo.scss` )
205220 const mockPathTestSCSS = transformSymbol ( `${ resolve ( ) } /core/runtime/__test__/style/test.scss` )
206221 const mockPathTest2CSS = transformSymbol ( `${ resolve ( ) } /core/runtime/__test__/style/test2.css` )
@@ -222,7 +237,13 @@ describe('pre process css', () => {
222237 } )
223238
224239 test ( 'preProcessCSS: map path less -> css or less' , ( ) => {
225- const res = preProcessCSS ( { rootDir : resolve ( 'packages' ) } )
240+ const res = preProcessCSS (
241+ {
242+ rootDir : resolve ( 'packages' ) ,
243+ preprocessor : { less } ,
244+ includeCompile : [ '**/**.css' , '**/**.less' ] ,
245+ } ,
246+ )
226247 const mockPathFooLESS = transformSymbol ( `${ resolve ( ) } /core/runtime/__test__/style/foo.less` )
227248 const mockPathTestLESS = transformSymbol ( `${ resolve ( ) } /core/runtime/__test__/style/test.less` )
228249 const mockPathTest2CSS = transformSymbol ( `${ resolve ( ) } /core/runtime/__test__/style/test2.css` )
@@ -244,7 +265,13 @@ describe('pre process css', () => {
244265 } )
245266
246267 test ( 'preProcessCSS: map path styl -> css or styl' , ( ) => {
247- const res = preProcessCSS ( { rootDir : resolve ( 'packages' ) } )
268+ const res = preProcessCSS (
269+ {
270+ rootDir : resolve ( 'packages' ) ,
271+ preprocessor : { stylus } ,
272+ includeCompile : [ '**/**.css' , '**/**.styl' ] ,
273+ } ,
274+ )
248275 const mockPathFooSTYL = transformSymbol ( `${ resolve ( ) } /core/runtime/__test__/style/foo.styl` )
249276 const mockPathTestSTYL = transformSymbol ( `${ resolve ( ) } /core/runtime/__test__/style/test.styl` )
250277 const mockPathTest2CSS = transformSymbol ( `${ resolve ( ) } /core/runtime/__test__/style/test2.css` )
@@ -266,7 +293,11 @@ describe('pre process css', () => {
266293 } )
267294
268295 test ( 'preProcessCSS: map path sass -> css or sass' , ( ) => {
269- const res = preProcessCSS ( { rootDir : resolve ( 'packages' ) } )
296+ const res = preProcessCSS ( {
297+ rootDir : resolve ( 'packages' ) ,
298+ preprocessor : { sass } ,
299+ includeCompile : [ '**/**.css' , '**/**.sass' ] ,
300+ } )
270301 const mockPathFooSASS = transformSymbol ( `${ resolve ( ) } /core/runtime/__test__/style/foo.sass` )
271302 const mockPathTestSASS = transformSymbol ( `${ resolve ( ) } /core/runtime/__test__/style/test.sass` )
272303 const mockPathTest2CSS = transformSymbol ( `${ resolve ( ) } /core/runtime/__test__/style/test2.css` )
@@ -468,7 +499,7 @@ describe('pre process css', () => {
468499 + ' color: v-bind(appTheme2);\n'
469500 + '}'
470501
471- const res = generateCSSCode ( mockCSSRes , '.css' )
502+ const res = generateCSSCode ( mockCSSRes , '.css' , { } )
472503 expect ( delTransformSymbol ( res ) ) . toBe ( delTransformSymbol ( mockCSSRes ) )
473504 expect ( delTransformSymbol ( res ) ) . toMatchSnapshot ( )
474505 } )
@@ -477,7 +508,7 @@ describe('pre process css', () => {
477508 const mockSassContent = '#app div { color: v-bind(appTheme2);}'
478509
479510 const mockCSSRes = '#app div { color: v-bind(appTheme2);}'
480- const res = generateCSSCode ( mockSassContent , '.scss' )
511+ const res = generateCSSCode ( mockSassContent , '.scss' , { sass } )
481512
482513 expect ( delTransformSymbol ( res ) ) . toBe ( delTransformSymbol ( mockCSSRes ) )
483514 expect ( delTransformSymbol ( res ) ) . toMatchSnapshot ( )
@@ -491,7 +522,7 @@ describe('pre process css', () => {
491522 + '}'
492523
493524 const mockCSSRes = '#app div { color: v-bind(appTheme2);}'
494- const res = generateCSSCode ( mockLessContent , '.less' )
525+ const res = generateCSSCode ( mockLessContent , '.less' , { less } )
495526
496527 expect ( delTransformSymbol ( res ) ) . toBe ( delTransformSymbol ( mockCSSRes ) )
497528 expect ( delTransformSymbol ( res ) ) . toMatchSnapshot ( )
@@ -503,7 +534,19 @@ describe('pre process css', () => {
503534 + ' color: v-bind(appTheme2);'
504535
505536 const mockCSSRes = '#app div { color: v-bind(appTheme2);}'
506- const res = generateCSSCode ( mockStylContent , '.styl' )
537+ const res = generateCSSCode ( mockStylContent , '.styl' , { stylus } )
538+
539+ expect ( delTransformSymbol ( res ) ) . toBe ( delTransformSymbol ( mockCSSRes ) )
540+ expect ( delTransformSymbol ( res ) ) . toMatchSnapshot ( )
541+ } )
542+
543+ test ( 'generateCSSCode: get sass code' , ( ) => {
544+ const mockStylContent = '#app\n'
545+ + ' div\n'
546+ + ' color: v-bind(appTheme2)'
547+
548+ const mockCSSRes = '#app div { color: v-bind(appTheme2);}'
549+ const res = generateCSSCode ( mockStylContent , '.sass' , { sass } )
507550
508551 expect ( delTransformSymbol ( res ) ) . toBe ( delTransformSymbol ( mockCSSRes ) )
509552 expect ( delTransformSymbol ( res ) ) . toMatchSnapshot ( )
0 commit comments