@@ -171,6 +171,89 @@ test('CSS Modules', async () => {
171171 )
172172} )
173173
174+ test ( 'CSS Modules namedExport' , async ( ) => {
175+ const testWithIdent = async (
176+ localIdentName : string | undefined ,
177+ regexToMatch : RegExp
178+ ) => {
179+ const baseLoaders = [
180+ {
181+ loader : 'style-loader' ,
182+ options : {
183+ modules : {
184+ namedExport : true ,
185+ } ,
186+ } ,
187+ } ,
188+ {
189+ loader : 'css-loader' ,
190+ options : {
191+ modules : {
192+ localIdentName,
193+ namedExport : true ,
194+ } ,
195+ } ,
196+ } ,
197+ ]
198+
199+ const { window, instance } = await mockBundleAndRun ( {
200+ entry : 'css-modules.vue' ,
201+ modify : ( config : any ) => {
202+ config ! . module ! . rules = [
203+ {
204+ test : / \. v u e $ / ,
205+ loader : 'vue-loader' ,
206+ } ,
207+ {
208+ test : / \. c s s $ / ,
209+ use : baseLoaders ,
210+ } ,
211+ {
212+ test : / \. s t y l u s $ / ,
213+ use : [ ...baseLoaders , 'stylus-loader' ] ,
214+ } ,
215+ ]
216+ } ,
217+ } )
218+
219+ // get local class name
220+ const className = instance . $style . red
221+ expect ( className ) . toMatch ( regexToMatch )
222+
223+ // class name in style
224+ let style = [ ] . slice
225+ . call ( window . document . querySelectorAll ( 'style' ) )
226+ . map ( ( style : any ) => {
227+ return style ! . textContent
228+ } )
229+ . join ( '\n' )
230+ style = normalizeNewline ( style )
231+ expect ( style ) . toContain ( '.' + className + ' {\n color: red;\n}' )
232+
233+ // animation name
234+ const match = style . match ( / @ k e y f r a m e s \s + ( \S + ) \s + { / )
235+ expect ( match ) . toHaveLength ( 2 )
236+ const animationName = match [ 1 ]
237+ expect ( animationName ) . not . toBe ( 'fade' )
238+ expect ( style ) . toContain ( 'animation: ' + animationName + ' 1s;' )
239+
240+ // default module + pre-processor + scoped
241+ const anotherClassName = instance . $style . red
242+ expect ( anotherClassName ) . toMatch ( regexToMatch )
243+ const id = 'data-v-' + genId ( 'css-modules.vue' )
244+ expect ( style ) . toContain ( '.' + anotherClassName + '[' + id + ']' )
245+ }
246+
247+ // default ident
248+ await testWithIdent ( undefined , / ^ \w { 21 , } / )
249+
250+ // custom ident
251+ await testWithIdent (
252+ '[path][name]---[local]---[hash:base64:5]' ,
253+ / c s s - m o d u l e s - - - r e d - - - \w { 5 } /
254+ )
255+ } )
256+
174257test ( 'CSS Modules Extend' , async ( ) => {
175258 const baseLoaders = [
176259 'style-loader' ,
0 commit comments