@@ -379,34 +379,68 @@ describe('vue-loader', function () {
379
379
} )
380
380
} )
381
381
382
- it . only ( 'css-modules' , function ( done ) {
382
+ it ( 'css-modules' , function ( done ) {
383
+ function testWithIdent ( localIdentName , regexToMatch , cb ) {
384
+ test ( {
385
+ entry : './test/fixtures/css-modules.vue' ,
386
+ vue : {
387
+ cssModules : {
388
+ localIdentName : localIdentName
389
+ }
390
+ }
391
+ } , function ( window ) {
392
+ var module = window . vueModule
393
+
394
+ // get local class name
395
+ var className = module . computed . style ( ) . red
396
+ expect ( className ) . to . match ( regexToMatch )
397
+
398
+ // class name in style
399
+ var style = [ ] . slice . call ( window . document . querySelectorAll ( 'style' ) ) . map ( function ( style ) {
400
+ return style . textContent
401
+ } ) . join ( '\n' )
402
+ expect ( style ) . to . contain ( '.' + className + ' {\n color: red;\n}' )
403
+
404
+ // animation name
405
+ var match = style . match ( / @ k e y f r a m e s \s + ( \S + ) \s + { / )
406
+ expect ( match ) . to . have . length ( 2 )
407
+ var animationName = match [ 1 ]
408
+ expect ( animationName ) . to . not . equal ( 'fade' )
409
+ expect ( style ) . to . contain ( 'animation: ' + animationName + ' 1s;' )
410
+
411
+ // default module + pre-processor + scoped
412
+ var anotherClassName = module . computed . $style ( ) . red
413
+ expect ( anotherClassName ) . to . match ( regexToMatch ) . and . not . equal ( className )
414
+ var id = 'data-v-' + genId ( require . resolve ( './fixtures/css-modules.vue' ) )
415
+ expect ( style ) . to . contain ( '.' + anotherClassName + '[' + id + ']' )
416
+
417
+ cb ( )
418
+ } )
419
+ }
420
+ // default localIdentName
421
+ testWithIdent ( undefined , / ^ _ \w { 22 } / , function ( ) {
422
+ // specified localIdentName
423
+ var ident = '[path][name]---[local]---[hash:base64:5]'
424
+ var regex = / ^ t e s t - f i x t u r e s - c s s - m o d u l e s - - - r e d - - - \w { 5 } /
425
+ testWithIdent ( ident , regex , done )
426
+ } )
427
+ } )
428
+
429
+ it . only ( 'css-modules in SSR' , function ( done ) {
383
430
test ( {
384
- entry : './test/fixtures/css-modules.vue'
431
+ entry : './test/fixtures/css-modules.vue' ,
432
+ vue : {
433
+ target : 'node'
434
+ }
385
435
} , function ( window ) {
386
436
var module = window . vueModule
387
437
388
- // get local class name
438
+ // class name
389
439
var className = module . computed . style ( ) . red
390
440
expect ( className ) . to . match ( / ^ _ / )
391
441
392
- // class name in style
393
- var style = [ ] . slice . call ( window . document . querySelectorAll ( 'style' ) ) . map ( function ( style ) {
394
- return style . textContent
395
- } ) . join ( '\n' )
396
- expect ( style ) . to . contain ( '.' + className + ' {\n color: red;\n}' )
397
-
398
- // animation name
399
- var match = style . match ( / @ k e y f r a m e s \s + ( \S + ) \s + { / )
400
- expect ( match ) . to . have . length ( 2 )
401
- var animationName = match [ 1 ]
402
- expect ( animationName ) . to . not . equal ( 'fade' )
403
- expect ( style ) . to . contain ( 'animation: ' + animationName + ' 1s;' )
404
-
405
- // default module + pre-processor + scoped
406
- var anotherClassName = module . computed . $style ( ) . red
407
- expect ( anotherClassName ) . to . match ( / ^ _ / ) . and . not . equal ( className )
408
- var id = 'data-v-' + genId ( require . resolve ( './fixtures/css-modules.vue' ) )
409
- expect ( style ) . to . contain ( '.' + anotherClassName + '[' + id + ']' )
442
+ // no css
443
+ expect ( window . document . querySelector ( 'style' ) ) . to . not . exist ( )
410
444
411
445
done ( )
412
446
} )
0 commit comments