@@ -410,6 +410,44 @@ describe('WebpackConfig object', () => {
410410 expect ( String ( config . babelOptions . exclude ) ) . to . equal ( String ( / ( n o d e _ m o d u l e s | b o w e r _ c o m p o n e n t s ) / ) ) ;
411411 } ) ;
412412
413+ it ( 'Calling with "exclude" option' , ( ) => {
414+ const config = createConfig ( ) ;
415+ config . configureBabel ( ( ) => { } , { exclude : 'foo' } ) ;
416+
417+ expect ( config . babelOptions . exclude ) . to . equal ( 'foo' ) ;
418+ } ) ;
419+
420+ it ( 'Calling with "include_node_modules" option' , ( ) => {
421+ const config = createConfig ( ) ;
422+ config . configureBabel ( ( ) => { } , { include_node_modules : [ 'foo' , 'bar' ] } ) ;
423+
424+ expect ( config . babelOptions . exclude ) . to . be . a ( 'Function' ) ;
425+
426+ const includedPaths = [
427+ path . join ( 'test' , 'lib' , 'index.js' ) ,
428+ path . join ( 'test' , 'node_modules' , 'foo' , 'index.js' ) ,
429+ path . join ( 'test' , 'node_modules' , 'foo' , 'lib' , 'index.js' ) ,
430+ path . join ( 'test' , 'node_modules' , 'bar' , 'lib' , 'index.js' ) ,
431+ path . join ( 'test' , 'node_modules' , 'baz' , 'node_modules' , 'foo' , 'index.js' ) ,
432+ ] ;
433+
434+ const excludedPaths = [
435+ path . join ( 'test' , 'bower_components' , 'foo' , 'index.js' ) ,
436+ path . join ( 'test' , 'bower_components' , 'bar' , 'index.js' ) ,
437+ path . join ( 'test' , 'bower_components' , 'baz' , 'index.js' ) ,
438+ path . join ( 'test' , 'node_modules' , 'baz' , 'lib' , 'index.js' ) ,
439+ path . join ( 'test' , 'node_modules' , 'baz' , 'lib' , 'foo' , 'index.js' )
440+ ] ;
441+
442+ for ( const filePath of includedPaths ) {
443+ expect ( config . babelOptions . exclude ( filePath ) ) . to . equal ( false ) ;
444+ }
445+
446+ for ( const filePath of excludedPaths ) {
447+ expect ( config . babelOptions . exclude ( filePath ) ) . to . equal ( true ) ;
448+ }
449+ } ) ;
450+
413451 it ( 'Calling with non-callback throws an error' , ( ) => {
414452 const config = createConfig ( ) ;
415453
@@ -427,19 +465,20 @@ describe('WebpackConfig object', () => {
427465 } ) . to . throw ( 'configureBabel() cannot be called because your app already has Babel configuration' ) ;
428466 } ) ;
429467
430- it ( 'Pass valid config' , ( ) => {
468+ it ( 'Pass invalid config' , ( ) => {
431469 const config = createConfig ( ) ;
432- config . configureBabel ( ( ) => { } , { exclude : 'foo' } ) ;
433470
434- expect ( config . babelOptions . exclude ) . to . equal ( 'foo' ) ;
471+ expect ( ( ) => {
472+ config . configureBabel ( ( ) => { } , { fake_option : 'foo' } ) ;
473+ } ) . to . throw ( 'Invalid option "fake_option" passed to configureBabel()' ) ;
435474 } ) ;
436475
437- it ( 'Pass invalid config ' , ( ) => {
476+ it ( 'Calling with both "include_node_modules" and "exclude" options ' , ( ) => {
438477 const config = createConfig ( ) ;
439478
440479 expect ( ( ) => {
441- config . configureBabel ( ( ) => { } , { fake_option : 'foo' } ) ;
442- } ) . to . throw ( 'Invalid option "fake_option" passed to configureBabel() ' ) ;
480+ config . configureBabel ( ( ) => { } , { exclude : 'foo' , include_node_modules : [ 'bar' , 'baz' ] } ) ;
481+ } ) . to . throw ( 'can\'t be used together ' ) ;
443482 } ) ;
444483 } ) ;
445484
0 commit comments