@@ -888,6 +888,71 @@ describe("`transform()`", () => {
888888 expect ( error ) . toBeInstanceOf ( Error ) ;
889889 expect ( callbackData ) . not . toBeDefined ( ) ;
890890 } ) ;
891+
892+ test ( "calls the `onTransformEndFn` callback of each plugin, if defined, when `transform` has finished running" , async ( ) => {
893+ const onTransformEndFn = jest . fn ( ) ;
894+ const plugins = [
895+ {
896+ module : {
897+ name : "sourcebit-test1" ,
898+ onTransformEnd : onTransformEndFn ,
899+ transform : async ( { data } ) => {
900+ return {
901+ ...data ,
902+ elements : [ { name : "Lead" } ]
903+ } ;
904+ }
905+ }
906+ } ,
907+ {
908+ module : {
909+ name : "sourcebit-test2" ,
910+ onTransformEnd : onTransformEndFn ,
911+ transform : ( { data } ) => {
912+ return {
913+ ...data ,
914+ elements : data . elements . concat ( {
915+ name : "Rhenium"
916+ } )
917+ } ;
918+ }
919+ }
920+ } ,
921+ {
922+ module : {
923+ name : "sourcebit-test3" ,
924+ onTransformEnd : onTransformEndFn ,
925+ transform : ( { data } ) => {
926+ return {
927+ ...data ,
928+ elements : data . elements . concat ( {
929+ name : "Osmium"
930+ } )
931+ } ;
932+ }
933+ }
934+ }
935+ ] ;
936+ const callback = jest . fn ( ) ;
937+ const sourcebit = new Sourcebit ( ) ;
938+
939+ sourcebit . onTransform = callback ;
940+ sourcebit . loadPlugins ( plugins ) ;
941+
942+ await sourcebit . bootstrapAll ( ) ;
943+
944+ const data = await sourcebit . transform ( ) ;
945+
946+ expect ( onTransformEndFn ) . toHaveBeenCalledTimes ( 3 ) ;
947+
948+ onTransformEndFn . mock . calls . forEach ( call => {
949+ expect ( call [ 0 ] . debug ) . toBeInstanceOf ( Function ) ;
950+ expect ( call [ 0 ] . getPluginContext ) . toBeInstanceOf ( Function ) ;
951+ expect ( call [ 0 ] . log ) . toBeInstanceOf ( Function ) ;
952+ expect ( call [ 0 ] . options ) . toEqual ( { } ) ;
953+ expect ( call [ 0 ] . data ) . toEqual ( data ) ;
954+ } ) ;
955+ } ) ;
891956} ) ;
892957
893958describe ( "writing files" , ( ) => {
0 commit comments