6
6
generateCSSCode ,
7
7
getCSSImport ,
8
8
getCSSVarsCode ,
9
- getCurSassFileContent ,
9
+ getCurFileContent ,
10
10
preProcessCSS ,
11
- setImportToSassCompileRes ,
11
+ setImportToCompileRes ,
12
12
walkCSSTree ,
13
13
} from '../pre-process-css'
14
14
import type { ImportStatement } from '../../parser/parser-import'
@@ -342,10 +342,31 @@ describe('pre process css', () => {
342
342
// test2.css -> test.css or test.scss ? -> test.css
343
343
const importerTest2CSS = res . get ( mockPathTest2CSS )
344
344
expect ( [ ...importerTest2CSS ! . importer ] [ 0 ] ) . toBe ( mockPathTestCSS )
345
- expect ( res ) . toMatchSnapshot ( )
346
345
} )
347
346
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' , ( ) => {
349
370
const mockSassContent = '@import "./test";\n'
350
371
+ '@use \'./test-use\';\n'
351
372
+ '#app {\n'
@@ -361,13 +382,13 @@ describe('pre process css', () => {
361
382
{ type : 'import' , path : '"./test"' , start : 8 , end : 16 } ,
362
383
{ type : 'use' , path : '\'./test-use\'' , start : 23 , end : 35 } ,
363
384
]
364
- const res = getCurSassFileContent ( mockSassContent , mockStatement as ImportStatement [ ] )
385
+ const res = getCurFileContent ( mockSassContent , mockStatement as ImportStatement [ ] )
365
386
expect ( res . includes ( 'import' ) ) . not . toBeTruthy ( )
366
387
expect ( res . includes ( 'use' ) ) . not . toBeTruthy ( )
367
388
expect ( res ) . toMatchSnapshot ( )
368
389
} )
369
390
370
- test ( 'getCurSassFileContent : no ; ' , ( ) => {
391
+ test ( 'getCurFileContent : no ; ' , ( ) => {
371
392
const mockSassContent = '@import "./test"\n'
372
393
+ '@use \'./test-use\'\n'
373
394
+ '#app {\n'
@@ -383,13 +404,13 @@ describe('pre process css', () => {
383
404
{ type : 'import' , path : '"./test"' , start : 8 , end : 16 } ,
384
405
{ type : 'use' , path : '\'./test-use\'' , start : 22 , end : 35 } ,
385
406
]
386
- const res = getCurSassFileContent ( mockSassContent , mockStatement as ImportStatement [ ] )
407
+ const res = getCurFileContent ( mockSassContent , mockStatement as ImportStatement [ ] )
387
408
expect ( res . includes ( '@import' ) ) . not . toBeTruthy ( )
388
409
expect ( res . includes ( '@use' ) ) . not . toBeTruthy ( )
389
410
expect ( res ) . toMatchSnapshot ( )
390
411
} )
391
412
392
- test ( 'getCurSassFileContent : no start and end ' , ( ) => {
413
+ test ( 'getCurFileContent : no start and end ' , ( ) => {
393
414
const mockSassContent = '@import "./test"\n'
394
415
+ '@use \'./test-use\'\n'
395
416
+ '#app {\n'
@@ -405,12 +426,12 @@ describe('pre process css', () => {
405
426
{ type : 'import' , path : '"./test"' } ,
406
427
{ type : 'use' , path : '\'./test-use\'' } ,
407
428
]
408
- const res = getCurSassFileContent ( mockSassContent , mockStatement as ImportStatement [ ] )
429
+ const res = getCurFileContent ( mockSassContent , mockStatement as ImportStatement [ ] )
409
430
expect ( res ) . toMatchObject ( mockSassContent )
410
431
expect ( res ) . toMatchSnapshot ( )
411
432
} )
412
433
413
- test ( 'setImportToSassCompileRes : basic' , ( ) => {
434
+ test ( 'setImportToCompileRes : basic' , ( ) => {
414
435
const mockSassContent = '#app {\n'
415
436
+ ' div {\n'
416
437
+ ' color: v-bind(fooColor);\n'
@@ -424,13 +445,13 @@ describe('pre process css', () => {
424
445
{ type : 'import' , path : '"./test"' } ,
425
446
{ type : 'use' , path : '\'./test-use\'' } ,
426
447
]
427
- const res = setImportToSassCompileRes ( mockSassContent , mockStatement as ImportStatement [ ] )
448
+ const res = setImportToCompileRes ( mockSassContent , mockStatement as ImportStatement [ ] )
428
449
expect ( res . includes ( '@import' ) ) . toBeTruthy ( )
429
450
expect ( res . includes ( '@use' ) ) . not . toBeTruthy ( )
430
451
expect ( res ) . toMatchSnapshot ( )
431
452
} )
432
453
433
- test ( 'setImportToSassCompileRes : @import' , ( ) => {
454
+ test ( 'setImportToCompileRes : @import' , ( ) => {
434
455
const mockSassContent = '#app {\n'
435
456
+ ' div {\n'
436
457
+ ' color: v-bind(fooColor);\n'
@@ -443,13 +464,13 @@ describe('pre process css', () => {
443
464
const mockStatement = [
444
465
{ type : 'import' , path : '"./test"' } ,
445
466
]
446
- const res = setImportToSassCompileRes ( mockSassContent , mockStatement as ImportStatement [ ] )
467
+ const res = setImportToCompileRes ( mockSassContent , mockStatement as ImportStatement [ ] )
447
468
expect ( res . includes ( '@import' ) ) . toBeTruthy ( )
448
469
expect ( res . includes ( '@use' ) ) . not . toBeTruthy ( )
449
470
expect ( res ) . toMatchSnapshot ( )
450
471
} )
451
472
452
- test ( 'setImportToSassCompileRes : @use' , ( ) => {
473
+ test ( 'setImportToCompileRes : @use' , ( ) => {
453
474
const mockSassContent = '#app {\n'
454
475
+ ' div {\n'
455
476
+ ' color: v-bind(fooColor);\n'
@@ -462,13 +483,13 @@ describe('pre process css', () => {
462
483
const mockStatement = [
463
484
{ type : 'use' , path : '"./test"' } ,
464
485
]
465
- const res = setImportToSassCompileRes ( mockSassContent , mockStatement as ImportStatement [ ] )
486
+ const res = setImportToCompileRes ( mockSassContent , mockStatement as ImportStatement [ ] )
466
487
expect ( res . includes ( '@import' ) ) . toBeTruthy ( )
467
488
expect ( res . includes ( '@use' ) ) . not . toBeTruthy ( )
468
489
expect ( res ) . toMatchSnapshot ( )
469
490
} )
470
491
471
- test ( 'setImportToSassCompileRes : no @use and @import' , ( ) => {
492
+ test ( 'setImportToCompileRes : no @use and @import' , ( ) => {
472
493
const mockSassContent = '#app {\n'
473
494
+ ' div {\n'
474
495
+ ' color: v-bind(fooColor);\n'
@@ -482,7 +503,7 @@ describe('pre process css', () => {
482
503
{ type : 'foo' , path : '"./test"' } ,
483
504
{ type : 'foo' , path : '"./test"' } ,
484
505
]
485
- const res = setImportToSassCompileRes ( mockSassContent , mockStatement as ImportStatement [ ] )
506
+ const res = setImportToCompileRes ( mockSassContent , mockStatement as ImportStatement [ ] )
486
507
expect ( res . includes ( '@import' ) ) . not . toBeTruthy ( )
487
508
expect ( res . includes ( '@use' ) ) . not . toBeTruthy ( )
488
509
expect ( res ) . toMatchObject ( mockSassContent )
@@ -511,4 +532,16 @@ describe('pre process css', () => {
511
532
expect ( res ) . toBe ( mockSassContent )
512
533
expect ( res ) . toMatchSnapshot ( )
513
534
} )
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
+ } )
514
547
} )
0 commit comments