@@ -99,36 +99,40 @@ describe('when applied with all options', () => {
99
99
chunkPluginEnvironment = new PluginEnvironment ( ) ;
100
100
compilation = chunkPluginEnvironment . getEnvironmentStub ( ) ;
101
101
compilation . assets = {
102
- 'test.js' : {
103
- source : ( ) => '/** @preserve Foo Bar */ function foo(longVariableName) { longVariableName = 1; }' ,
104
- map : ( ) => {
105
- return {
102
+ sourceAndMap : ( ) => {
103
+ return {
104
+ source : '/** @preserve Foo Bar */ function foo(longVariableName) { longVariableName = 1; }' ,
105
+ map : {
106
106
version : 3 ,
107
107
sources : [ 'test.js' ] ,
108
108
names : [ 'foo' , 'longVariableName' ] ,
109
109
mappings : 'AAAA,QAASA,KAAIC,kBACTA,iBAAmB' ,
110
- } ;
111
- } ,
110
+ } ,
111
+ } ;
112
112
} ,
113
113
'test1.js' : {
114
- source : ( ) => 'invalid javascript' ,
115
- map : ( ) => {
114
+ sourceAndMap : ( ) => {
116
115
return {
117
- version : 3 ,
118
- sources : [ 'test1.js' ] ,
119
- names : [ '' ] ,
120
- mappings : 'AAAA' ,
116
+ source : 'invalid javascript' ,
117
+ map : {
118
+ version : 3 ,
119
+ sources : [ 'test1.js' ] ,
120
+ names : [ '' ] ,
121
+ mappings : 'AAAA' ,
122
+ } ,
121
123
} ;
122
124
} ,
123
125
} ,
124
126
'test2.js' : {
125
- source : ( ) => 'function foo(x) { if (x) { return bar(); not_called1(); } }' ,
126
- map : ( ) => {
127
+ sourceAndMap : ( ) => {
127
128
return {
128
- version : 3 ,
129
- sources : [ 'test1.js' ] ,
130
- names : [ 'foo' , 'x' , 'bar' , 'not_called1' ] ,
131
- mappings : 'AAAA,QAASA,KAAIC,GACT,GAAIA,EAAG,CACH,MAAOC,MACPC' ,
129
+ source : 'function foo(x) { if (x) { return bar(); not_called1(); } }' ,
130
+ map : {
131
+ version : 3 ,
132
+ sources : [ 'test1.js' ] ,
133
+ names : [ 'foo' , 'x' , 'bar' , 'not_called1' ] ,
134
+ mappings : 'AAAA,QAASA,KAAIC,GACT,GAAIA,EAAG,CACH,MAAOC,MACPC' ,
135
+ } ,
132
136
} ;
133
137
} ,
134
138
} ,
@@ -146,13 +150,15 @@ describe('when applied with all options', () => {
146
150
} ,
147
151
} ,
148
152
'test4.js' : {
149
- source : ( ) => '/*! this comment should be extracted */ function foo(longVariableName) { /* this will not be extracted */ longVariableName = 1; } // another comment that should be extracted to a separate file\n function foo2(bar) { return bar; }' ,
150
- map : ( ) => {
153
+ sourceAndMap : ( ) => {
151
154
return {
152
- version : 3 ,
153
- sources : [ 'test.js' ] ,
154
- names : [ 'foo' , 'longVariableName' ] ,
155
- mappings : 'AAAA,QAASA,KAAIC,kBACTA,iBAAmB' ,
155
+ source : '/*! this comment should be extracted */ function foo(longVariableName) { /* this will not be extracted */ longVariableName = 1; } // another comment that should be extracted to a separate file\n function foo2(bar) { return bar; }' ,
156
+ map : {
157
+ version : 3 ,
158
+ sources : [ 'test.js' ] ,
159
+ names : [ 'foo' , 'longVariableName' ] ,
160
+ mappings : 'AAAA,QAASA,KAAIC,kBACTA,iBAAmB' ,
161
+ } ,
156
162
} ;
157
163
} ,
158
164
} ,
@@ -279,7 +285,7 @@ describe('when applied with all options', () => {
279
285
} ) ;
280
286
281
287
describe ( 'with warningsFilter set' , ( ) => {
282
- describe ( 'and the filter returns true' , ( ) => {
288
+ describe ( 'and the filter returns true without source map ' , ( ) => {
283
289
beforeEach ( ( ) => {
284
290
const pluginEnvironment = new PluginEnvironment ( ) ;
285
291
const compilerEnv = pluginEnvironment . getEnvironmentStub ( ) ;
@@ -302,14 +308,61 @@ describe('when applied with all options', () => {
302
308
chunkPluginEnvironment = new PluginEnvironment ( ) ;
303
309
compilation = chunkPluginEnvironment . getEnvironmentStub ( ) ;
304
310
compilation . assets = {
305
- 'test2 .js' : {
311
+ 'test .js' : {
306
312
source : ( ) => 'function foo(x) { if (x) { return bar(); not_called1(); } }' ,
307
- map : ( ) => {
313
+ } ,
314
+ } ;
315
+ compilation . errors = [ ] ;
316
+ compilation . warnings = [ ] ;
317
+
318
+ eventBindings [ 0 ] . handler ( compilation ) ;
319
+ compilationEventBindings = chunkPluginEnvironment . getEventBindings ( ) ;
320
+ } ) ;
321
+
322
+ it ( 'should get all warnings' , ( ) => {
323
+ compilationEventBindings [ 1 ] . handler ( [ {
324
+ files : [ 'test.js' ] ,
325
+ } ] , ( ) => {
326
+ expect ( compilation . warnings . length ) . toBe ( 1 ) ;
327
+ expect ( compilation . warnings [ 0 ] ) . toBeInstanceOf ( Error ) ;
328
+ expect ( compilation . warnings [ 0 ] . message ) . toEqual ( expect . stringContaining ( 'Dropping unreachable code' ) ) ;
329
+ } ) ;
330
+ } ) ;
331
+ } ) ;
332
+
333
+ describe ( 'and the filter returns true with source map' , ( ) => {
334
+ beforeEach ( ( ) => {
335
+ const pluginEnvironment = new PluginEnvironment ( ) ;
336
+ const compilerEnv = pluginEnvironment . getEnvironmentStub ( ) ;
337
+ compilerEnv . context = '' ;
338
+
339
+ const plugin = new UglifyJsPlugin ( {
340
+ warningsFilter : ( ) => true ,
341
+ sourceMap : true ,
342
+ uglifyOptions : {
343
+ warnings : true ,
344
+ mangle : false ,
345
+ output : {
346
+ beautify : true ,
347
+ } ,
348
+ } ,
349
+ } ) ;
350
+ plugin . apply ( compilerEnv ) ;
351
+ eventBindings = pluginEnvironment . getEventBindings ( ) ;
352
+
353
+ chunkPluginEnvironment = new PluginEnvironment ( ) ;
354
+ compilation = chunkPluginEnvironment . getEnvironmentStub ( ) ;
355
+ compilation . assets = {
356
+ 'test.js' : {
357
+ sourceAndMap : ( ) => {
308
358
return {
309
- version : 3 ,
310
- sources : [ 'test1.js' ] ,
311
- names : [ 'foo' , 'x' , 'bar' , 'not_called1' ] ,
312
- mappings : 'AAAA,QAASA,KAAIC,GACT,GAAIA,EAAG,CACH,MAAOC,MACPC' ,
359
+ source : 'function foo(x) { if (x) { return bar(); not_called1(); } }' ,
360
+ map : {
361
+ version : 3 ,
362
+ sources : [ 'test.js' ] ,
363
+ names : [ 'foo' , 'x' , 'bar' , 'not_called1' ] ,
364
+ mappings : 'AAAA,QAASA,KAAIC,GACT,GAAIA,EAAG,CACH,MAAOC,MACPC' ,
365
+ } ,
313
366
} ;
314
367
} ,
315
368
} ,
@@ -323,7 +376,7 @@ describe('when applied with all options', () => {
323
376
324
377
it ( 'should get all warnings' , ( ) => {
325
378
compilationEventBindings [ 1 ] . handler ( [ {
326
- files : [ 'test2 .js' ] ,
379
+ files : [ 'test .js' ] ,
327
380
} ] , ( ) => {
328
381
expect ( compilation . warnings . length ) . toBe ( 1 ) ;
329
382
expect ( compilation . warnings [ 0 ] ) . toBeInstanceOf ( Error ) ;
@@ -332,7 +385,7 @@ describe('when applied with all options', () => {
332
385
} ) ;
333
386
} ) ;
334
387
335
- describe ( 'and the filter returns false' , ( ) => {
388
+ describe ( 'and the filter returns false without source map ' , ( ) => {
336
389
beforeEach ( ( ) => {
337
390
const pluginEnvironment = new PluginEnvironment ( ) ;
338
391
const compilerEnv = pluginEnvironment . getEnvironmentStub ( ) ;
@@ -355,14 +408,59 @@ describe('when applied with all options', () => {
355
408
chunkPluginEnvironment = new PluginEnvironment ( ) ;
356
409
compilation = chunkPluginEnvironment . getEnvironmentStub ( ) ;
357
410
compilation . assets = {
358
- 'test2 .js' : {
411
+ 'test .js' : {
359
412
source : ( ) => 'function foo(x) { if (x) { return bar(); not_called1(); } }' ,
360
- map : ( ) => {
413
+ } ,
414
+ } ;
415
+ compilation . errors = [ ] ;
416
+ compilation . warnings = [ ] ;
417
+
418
+ eventBindings [ 0 ] . handler ( compilation ) ;
419
+ compilationEventBindings = chunkPluginEnvironment . getEventBindings ( ) ;
420
+ } ) ;
421
+
422
+ it ( 'should get no warnings' , ( ) => {
423
+ compilationEventBindings [ 1 ] . handler ( [ {
424
+ files : [ 'test.js' ] ,
425
+ } ] , ( ) => {
426
+ expect ( compilation . warnings . length ) . toBe ( 0 ) ;
427
+ } ) ;
428
+ } ) ;
429
+ } ) ;
430
+
431
+ describe ( 'and the filter returns false with source map' , ( ) => {
432
+ beforeEach ( ( ) => {
433
+ const pluginEnvironment = new PluginEnvironment ( ) ;
434
+ const compilerEnv = pluginEnvironment . getEnvironmentStub ( ) ;
435
+ compilerEnv . context = '' ;
436
+
437
+ const plugin = new UglifyJsPlugin ( {
438
+ warningsFilter : ( ) => false ,
439
+ sourceMap : true ,
440
+ uglifyOptions : {
441
+ warnings : true ,
442
+ mangle : false ,
443
+ output : {
444
+ beautify : true ,
445
+ } ,
446
+ } ,
447
+ } ) ;
448
+ plugin . apply ( compilerEnv ) ;
449
+ eventBindings = pluginEnvironment . getEventBindings ( ) ;
450
+
451
+ chunkPluginEnvironment = new PluginEnvironment ( ) ;
452
+ compilation = chunkPluginEnvironment . getEnvironmentStub ( ) ;
453
+ compilation . assets = {
454
+ 'test.js' : {
455
+ sourceAndMap : ( ) => {
361
456
return {
362
- version : 3 ,
363
- sources : [ 'test1.js' ] ,
364
- names : [ 'foo' , 'x' , 'bar' , 'not_called1' ] ,
365
- mappings : 'AAAA,QAASA,KAAIC,GACT,GAAIA,EAAG,CACH,MAAOC,MACPC' ,
457
+ source : 'function foo(x) { if (x) { return bar(); not_called1(); } }' ,
458
+ map : {
459
+ version : 3 ,
460
+ sources : [ 'test.js' ] ,
461
+ names : [ 'foo' , 'x' , 'bar' , 'not_called1' ] ,
462
+ mappings : 'AAAA,QAASA,KAAIC,GACT,GAAIA,EAAG,CACH,MAAOC,MACPC' ,
463
+ } ,
366
464
} ;
367
465
} ,
368
466
} ,
@@ -376,7 +474,7 @@ describe('when applied with all options', () => {
376
474
377
475
it ( 'should get no warnings' , ( ) => {
378
476
compilationEventBindings [ 1 ] . handler ( [ {
379
- files : [ 'test2 .js' ] ,
477
+ files : [ 'test .js' ] ,
380
478
} ] , ( ) => {
381
479
expect ( compilation . warnings . length ) . toBe ( 0 ) ;
382
480
} ) ;
0 commit comments