@@ -1106,4 +1106,66 @@ describe('broccoli-funnel', function() {
11061106 expect ( getDestPathCalled ) . to . be . equal ( 1 ) ;
11071107 } ) ;
11081108 } ) ;
1109+
1110+ describe ( 'subclassing' , function ( ) {
1111+ it ( 'can be subclassed, simple destDir modification' , async function ( ) {
1112+ class FunnelSubclass extends Funnel . Funnel {
1113+ constructor ( input , options ) {
1114+ super ( input , options ) ;
1115+
1116+ this . _hasBuilt = false ;
1117+ }
1118+
1119+ build ( ) {
1120+ if ( this . _hasBuilt === false ) {
1121+ this . destDir = 'lol' ;
1122+ this . _hasBuilt = true ;
1123+ }
1124+
1125+ return super . build ( ) ;
1126+ }
1127+ }
1128+
1129+ let inputPath = input . path ( 'lib/utils' ) ;
1130+ let node = new FunnelSubclass ( inputPath , { } ) ;
1131+ output = createBuilder ( node ) ;
1132+
1133+ await output . build ( ) ;
1134+ let outputPath = output . path ( ) ;
1135+
1136+ expect ( walkSync ( outputPath ) ) . to . eql ( [ 'lol/' , 'lol/foo.js' ] ) ;
1137+ } ) ;
1138+
1139+ it ( 'subclasses can provide additional trees' , async function ( ) {
1140+ class FunnelSubclass extends Funnel . Funnel {
1141+ constructor ( inputNode , options ) {
1142+ super ( [ inputNode , input . path ( 'dir1/subdir2' ) ] , options ) ;
1143+
1144+ this . _hasBuilt = false ;
1145+ }
1146+
1147+ build ( ) {
1148+ if ( this . _hasBuilt === false ) {
1149+ if ( ! fs . existsSync ( `${ this . inputPaths [ 1 ] } /bar.css` ) ) {
1150+ throw new Error ( 'Could not find file!!!' ) ;
1151+ }
1152+ // set custom destDir to ensure our custom build code ran
1153+ this . destDir = 'lol' ;
1154+ this . _hasBuilt = true ;
1155+ }
1156+
1157+ return super . build ( ) ;
1158+ }
1159+ }
1160+
1161+ let inputPath = input . path ( 'lib/utils' ) ;
1162+ let node = new FunnelSubclass ( inputPath , { } ) ;
1163+ output = createBuilder ( node ) ;
1164+
1165+ await output . build ( ) ;
1166+ let outputPath = output . path ( ) ;
1167+
1168+ expect ( walkSync ( outputPath ) ) . to . eql ( [ 'lol/' , 'lol/foo.js' ] ) ;
1169+ } ) ;
1170+ } ) ;
11091171} ) ;
0 commit comments