1+ const requireFromString = require ( 'require-from-string' )
12const path = require ( 'path' )
23const compile = require ( './compile' )
34
45const cssCustomsLoader = require . resolve ( '../' )
5- const getCompiledOutput = ( { stats, entry } ) =>
6- stats
6+ const getCompiledExportedValue = ( { stats, entry } ) => {
7+ const { source } = stats
78 . toJson ( )
89 . modules . find (
910 ( { name, identifier } ) =>
1011 name . includes ( entry ) && identifier . includes ( cssCustomsLoader )
1112 )
12- // normalize for CI
13- . source . replace (
14- path . relative ( `${ __dirname } /fixtures` , process . cwd ( ) ) ,
15- '<relative path to CWD>'
16- )
13+ return requireFromString (
14+ source ,
15+ `${ __dirname } /fixtures/ ${ path . basename ( entry ) } `
16+ )
17+ }
1718
1819describe ( `emits an error` , ( ) => {
1920 test ( `when css-customs-loader is placed after css-loader` , async ( ) => {
@@ -101,8 +102,20 @@ it(`exposes CSS customs in the default export object`, async () => {
101102 } ,
102103 ] ,
103104 } )
104- const output = getCompiledOutput ( { stats, entry } )
105- expect ( output ) . toMatchSnapshot ( )
105+ const { locals } = getCompiledExportedValue ( { stats, entry } )
106+ expect ( locals ) . toMatchInlineSnapshot ( `
107+ Object {
108+ "customMedia": Object {
109+ "--narrow-window": "(max-width: 30em)",
110+ },
111+ "customProperties": Object {
112+ "--primary-color": "lightblue",
113+ },
114+ "customSelectors": Object {
115+ ":--title": "h1",
116+ },
117+ }
118+ ` )
106119} )
107120
108121it ( `exposes CSS Modules in the same object as customs` , async ( ) => {
@@ -125,8 +138,21 @@ it(`exposes CSS Modules in the same object as customs`, async () => {
125138 } ,
126139 ] ,
127140 } )
128- const output = getCompiledOutput ( { stats, entry } )
129- expect ( output ) . toMatchSnapshot ( )
141+ const { locals } = getCompiledExportedValue ( { stats, entry } )
142+ expect ( locals ) . toMatchInlineSnapshot ( `
143+ Object {
144+ "customMedia": Object {
145+ "--narrow-window": "(max-width: 30em)",
146+ },
147+ "customProperties": Object {
148+ "--primary-color": "lightblue",
149+ },
150+ "customSelectors": Object {
151+ ":--title": "h1",
152+ },
153+ "text": "_3KySKA6rf07sl0ilq7bBBm",
154+ }
155+ ` )
130156} )
131157
132158it ( `can export only locals` , async ( ) => {
@@ -150,8 +176,21 @@ it(`can export only locals`, async () => {
150176 } ,
151177 ] ,
152178 } )
153- const output = getCompiledOutput ( { stats, entry } )
154- expect ( output ) . toMatchSnapshot ( )
179+ const result = getCompiledExportedValue ( { stats, entry } )
180+ expect ( result ) . toMatchInlineSnapshot ( `
181+ Object {
182+ "customMedia": Object {
183+ "--narrow-window": "(max-width: 30em)",
184+ },
185+ "customProperties": Object {
186+ "--primary-color": "lightblue",
187+ },
188+ "customSelectors": Object {
189+ ":--title": "h1",
190+ },
191+ "text": "_3KySKA6rf07sl0ilq7bBBm",
192+ }
193+ ` )
155194} )
156195
157196it ( `supports files with external @imports` , async ( ) => {
@@ -210,8 +249,16 @@ it(`uses PostCSS plugins before postcss-preset-env`, async () => {
210249 } ,
211250 ] ,
212251 } )
213- const output = getCompiledOutput ( { stats, entry } )
214- expect ( output ) . toMatchSnapshot ( )
252+ const { locals } = getCompiledExportedValue ( { stats, entry } )
253+ expect ( locals ) . toMatchInlineSnapshot ( `
254+ Object {
255+ "customMedia": Object {},
256+ "customProperties": Object {
257+ "--primary-color": "#1da1f2",
258+ },
259+ "customSelectors": Object {},
260+ }
261+ ` )
215262} )
216263
217264it ( 'uses webpack loaders after postcss-loader' , async ( ) => {
@@ -234,6 +281,14 @@ it('uses webpack loaders after postcss-loader', async () => {
234281 } ,
235282 ] ,
236283 } )
237- const output = getCompiledOutput ( { stats, entry } )
238- expect ( output ) . toMatchSnapshot ( )
284+ const { locals } = getCompiledExportedValue ( { stats, entry } )
285+ expect ( locals ) . toMatchInlineSnapshot ( `
286+ Object {
287+ "customMedia": Object {},
288+ "customProperties": Object {
289+ "--primary-color": "lightblue",
290+ },
291+ "customSelectors": Object {},
292+ }
293+ ` )
239294} )
0 commit comments