@@ -261,6 +261,79 @@ describe('loader', () => {
261
261
)
262
262
) ;
263
263
} ) ;
264
+
265
+ describe ( 'preprocess' , ( ) => {
266
+ it ( 'should preprocess successfully' , ( done ) => {
267
+ function callback ( err , code , map ) {
268
+ expect ( err ) . not . to . exist ;
269
+ expect ( code ) . to . exist ;
270
+ expect ( code ) . to . contain ( 'button{width:50px;height:50px}' ) ;
271
+ expect ( map ) . to . exist ;
272
+ }
273
+
274
+ function cb ( ) {
275
+ try {
276
+ callback ( ...[ ] . slice . call ( arguments ) ) ;
277
+ } catch ( err ) {
278
+ expect ( callbackSpy ) . to . have . been . called ;
279
+ return done ( err ) ;
280
+ }
281
+ expect ( callbackSpy ) . to . have . been . called ;
282
+ done ( ) ;
283
+ }
284
+
285
+ const fileContents = readFileSync ( 'test/fixtures/style-valid.html' ,
286
+ 'utf-8' ) ;
287
+ const cacheableSpy = spy ( ( ) => {
288
+ } ) ;
289
+ const callbackSpy = spy ( cb ) ;
290
+ const options = {
291
+ style : ( { content } ) => {
292
+ return {
293
+ code : content . replace ( / \$ s i z e / gi, '50px' ) ,
294
+ } ;
295
+ } ,
296
+ } ;
297
+
298
+ loader . call (
299
+ {
300
+ cacheable : cacheableSpy ,
301
+ async : ( ) => callbackSpy ,
302
+ resourcePath : 'test/fixtures/style-valid.html' ,
303
+ options,
304
+ } ,
305
+ fileContents ,
306
+ null
307
+ ) ;
308
+
309
+ expect ( cacheableSpy ) . to . have . been . called ;
310
+ } ) ;
311
+
312
+ it ( 'should not preprocess successfully' , ( ) => {
313
+ const fileContents = readFileSync ( 'test/fixtures/style-valid.html' , 'utf-8' ) ;
314
+ const cacheableSpy = spy ( ( ) => {
315
+ } ) ;
316
+ const options = {
317
+ style : ( ) => {
318
+ throw new Error ( 'Error while preprocessing' ) ;
319
+ } ,
320
+ } ;
321
+
322
+ loader . call (
323
+ {
324
+ cacheable : cacheableSpy ,
325
+ async : ( ) => ( err ) => {
326
+ expect ( err ) . to . exist ;
327
+ } ,
328
+ resourcePath : 'test/fixtures/style-valid.html' ,
329
+ options,
330
+ } ,
331
+ fileContents ,
332
+ null
333
+ ) ;
334
+
335
+ } ) ;
336
+ } ) ;
264
337
} ) ;
265
338
} ) ;
266
339
0 commit comments