@@ -367,9 +367,32 @@ describe('pre process css', () => {
367367 expect ( [ ...importerTest2CSS ! . importer ] [ 0 ] ) . toBe ( mockPathTestCSS )
368368 } )
369369
370+ test ( 'preProcessCSS: map path styl -> css or styl' , ( ) => {
371+ const res = preProcessCSS ( { rootDir : resolve ( 'packages' ) } )
372+ const mockPathFooSTYL = transformSymbol ( `${ resolve ( ) } /core/css/__test__/foo.styl` )
373+ const mockPathTestSTYL = transformSymbol ( `${ resolve ( ) } /core/css/__test__/test.styl` )
374+ const mockPathTest2CSS = transformSymbol ( `${ resolve ( ) } /core/css/__test__/test2.css` )
375+ // foo.styl -> test.css or test.styl ? -> test.styl
376+ const importerFooSTYL = res . get ( mockPathFooSTYL )
377+ expect ( [ ...importerFooSTYL ! . importer ] [ 0 ] ) . toBe ( mockPathTestSTYL )
378+ // foo.styl -> test.css or test.styl ? -> test.styl -> test2.css
379+ const importerTestSTYL = res . get ( mockPathTestSTYL )
380+ expect ( [ ...importerTestSTYL ! . importer ] [ 0 ] ) . toBe ( mockPathTest2CSS )
381+
382+ // foo2.styl -> test2.css
383+ const mockPathFoo2STYL = transformSymbol ( `${ resolve ( ) } /core/css/__test__/foo2.styl` )
384+ const mockPathTestCSS = transformSymbol ( `${ resolve ( ) } /core/css/__test__/test.css` )
385+ const importerFoo2STYL = res . get ( mockPathFoo2STYL )
386+ expect ( [ ...importerFoo2STYL ! . importer ] [ 0 ] ) . toBe ( mockPathTest2CSS )
387+ // test2.css -> test.css or test.styl ? -> test.css
388+ const importerTest2CSS = res . get ( mockPathTest2CSS )
389+ expect ( [ ...importerTest2CSS ! . importer ] [ 0 ] ) . toBe ( mockPathTestCSS )
390+ } )
391+
370392 test ( 'getCurFileContent: basic' , ( ) => {
371393 const mockSassContent = '@import "./test";\n'
372394 + '@use \'./test-use\';\n'
395+ + '@require \'./test-require\';\n'
373396 + '#app {\n'
374397 + ' div {\n'
375398 + ' color: v-bind(fooColor);\n'
@@ -382,16 +405,19 @@ describe('pre process css', () => {
382405 const mockStatement = [
383406 { type : 'import' , path : '"./test"' , start : 8 , end : 16 } ,
384407 { type : 'use' , path : '\'./test-use\'' , start : 23 , end : 35 } ,
408+ { type : 'require' , path : '\'./test-require\'' , start : 46 , end : 62 } ,
385409 ]
386410 const res = getCurFileContent ( mockSassContent , mockStatement as ImportStatement [ ] )
387411 expect ( res . includes ( 'import' ) ) . not . toBeTruthy ( )
388412 expect ( res . includes ( 'use' ) ) . not . toBeTruthy ( )
413+ expect ( res . includes ( 'require' ) ) . not . toBeTruthy ( )
389414 expect ( res ) . toMatchSnapshot ( )
390415 } )
391416
392417 test ( 'getCurFileContent: no ; ' , ( ) => {
393418 const mockSassContent = '@import "./test"\n'
394419 + '@use \'./test-use\'\n'
420+ + '@require \'./test-require\'\n'
395421 + '#app {\n'
396422 + ' div {\n'
397423 + ' color: v-bind(fooColor);\n'
@@ -404,16 +430,19 @@ describe('pre process css', () => {
404430 const mockStatement = [
405431 { type : 'import' , path : '"./test"' , start : 8 , end : 16 } ,
406432 { type : 'use' , path : '\'./test-use\'' , start : 22 , end : 35 } ,
433+ { type : 'require' , path : '\'./test-require\'' , start : 44 , end : 60 } ,
407434 ]
408435 const res = getCurFileContent ( mockSassContent , mockStatement as ImportStatement [ ] )
409436 expect ( res . includes ( '@import' ) ) . not . toBeTruthy ( )
410437 expect ( res . includes ( '@use' ) ) . not . toBeTruthy ( )
438+ expect ( res . includes ( '@require' ) ) . not . toBeTruthy ( )
411439 expect ( res ) . toMatchSnapshot ( )
412440 } )
413441
414442 test ( 'getCurFileContent: no start and end ' , ( ) => {
415443 const mockSassContent = '@import "./test"\n'
416444 + '@use \'./test-use\'\n'
445+ + '@require \'./test-require\'\n'
417446 + '#app {\n'
418447 + ' div {\n'
419448 + ' color: v-bind(fooColor);\n'
@@ -426,6 +455,7 @@ describe('pre process css', () => {
426455 const mockStatement = [
427456 { type : 'import' , path : '"./test"' } ,
428457 { type : 'use' , path : '\'./test-use\'' } ,
458+ { type : 'require' , path : '\'./test-require\'' } ,
429459 ]
430460 const res = getCurFileContent ( mockSassContent , mockStatement as ImportStatement [ ] )
431461 expect ( res ) . toMatchObject ( mockSassContent )
@@ -468,6 +498,7 @@ describe('pre process css', () => {
468498 const res = setImportToCompileRes ( mockSassContent , mockStatement as ImportStatement [ ] )
469499 expect ( res . includes ( '@import' ) ) . toBeTruthy ( )
470500 expect ( res . includes ( '@use' ) ) . not . toBeTruthy ( )
501+ expect ( res . includes ( '@require' ) ) . not . toBeTruthy ( )
471502 expect ( res ) . toMatchSnapshot ( )
472503 } )
473504
@@ -487,10 +518,11 @@ describe('pre process css', () => {
487518 const res = setImportToCompileRes ( mockSassContent , mockStatement as ImportStatement [ ] )
488519 expect ( res . includes ( '@import' ) ) . toBeTruthy ( )
489520 expect ( res . includes ( '@use' ) ) . not . toBeTruthy ( )
521+ expect ( res . includes ( '@require' ) ) . not . toBeTruthy ( )
490522 expect ( res ) . toMatchSnapshot ( )
491523 } )
492524
493- test ( 'setImportToCompileRes: no @use and @import ' , ( ) => {
525+ test ( 'setImportToCompileRes: @require ' , ( ) => {
494526 const mockSassContent = '#app {\n'
495527 + ' div {\n'
496528 + ' color: v-bind(fooColor);\n'
@@ -501,12 +533,34 @@ describe('pre process css', () => {
501533 + '}'
502534
503535 const mockStatement = [
536+ { type : 'require' , path : '"./test"' } ,
537+ ]
538+ const res = setImportToCompileRes ( mockSassContent , mockStatement as ImportStatement [ ] )
539+ expect ( res . includes ( '@import' ) ) . toBeTruthy ( )
540+ expect ( res . includes ( '@use' ) ) . not . toBeTruthy ( )
541+ expect ( res . includes ( '@require' ) ) . not . toBeTruthy ( )
542+ expect ( res ) . toMatchSnapshot ( )
543+ } )
544+
545+ test ( 'setImportToCompileRes: no @use and @import and @require' , ( ) => {
546+ const mockSassContent = '#app {\n'
547+ + ' div {\n'
548+ + ' color: v-bind(fooColor);\n'
549+ + ' }\n'
550+ + ' .foo {\n'
551+ + ' color: red\n'
552+ + ' }\n'
553+ + '}'
554+
555+ const mockStatement = [
556+ { type : 'foo' , path : '"./test"' } ,
504557 { type : 'foo' , path : '"./test"' } ,
505558 { type : 'foo' , path : '"./test"' } ,
506559 ]
507560 const res = setImportToCompileRes ( mockSassContent , mockStatement as ImportStatement [ ] )
508561 expect ( res . includes ( '@import' ) ) . not . toBeTruthy ( )
509562 expect ( res . includes ( '@use' ) ) . not . toBeTruthy ( )
563+ expect ( res . includes ( '@require' ) ) . not . toBeTruthy ( )
510564 expect ( res ) . toMatchObject ( mockSassContent )
511565 expect ( res ) . toMatchSnapshot ( )
512566 } )
@@ -535,14 +589,26 @@ describe('pre process css', () => {
535589 } )
536590
537591 test ( 'generateCSSCode: get less code' , ( ) => {
538- const mockSassContent = '@import "./test";\n'
592+ const mockLessContent = '@import "./test";\n'
539593 + '#app div {\n'
540594 + ' color: v-bind(fooColor);\n'
541595 + '}'
542596 + '\n'
543597 const mockPath = `${ resolve ( 'packages' ) } /core/css/__test__/foo.less`
544598 const res = generateCSSCode ( mockPath , '.less' )
545- expect ( delTransformSymbol ( res ) ) . toBe ( delTransformSymbol ( mockSassContent ) )
599+ expect ( delTransformSymbol ( res ) ) . toBe ( delTransformSymbol ( mockLessContent ) )
600+ expect ( delTransformSymbol ( res ) ) . toMatchSnapshot ( )
601+ } )
602+
603+ test ( 'generateCSSCode: get styl code' , ( ) => {
604+ const mockStylContent = '@import "./test";\n'
605+ + '#app div {\n'
606+ + ' color: v-bind(stylColor);\n'
607+ + '}'
608+ + '\n'
609+ const mockPath = `${ resolve ( 'packages' ) } /core/css/__test__/foo.styl`
610+ const res = generateCSSCode ( mockPath , '.styl' )
611+ expect ( delTransformSymbol ( res ) ) . toBe ( delTransformSymbol ( mockStylContent ) )
546612 expect ( delTransformSymbol ( res ) ) . toMatchSnapshot ( )
547613 } )
548614} )
0 commit comments