@@ -43,6 +43,15 @@ describe("Errors", () => {
43
43
callback ( stats . errors , stats . warnings ) ;
44
44
} ) ;
45
45
}
46
+
47
+ function getErrorsPromise ( options , callback ) {
48
+ return new Promise ( ( resolve , reject ) => {
49
+ getErrors ( options , ( errors , warnings ) => {
50
+ callback ( errors , warnings ) ;
51
+ resolve ( ) ;
52
+ } ) ;
53
+ } ) ;
54
+ }
46
55
it ( "should throw an error if file doesn't exist" , done => {
47
56
getErrors (
48
57
{
@@ -190,4 +199,162 @@ describe("Errors", () => {
190
199
}
191
200
) ;
192
201
} ) ;
202
+ it ( "should show loader name when emit/throw errors or warnings from loaders" , ( ) => {
203
+ return Promise . all ( [
204
+ getErrorsPromise (
205
+ {
206
+ mode : "development" ,
207
+ entry : "./entry-point-error-loader-required.js"
208
+ } ,
209
+ ( errors , warnings ) => {
210
+ expect ( warnings ) . toHaveLength ( 1 ) ;
211
+ expect ( warnings [ 0 ] . split ( "\n" ) [ 1 ] ) . toMatch (
212
+ / ^ M o d u l e W a r n i n g \( f r o m .\/ e m i t - e r r o r - l o a d e r .j s \) : $ /
213
+ ) ;
214
+ expect ( errors ) . toHaveLength ( 1 ) ;
215
+ expect ( errors [ 0 ] . split ( "\n" ) [ 1 ] ) . toMatch (
216
+ / ^ M o d u l e E r r o r \( f r o m .\/ e m i t - e r r o r - l o a d e r .j s \) : $ /
217
+ ) ;
218
+ }
219
+ ) ,
220
+ getErrorsPromise (
221
+ {
222
+ mode : "development" ,
223
+ entry : path . resolve ( base , "./emit-error-loader" ) + "!./entry-point.js"
224
+ } ,
225
+ ( errors , warnings ) => {
226
+ expect ( warnings ) . toHaveLength ( 1 ) ;
227
+ expect ( warnings [ 0 ] . split ( "\n" ) [ 1 ] ) . toMatch (
228
+ / ^ M o d u l e W a r n i n g \( f r o m .\/ e m i t - e r r o r - l o a d e r .j s \) : $ /
229
+ ) ;
230
+ expect ( errors ) . toHaveLength ( 1 ) ;
231
+ expect ( errors [ 0 ] . split ( "\n" ) [ 1 ] ) . toMatch (
232
+ / ^ M o d u l e E r r o r \( f r o m .\/ e m i t - e r r o r - l o a d e r .j s \) : $ /
233
+ ) ;
234
+ }
235
+ ) ,
236
+ getErrorsPromise (
237
+ {
238
+ mode : "development" ,
239
+ entry : "./not-a-json.js" ,
240
+ module : {
241
+ rules : [
242
+ {
243
+ test : / n o t - a - j s o n \. j s $ / ,
244
+ use : [
245
+ "json-loader" ,
246
+ {
247
+ loader : path . resolve ( base , "./emit-error-loader" )
248
+ }
249
+ ]
250
+ }
251
+ ]
252
+ }
253
+ } ,
254
+ ( errors , warnings ) => {
255
+ expect ( warnings ) . toHaveLength ( 1 ) ;
256
+ expect ( warnings [ 0 ] . split ( "\n" ) [ 1 ] ) . toMatch (
257
+ / ^ M o d u l e W a r n i n g \( f r o m .\/ e m i t - e r r o r - l o a d e r .j s \) : $ /
258
+ ) ;
259
+ expect ( errors ) . toHaveLength ( 2 ) ;
260
+ expect ( errors [ 0 ] . split ( "\n" ) [ 1 ] ) . toMatch (
261
+ / ^ M o d u l e E r r o r \( f r o m .\/ e m i t - e r r o r - l o a d e r .j s \) : $ /
262
+ ) ;
263
+ expect ( errors [ 1 ] . split ( "\n" ) [ 1 ] ) . toMatch (
264
+ / ^ M o d u l e b u i l d f a i l e d \( f r o m \( w e b p a c k \) \/ n o d e _ m o d u l e s \/ j s o n - l o a d e r \/ i n d e x .j s \) : $ /
265
+ ) ;
266
+ }
267
+ ) ,
268
+ getErrorsPromise (
269
+ {
270
+ mode : "development" ,
271
+ entry : "./entry-point.js" ,
272
+ module : {
273
+ rules : [
274
+ {
275
+ test : / e n t r y - p o i n t \. j s $ / ,
276
+ use : path . resolve ( base , "./async-error-loader" )
277
+ }
278
+ ]
279
+ }
280
+ } ,
281
+ ( errors , warnings ) => {
282
+ expect ( errors ) . toHaveLength ( 1 ) ;
283
+ expect ( errors [ 0 ] . split ( "\n" ) [ 1 ] ) . toMatch (
284
+ / ^ M o d u l e b u i l d f a i l e d \( f r o m .\/ a s y n c - e r r o r - l o a d e r .j s \) : $ /
285
+ ) ;
286
+ }
287
+ ) ,
288
+ getErrorsPromise (
289
+ {
290
+ mode : "development" ,
291
+ entry : "./entry-point.js" ,
292
+ module : {
293
+ rules : [
294
+ {
295
+ test : / e n t r y - p o i n t \. j s $ / ,
296
+ use : path . resolve ( base , "./throw-error-loader" )
297
+ }
298
+ ]
299
+ }
300
+ } ,
301
+ ( errors , warnings ) => {
302
+ expect ( errors ) . toHaveLength ( 1 ) ;
303
+ expect ( errors [ 0 ] . split ( "\n" ) [ 1 ] ) . toMatch (
304
+ / ^ M o d u l e b u i l d f a i l e d \( f r o m .\/ t h r o w - e r r o r - l o a d e r .j s \) : $ /
305
+ ) ;
306
+ }
307
+ ) ,
308
+ getErrorsPromise (
309
+ {
310
+ mode : "development" ,
311
+ entry : "./entry-point.js" ,
312
+ module : {
313
+ rules : [
314
+ {
315
+ test : / e n t r y - p o i n t \. j s $ / ,
316
+ use : path . resolve ( base , "./irregular-error-loader" )
317
+ }
318
+ ]
319
+ }
320
+ } ,
321
+ ( errors , warnings ) => {
322
+ expect ( warnings ) . toHaveLength ( 2 ) ;
323
+ expect ( warnings [ 0 ] . split ( "\n" ) [ 1 ] ) . toMatch (
324
+ / ^ M o d u l e W a r n i n g \( f r o m .\/ i r r e g u l a r - e r r o r - l o a d e r .j s \) : $ /
325
+ ) ;
326
+ expect ( warnings [ 1 ] . split ( "\n" ) [ 1 ] ) . toMatch (
327
+ / ^ M o d u l e W a r n i n g \( f r o m .\/ i r r e g u l a r - e r r o r - l o a d e r .j s \) : $ /
328
+ ) ;
329
+
330
+ expect ( errors ) . toHaveLength ( 3 ) ;
331
+ expect ( errors [ 0 ] . split ( "\n" ) [ 1 ] ) . toMatch (
332
+ / ^ M o d u l e E r r o r \( f r o m .\/ i r r e g u l a r - e r r o r - l o a d e r .j s \) : $ /
333
+ ) ;
334
+ expect ( errors [ 1 ] . split ( "\n" ) [ 1 ] ) . toMatch (
335
+ / ^ M o d u l e E r r o r \( f r o m .\/ i r r e g u l a r - e r r o r - l o a d e r .j s \) : $ /
336
+ ) ;
337
+ expect ( errors [ 2 ] . split ( "\n" ) [ 1 ] ) . toMatch (
338
+ / ^ M o d u l e b u i l d f a i l e d \( f r o m .\/ i r r e g u l a r - e r r o r - l o a d e r .j s \) : $ /
339
+ ) ;
340
+ }
341
+ )
342
+ ] ) ;
343
+ } ) ;
344
+ it ( "should throw a build error if no source be returned after run loaders" , done => {
345
+ getErrors (
346
+ {
347
+ mode : "development" ,
348
+ entry : path . resolve ( base , "./no-return-loader" ) + "!./entry-point.js"
349
+ } ,
350
+ ( errors , warnings ) => {
351
+ expect ( errors ) . toHaveLength ( 1 ) ;
352
+ const messages = errors [ 0 ] . split ( "\n" ) ;
353
+ expect ( messages [ 1 ] ) . toMatch (
354
+ / ^ M o d u l e b u i l d f a i l e d : E r r o r : F i n a l l o a d e r \( .+ \) d i d n ' t r e t u r n a B u f f e r o r S t r i n g /
355
+ ) ;
356
+ done ( ) ;
357
+ }
358
+ ) ;
359
+ } ) ;
193
360
} ) ;
0 commit comments