@@ -410,6 +410,44 @@ describe('WebpackConfig object', () => {
410
410
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 ) / ) ) ;
411
411
} ) ;
412
412
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
+
413
451
it ( 'Calling with non-callback throws an error' , ( ) => {
414
452
const config = createConfig ( ) ;
415
453
@@ -427,19 +465,28 @@ describe('WebpackConfig object', () => {
427
465
} ) . to . throw ( 'configureBabel() cannot be called because your app already has Babel configuration' ) ;
428
466
} ) ;
429
467
430
- it ( 'Pass valid config' , ( ) => {
468
+ it ( 'Pass invalid config' , ( ) => {
431
469
const config = createConfig ( ) ;
432
- config . configureBabel ( ( ) => { } , { exclude : 'foo' } ) ;
433
470
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()' ) ;
435
474
} ) ;
436
475
437
- it ( 'Pass invalid config ' , ( ) => {
476
+ it ( 'Calling with both "include_node_modules" and "exclude" options ' , ( ) => {
438
477
const config = createConfig ( ) ;
439
478
440
479
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' ) ;
482
+ } ) ;
483
+
484
+ it ( 'Calling with an invalid "include_node_modules" option value' , ( ) => {
485
+ const config = createConfig ( ) ;
486
+
487
+ expect ( ( ) => {
488
+ config . configureBabel ( ( ) => { } , { include_node_modules : 'foo' } ) ;
489
+ } ) . to . throw ( 'must be an Array' ) ;
443
490
} ) ;
444
491
} ) ;
445
492
0 commit comments