@@ -50,6 +50,34 @@ describe('When the module attribute has an invalid value', () => {
5050 } ) ;
5151} ) ;
5252
53+ test ( 'Use the filepath only as hash seeder' , async ( ) => {
54+ const output = await compiler ( {
55+ source : '<style module>.red { color: red; } .bold { color: bold; }</style><span class="red bold">Red</span>' ,
56+ } , {
57+ mode : 'native' ,
58+ localIdentName : '[local]-[hash:6]' ,
59+ hashSeeder : [ 'filepath' ] ,
60+ } ) ;
61+
62+ expect ( output ) . toBe (
63+ '<style module>:global(.red-027d15) { color: red; } :global(.bold-027d15) { color: bold; }</style><span class="red-027d15 bold-027d15">Red</span>'
64+ ) ;
65+ } ) ;
66+
67+ describe ( 'When the hashSeeder has a wrong key' , ( ) => {
68+ const source = '<style module>.red { color: red; }</style>' ;
69+
70+ it ( 'throws an exception' , async ( ) => {
71+ await expect ( compiler ( {
72+ source
73+ } , {
74+ hashSeeder : [ 'filepath' , 'content' ] ,
75+ } ) ) . rejects . toThrow (
76+ `The hash seeder only accepts the keys 'style', 'filepath' and 'classname': 'content' was passed.`
77+ ) ;
78+ } ) ;
79+ } ) ;
80+
5381describe ( 'When the preprocessor is set as default scoping' , ( ) => {
5482 it ( 'parses the style tag with no module attributes' , async ( ) => {
5583 const source = '<style>.red { color: red; }</style><p class="red">red</p>' ;
@@ -94,40 +122,10 @@ describe('When the preprocessor is set as default scoping', () => {
94122 const output = await compiler ( {
95123 source
96124 } , {
97- parseStyleTag : true ,
98125 useAsDefaultScoping : true ,
99126 } ) ;
100127
101128 expect ( output ) . toBe ( '<p class="red">red</p>' )
102129 } ) ;
103130} ) ;
104131
105- test ( 'Use the filepath only as hash seeder' , async ( ) => {
106- const output = await compiler ( {
107- source : '<style module>.red { color: red; } .bold { color: bold; }</style><span class="red bold">Red</span>' ,
108- } , {
109- mode : 'native' ,
110- localIdentName : '[local]-[hash:6]' ,
111- hashSeeder : [ 'filepath' ] ,
112- } ) ;
113-
114- expect ( output ) . toBe (
115- '<style module>:global(.red-027d15) { color: red; } :global(.bold-027d15) { color: bold; }</style><span class="red-027d15 bold-027d15">Red</span>'
116- ) ;
117- } ) ;
118-
119- describe ( 'When the hashSeeder has a wrong key' , ( ) => {
120- const source = '<style module>.red { color: red; }</style>' ;
121-
122- it ( 'throws an exception' , async ( ) => {
123- await expect ( compiler ( {
124- source
125- } , {
126- hashSeeder : [ 'filepath' , 'content' ] ,
127- } ) ) . rejects . toThrow (
128- `The hash seeder only accepts the keys 'style', 'filepath' and 'classname': 'content' was passed.`
129- ) ;
130- } ) ;
131- } ) ;
132-
133-
0 commit comments