@@ -94,6 +94,17 @@ describe('apply function', () => {
94
94
} else {
95
95
expect ( compilation . assets ) . to . deep . equal ( { } ) ;
96
96
}
97
+
98
+ if ( opts . expectedAssetContent ) {
99
+ for ( var key in opts . expectedAssetContent ) {
100
+ expect ( compilation . assets [ key ] ) . to . exist ;
101
+ if ( compilation . assets [ key ] ) {
102
+ let expectedContent = opts . expectedAssetContent [ key ] ;
103
+ let compiledContent = compilation . assets [ key ] . source ( ) . toString ( ) ;
104
+ expect ( compiledContent ) . to . equal ( expectedContent ) ;
105
+ }
106
+ }
107
+ }
97
108
} ) ;
98
109
} ;
99
110
@@ -107,12 +118,7 @@ describe('apply function', () => {
107
118
}
108
119
} ;
109
120
110
- return run ( opts )
111
- . then ( ( compilation ) => {
112
- const assetContent = compilation . assets [ opts . existingAsset ] . source ( ) . toString ( ) ;
113
-
114
- expect ( assetContent ) . to . equal ( opts . expectedAssetContent ) ;
115
- } ) ;
121
+ return run ( opts ) . then ( ( ) => { } ) ;
116
122
} ;
117
123
118
124
const runChange = ( opts ) => {
@@ -344,6 +350,25 @@ describe('apply function', () => {
344
350
. catch ( done ) ;
345
351
} ) ;
346
352
353
+ it ( 'can transform a file' , ( done ) => {
354
+ runEmit ( {
355
+ expectedAssetKeys : [
356
+ 'file.txt'
357
+ ] ,
358
+ expectedAssetContent : {
359
+ 'file.txt' : 'changed'
360
+ } ,
361
+ patterns : [ {
362
+ from : 'file.txt' ,
363
+ transform : function ( ) {
364
+ return 'changed' ;
365
+ }
366
+ } ]
367
+ } )
368
+ . then ( done )
369
+ . catch ( done ) ;
370
+ } ) ;
371
+
347
372
it ( 'warns when file not found' , ( done ) => {
348
373
runEmit ( {
349
374
expectedAssetKeys : [ ] ,
@@ -358,6 +383,23 @@ describe('apply function', () => {
358
383
. catch ( done ) ;
359
384
} ) ;
360
385
386
+ it ( 'warns when tranform failed' , ( done ) => {
387
+ runEmit ( {
388
+ expectedAssetKeys : [ ] ,
389
+ expectedErrors : [
390
+ 'a failure happened'
391
+ ] ,
392
+ patterns : [ {
393
+ from : 'file.txt' ,
394
+ transform : function ( ) {
395
+ throw 'a failure happened' ;
396
+ }
397
+ } ]
398
+ } )
399
+ . then ( done )
400
+ . catch ( done ) ;
401
+ } ) ;
402
+
361
403
it ( 'can use an absolute path to move a file to the root directory' , ( done ) => {
362
404
const absolutePath = path . resolve ( HELPER_DIR , 'file.txt' ) ;
363
405
@@ -592,7 +634,9 @@ describe('apply function', () => {
592
634
it ( 'won\'t overwrite a file already in the compilation' , ( done ) => {
593
635
runForce ( {
594
636
existingAsset : 'file.txt' ,
595
- expectedAssetContent : 'existing' ,
637
+ expectedAssetContent : {
638
+ 'file.txt' : 'existing'
639
+ } ,
596
640
patterns : [ {
597
641
from : 'file.txt'
598
642
} ]
@@ -604,7 +648,9 @@ describe('apply function', () => {
604
648
it ( 'can force overwrite of a file already in the compilation' , ( done ) => {
605
649
runForce ( {
606
650
existingAsset : 'file.txt' ,
607
- expectedAssetContent : 'new' ,
651
+ expectedAssetContent : {
652
+ 'file.txt' : 'new'
653
+ } ,
608
654
patterns : [ {
609
655
force : true ,
610
656
from : 'file.txt'
@@ -837,7 +883,9 @@ describe('apply function', () => {
837
883
it ( 'won\'t overwrite a file already in the compilation' , ( done ) => {
838
884
runForce ( {
839
885
existingAsset : 'directoryfile.txt' ,
840
- expectedAssetContent : 'existing' ,
886
+ expectedAssetContent : {
887
+ 'directoryfile.txt' : 'existing'
888
+ } ,
841
889
patterns : [ {
842
890
from : 'directory'
843
891
} ]
@@ -849,7 +897,9 @@ describe('apply function', () => {
849
897
it ( 'can force overwrite of a file already in the compilation' , ( done ) => {
850
898
runForce ( {
851
899
existingAsset : 'directoryfile.txt' ,
852
- expectedAssetContent : 'new' ,
900
+ expectedAssetContent : {
901
+ 'directoryfile.txt' : 'new'
902
+ } ,
853
903
patterns : [ {
854
904
force : true ,
855
905
from : 'directory'
0 commit comments