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