@@ -65,6 +65,53 @@ describe('Basic CSS Module Support', () => {
6565 } )
6666} )
6767
68+ describe ( '3rd Party CSS Module Support' , ( ) => {
69+ const appDir = join ( fixturesDir , '3rd-party-module' )
70+
71+ let appPort
72+ let app
73+ beforeAll ( async ( ) => {
74+ await remove ( join ( appDir , '.next' ) )
75+ await nextBuild ( appDir )
76+ appPort = await findPort ( )
77+ app = await nextStart ( appDir , appPort )
78+ } )
79+ afterAll ( async ( ) => {
80+ await killApp ( app )
81+ } )
82+
83+ it ( `should've emitted a single CSS file` , async ( ) => {
84+ const cssFolder = join ( appDir , '.next/static/css' )
85+
86+ const files = await readdir ( cssFolder )
87+ const cssFiles = files . filter ( f => / \. c s s $ / . test ( f ) )
88+
89+ expect ( cssFiles . length ) . toBe ( 1 )
90+ const cssContent = await readFile ( join ( cssFolder , cssFiles [ 0 ] ) , 'utf8' )
91+
92+ expect ( cssContent . replace ( / \/ \* .* ?\* \/ / g, '' ) . trim ( ) ) . toMatchInlineSnapshot (
93+ `".index_foo__29BAH{position:relative}.index_foo__29BAH .bar,.index_foo__29BAH .baz{height:100%;overflow:hidden}.index_foo__29BAH .lol,.index_foo__29BAH>.lel{width:80%}"`
94+ )
95+ } )
96+
97+ it ( `should've injected the CSS on server render` , async ( ) => {
98+ const content = await renderViaHTTP ( appPort , '/' )
99+ const $ = cheerio . load ( content )
100+
101+ const cssPreload = $ ( 'link[rel="preload"][as="style"]' )
102+ expect ( cssPreload . length ) . toBe ( 1 )
103+ expect ( cssPreload . attr ( 'href' ) ) . toMatch ( / ^ \/ _ n e x t \/ s t a t i c \/ c s s \/ .* \. c s s $ / )
104+
105+ const cssSheet = $ ( 'link[rel="stylesheet"]' )
106+ expect ( cssSheet . length ) . toBe ( 1 )
107+ expect ( cssSheet . attr ( 'href' ) ) . toMatch ( / ^ \/ _ n e x t \/ s t a t i c \/ c s s \/ .* \. c s s $ / )
108+
109+ expect ( $ ( '#verify-div' ) . attr ( 'class' ) ) . toMatchInlineSnapshot (
110+ `"index_foo__29BAH"`
111+ )
112+ } )
113+ } )
114+
68115describe ( 'Has CSS Module in computed styles in Development' , ( ) => {
69116 const appDir = join ( fixturesDir , 'dev-module' )
70117
0 commit comments