66 generateCSSCode ,
77 getCSSImport ,
88 getCSSVarsCode ,
9- getCurSassFileContent ,
9+ getCurFileContent ,
1010 preProcessCSS ,
11- setImportToSassCompileRes ,
11+ setImportToCompileRes ,
1212 walkCSSTree ,
1313} from '../pre-process-css'
1414import type { ImportStatement } from '../../parser/parser-import'
@@ -342,10 +342,31 @@ describe('pre process css', () => {
342342 // test2.css -> test.css or test.scss ? -> test.css
343343 const importerTest2CSS = res . get ( mockPathTest2CSS )
344344 expect ( [ ...importerTest2CSS ! . importer ] [ 0 ] ) . toBe ( mockPathTestCSS )
345- expect ( res ) . toMatchSnapshot ( )
346345 } )
347346
348- test ( 'getCurSassFileContent: basic' , ( ) => {
347+ test ( 'preProcessCSS: map path less -> css or less' , ( ) => {
348+ const res = preProcessCSS ( { rootDir : resolve ( 'packages' ) } )
349+ const mockPathFooLESS = transformSymbol ( `${ resolve ( ) } /core/css/__test__/foo.less` )
350+ const mockPathTestLESS = transformSymbol ( `${ resolve ( ) } /core/css/__test__/test.less` )
351+ const mockPathTest2CSS = transformSymbol ( `${ resolve ( ) } /core/css/__test__/test2.css` )
352+ // foo.less -> test.css or test.less ? -> test.less
353+ const importerFooLESS = res . get ( mockPathFooLESS )
354+ expect ( [ ...importerFooLESS ! . importer ] [ 0 ] ) . toBe ( mockPathTestLESS )
355+ // foo.less -> test.css or test.less ? -> test.less -> test2.css
356+ const importerTestLESS = res . get ( mockPathTestLESS )
357+ expect ( [ ...importerTestLESS ! . importer ] [ 0 ] ) . toBe ( mockPathTest2CSS )
358+
359+ // foo2.less -> test2.css
360+ const mockPathFoo2LESS = transformSymbol ( `${ resolve ( ) } /core/css/__test__/foo2.less` )
361+ const mockPathTestCSS = transformSymbol ( `${ resolve ( ) } /core/css/__test__/test.css` )
362+ const importerFoo2LESS = res . get ( mockPathFoo2LESS )
363+ expect ( [ ...importerFoo2LESS ! . importer ] [ 0 ] ) . toBe ( mockPathTest2CSS )
364+ // test2.css -> test.css or test.less ? -> test.css
365+ const importerTest2CSS = res . get ( mockPathTest2CSS )
366+ expect ( [ ...importerTest2CSS ! . importer ] [ 0 ] ) . toBe ( mockPathTestCSS )
367+ } )
368+
369+ test ( 'getCurFileContent: basic' , ( ) => {
349370 const mockSassContent = '@import "./test";\n'
350371 + '@use \'./test-use\';\n'
351372 + '#app {\n'
@@ -361,13 +382,13 @@ describe('pre process css', () => {
361382 { type : 'import' , path : '"./test"' , start : 8 , end : 16 } ,
362383 { type : 'use' , path : '\'./test-use\'' , start : 23 , end : 35 } ,
363384 ]
364- const res = getCurSassFileContent ( mockSassContent , mockStatement as ImportStatement [ ] )
385+ const res = getCurFileContent ( mockSassContent , mockStatement as ImportStatement [ ] )
365386 expect ( res . includes ( 'import' ) ) . not . toBeTruthy ( )
366387 expect ( res . includes ( 'use' ) ) . not . toBeTruthy ( )
367388 expect ( res ) . toMatchSnapshot ( )
368389 } )
369390
370- test ( 'getCurSassFileContent : no ; ' , ( ) => {
391+ test ( 'getCurFileContent : no ; ' , ( ) => {
371392 const mockSassContent = '@import "./test"\n'
372393 + '@use \'./test-use\'\n'
373394 + '#app {\n'
@@ -383,13 +404,13 @@ describe('pre process css', () => {
383404 { type : 'import' , path : '"./test"' , start : 8 , end : 16 } ,
384405 { type : 'use' , path : '\'./test-use\'' , start : 22 , end : 35 } ,
385406 ]
386- const res = getCurSassFileContent ( mockSassContent , mockStatement as ImportStatement [ ] )
407+ const res = getCurFileContent ( mockSassContent , mockStatement as ImportStatement [ ] )
387408 expect ( res . includes ( '@import' ) ) . not . toBeTruthy ( )
388409 expect ( res . includes ( '@use' ) ) . not . toBeTruthy ( )
389410 expect ( res ) . toMatchSnapshot ( )
390411 } )
391412
392- test ( 'getCurSassFileContent : no start and end ' , ( ) => {
413+ test ( 'getCurFileContent : no start and end ' , ( ) => {
393414 const mockSassContent = '@import "./test"\n'
394415 + '@use \'./test-use\'\n'
395416 + '#app {\n'
@@ -405,12 +426,12 @@ describe('pre process css', () => {
405426 { type : 'import' , path : '"./test"' } ,
406427 { type : 'use' , path : '\'./test-use\'' } ,
407428 ]
408- const res = getCurSassFileContent ( mockSassContent , mockStatement as ImportStatement [ ] )
429+ const res = getCurFileContent ( mockSassContent , mockStatement as ImportStatement [ ] )
409430 expect ( res ) . toMatchObject ( mockSassContent )
410431 expect ( res ) . toMatchSnapshot ( )
411432 } )
412433
413- test ( 'setImportToSassCompileRes : basic' , ( ) => {
434+ test ( 'setImportToCompileRes : basic' , ( ) => {
414435 const mockSassContent = '#app {\n'
415436 + ' div {\n'
416437 + ' color: v-bind(fooColor);\n'
@@ -424,13 +445,13 @@ describe('pre process css', () => {
424445 { type : 'import' , path : '"./test"' } ,
425446 { type : 'use' , path : '\'./test-use\'' } ,
426447 ]
427- const res = setImportToSassCompileRes ( mockSassContent , mockStatement as ImportStatement [ ] )
448+ const res = setImportToCompileRes ( mockSassContent , mockStatement as ImportStatement [ ] )
428449 expect ( res . includes ( '@import' ) ) . toBeTruthy ( )
429450 expect ( res . includes ( '@use' ) ) . not . toBeTruthy ( )
430451 expect ( res ) . toMatchSnapshot ( )
431452 } )
432453
433- test ( 'setImportToSassCompileRes : @import' , ( ) => {
454+ test ( 'setImportToCompileRes : @import' , ( ) => {
434455 const mockSassContent = '#app {\n'
435456 + ' div {\n'
436457 + ' color: v-bind(fooColor);\n'
@@ -443,13 +464,13 @@ describe('pre process css', () => {
443464 const mockStatement = [
444465 { type : 'import' , path : '"./test"' } ,
445466 ]
446- const res = setImportToSassCompileRes ( mockSassContent , mockStatement as ImportStatement [ ] )
467+ const res = setImportToCompileRes ( mockSassContent , mockStatement as ImportStatement [ ] )
447468 expect ( res . includes ( '@import' ) ) . toBeTruthy ( )
448469 expect ( res . includes ( '@use' ) ) . not . toBeTruthy ( )
449470 expect ( res ) . toMatchSnapshot ( )
450471 } )
451472
452- test ( 'setImportToSassCompileRes : @use' , ( ) => {
473+ test ( 'setImportToCompileRes : @use' , ( ) => {
453474 const mockSassContent = '#app {\n'
454475 + ' div {\n'
455476 + ' color: v-bind(fooColor);\n'
@@ -462,13 +483,13 @@ describe('pre process css', () => {
462483 const mockStatement = [
463484 { type : 'use' , path : '"./test"' } ,
464485 ]
465- const res = setImportToSassCompileRes ( mockSassContent , mockStatement as ImportStatement [ ] )
486+ const res = setImportToCompileRes ( mockSassContent , mockStatement as ImportStatement [ ] )
466487 expect ( res . includes ( '@import' ) ) . toBeTruthy ( )
467488 expect ( res . includes ( '@use' ) ) . not . toBeTruthy ( )
468489 expect ( res ) . toMatchSnapshot ( )
469490 } )
470491
471- test ( 'setImportToSassCompileRes : no @use and @import' , ( ) => {
492+ test ( 'setImportToCompileRes : no @use and @import' , ( ) => {
472493 const mockSassContent = '#app {\n'
473494 + ' div {\n'
474495 + ' color: v-bind(fooColor);\n'
@@ -482,7 +503,7 @@ describe('pre process css', () => {
482503 { type : 'foo' , path : '"./test"' } ,
483504 { type : 'foo' , path : '"./test"' } ,
484505 ]
485- const res = setImportToSassCompileRes ( mockSassContent , mockStatement as ImportStatement [ ] )
506+ const res = setImportToCompileRes ( mockSassContent , mockStatement as ImportStatement [ ] )
486507 expect ( res . includes ( '@import' ) ) . not . toBeTruthy ( )
487508 expect ( res . includes ( '@use' ) ) . not . toBeTruthy ( )
488509 expect ( res ) . toMatchObject ( mockSassContent )
@@ -511,4 +532,16 @@ describe('pre process css', () => {
511532 expect ( res ) . toBe ( mockSassContent )
512533 expect ( res ) . toMatchSnapshot ( )
513534 } )
535+
536+ test ( 'generateCSSCode: get less code' , ( ) => {
537+ const mockSassContent = '@import "./test";\n'
538+ + '#app div {\n'
539+ + ' color: v-bind(fooColor);\n'
540+ + '}'
541+ + '\n'
542+ const mockPath = `${ resolve ( 'packages' ) } /core/css/__test__/foo.less`
543+ const res = generateCSSCode ( mockPath , '.less' )
544+ expect ( res ) . toBe ( mockSassContent )
545+ expect ( res ) . toMatchSnapshot ( )
546+ } )
514547} )
0 commit comments