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
56test ( 'Generate CSS Modules from HTML attributes, Replace CSS className' , async ( ) => {
67 const output = await compiler ( {
@@ -10,6 +11,14 @@ test('Generate CSS Modules from HTML attributes, Replace CSS className', async (
1011
1112 expect ( output ) . toBe ( '<style>:global(.red-123456) { color: red; }</style>\n<span class="red-123456">Red</span>' ) ;
1213} ) ;
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+ } ) ;
1322
1423test ( 'Avoid generated class to start with a non character' , async ( ) => {
1524 const output = await compiler ( {
@@ -18,6 +27,13 @@ test('Avoid generated class to start with a non character', async () => {
1827 } ) ;
1928 expect ( output ) . toBe ( '<style>:global(._1red) { color: red; }</style>\n<span class="_1red">Red</span>' ) ;
2029} ) ;
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+ } ) ;
2137
2238test ( 'Avoid generated class to end with a hyphen' , async ( ) => {
2339 const output = await compiler ( {
@@ -26,3 +42,10 @@ test('Avoid generated class to end with a hyphen', async () => {
2642 } ) ;
2743 expect ( output ) . toBe ( '<style>:global(.red) { color: red; }</style>\n<span class="red">Red</span>' ) ;
2844} ) ;
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+ } ) ;
0 commit comments