11const compiler = require ( './compiler.js' ) ;
22
33const source = '<style>.red { color: red; }</style>\n<span class="$style.red">Red</span>' ;
4- const sourceShorthand = '<style>.red { color: red; }</style>\n<span class="$.red">Red</span>' ;
54
6- test ( 'Generate CSS Modules from HTML attributes, Replace CSS className ' , async ( ) => {
5+ test ( 'Customize generated classname from getLocalIdentName ' , async ( ) => {
76 const output = await compiler ( {
87 source,
9- localIdentName : '[local]-123456' ,
8+ } , {
9+ localIdentName : '[local]-123456MC' ,
10+ getLocalIdentName : ( context , localIdentName ) => {
11+ return localIdentName . interpolated . toLowerCase ( ) ;
12+ }
1013 } ) ;
1114
12- expect ( output ) . toBe ( '<style>:global(.red-123456) { color: red; }</style>\n<span class="red-123456">Red</span>' ) ;
13- } ) ;
14- test ( '[Shorthand] Generate CSS Modules from HTML attributes, Replace CSS className' , async ( ) => {
15- const output = await compiler ( {
16- source : sourceShorthand ,
17- localIdentName : '[local]-123456' ,
18- } ) ;
19-
20- expect ( output ) . toBe ( '<style>:global(.red-123456) { color: red; }</style>\n<span class="red-123456">Red</span>' ) ;
21- } ) ;
22-
23- test ( 'Avoid generated class to start with a non character' , async ( ) => {
24- const output = await compiler ( {
25- source,
26- localIdentName : '1[local]' ,
27- } ) ;
28- expect ( output ) . toBe ( '<style>:global(._1red) { color: red; }</style>\n<span class="_1red">Red</span>' ) ;
29- } ) ;
30- test ( '[Shorthand] Avoid generated class to start with a non character' , async ( ) => {
31- const output = await compiler ( {
32- source : sourceShorthand ,
33- localIdentName : '1[local]' ,
34- } ) ;
35- expect ( output ) . toBe ( '<style>:global(._1red) { color: red; }</style>\n<span class="_1red">Red</span>' ) ;
36- } ) ;
37-
38- test ( 'Avoid generated class to end with a hyphen' , async ( ) => {
39- const output = await compiler ( {
40- source,
41- localIdentName : '[local]-' ,
42- } ) ;
43- expect ( output ) . toBe ( '<style>:global(.red) { color: red; }</style>\n<span class="red">Red</span>' ) ;
44- } ) ;
45- test ( '[Shorthand] Avoid generated class to end with a hyphen' , async ( ) => {
46- const output = await compiler ( {
47- source : sourceShorthand ,
48- localIdentName : '[local]-' ,
49- } ) ;
50- expect ( output ) . toBe ( '<style>:global(.red) { color: red; }</style>\n<span class="red">Red</span>' ) ;
51- } ) ;
15+ expect ( output ) . toBe ( '<style>:global(.red-123456mc) { color: red; }</style>\n<span class="red-123456mc">Red</span>' ) ;
16+ } ) ;
0 commit comments