@@ -410,7 +410,7 @@ describe('index', () => {
410
410
// When
411
411
result = await copyFiles ( input , output , useExtension , forceDirectory ) ;
412
412
// Then
413
- expect ( sortResults ( result ) ) . toEqual ( expectedResult ) ;
413
+ expect ( sortResults ( result ) ) . toEqual ( sortResults ( expectedResult ) ) ;
414
414
expect ( fs . readdir ) . toHaveBeenCalledTimes ( 3 ) ;
415
415
expect ( fs . readdir ) . toHaveBeenNthCalledWith ( 1 , src ) ;
416
416
expect ( fs . readdir ) . toHaveBeenNthCalledWith ( 2 , config ) ;
@@ -429,6 +429,115 @@ describe('index', () => {
429
429
} ) ;
430
430
} ) ;
431
431
432
+ it ( 'should copy multiple directories and ignore others' , async ( ) => {
433
+ // Given
434
+ const src = path . join ( cwd , 'src' ) ;
435
+ const config = path . join ( cwd , 'config' ) ;
436
+ const input = [ src , config ] ;
437
+ const output = path . join ( cwd , 'esm' ) ;
438
+ const ignore = [ 'node_modules' , 'utils/@types' ] ;
439
+ const useExtension = 'js' ;
440
+ const forceDirectory = false ;
441
+ const filesSrc = [ 'index.js' , 'utils' , 'README.md' , '.eslintrc' , 'node_modules' ] ;
442
+ const filesUtils = [ 'index.js' , 'utils.js' , '@types' ] ;
443
+ const filesUtilsTypes = [ 'index.js' ] ;
444
+ const filesNodeModules = [ 'modules.js' ] ;
445
+ const filesConfig = [ 'config.js' , '@types' ] ;
446
+ const filesConfigTypes = [ 'index.js' ] ;
447
+ /* eslint-disable jsdoc/require-jsdoc */
448
+ // - src
449
+ fs . readdir . mockImplementationOnce ( ( ) => filesSrc ) ;
450
+ // - config
451
+ fs . readdir . mockImplementationOnce ( ( ) => filesConfig ) ;
452
+ // - src/index.js
453
+ fs . stat . mockImplementationOnce ( ( ) => ( { isDirectory : ( ) => false } ) ) ;
454
+ // - src/utils
455
+ fs . stat . mockImplementationOnce ( ( ) => ( { isDirectory : ( ) => true } ) ) ;
456
+ // - src/README.md
457
+ fs . stat . mockImplementationOnce ( ( ) => ( { isDirectory : ( ) => false } ) ) ;
458
+ // - src/node_modules
459
+ fs . stat . mockImplementationOnce ( ( ) => ( { isDirectory : ( ) => true } ) ) ;
460
+ // - config/config.js
461
+ fs . stat . mockImplementationOnce ( ( ) => ( { isDirectory : ( ) => false } ) ) ;
462
+ // - config/@types
463
+ fs . stat . mockImplementationOnce ( ( ) => ( { isDirectory : ( ) => true } ) ) ;
464
+ // - src/utils
465
+ fs . readdir . mockImplementationOnce ( ( ) => filesUtils ) ;
466
+ // - src/node_modules
467
+ fs . readdir . mockImplementationOnce ( ( ) => filesNodeModules ) ;
468
+ // - config/@types
469
+ fs . readdir . mockImplementationOnce ( ( ) => filesConfigTypes ) ;
470
+ // - src/utils/index.js
471
+ fs . stat . mockImplementationOnce ( ( ) => ( { isDirectory : ( ) => false } ) ) ;
472
+ // - src/utils/utils.js
473
+ fs . stat . mockImplementationOnce ( ( ) => ( { isDirectory : ( ) => false } ) ) ;
474
+ // - src/utils/@types
475
+ fs . stat . mockImplementationOnce ( ( ) => ( { isDirectory : ( ) => true } ) ) ;
476
+ // - src/node_modules/modules.js
477
+ fs . stat . mockImplementationOnce ( ( ) => ( { isDirectory : ( ) => false } ) ) ;
478
+ // - config/@types/index.js
479
+ fs . stat . mockImplementationOnce ( ( ) => ( { isDirectory : ( ) => false } ) ) ;
480
+ // - src/utils/@types
481
+ fs . readdir . mockImplementationOnce ( ( ) => filesUtilsTypes ) ;
482
+ // - src/utils/@types/index.js
483
+ fs . stat . mockImplementationOnce ( ( ) => ( { isDirectory : ( ) => false } ) ) ;
484
+
485
+ /* eslint-enable jsdoc/require-jsdoc */
486
+ let result = null ;
487
+ const expectedResult = [
488
+ {
489
+ from : path . join ( config , 'config.js' ) ,
490
+ to : path . join ( output , 'config' , 'config.js' ) ,
491
+ } ,
492
+ {
493
+ from : path . join ( config , '@types' , 'index.js' ) ,
494
+ to : path . join ( output , 'config' , '@types' , 'index.js' ) ,
495
+ } ,
496
+ {
497
+ from : path . join ( src , 'index.js' ) ,
498
+ to : path . join ( output , 'src' , 'index.js' ) ,
499
+ } ,
500
+ {
501
+ from : path . join ( src , 'utils' , 'index.js' ) ,
502
+ to : path . join ( output , 'src' , 'utils' , 'index.js' ) ,
503
+ } ,
504
+ {
505
+ from : path . join ( src , 'utils' , 'utils.js' ) ,
506
+ to : path . join ( output , 'src' , 'utils' , 'utils.js' ) ,
507
+ } ,
508
+ ] ;
509
+ // When
510
+ result = await copyFiles ( input , output , useExtension , forceDirectory , ignore ) ;
511
+ // Then
512
+ expect ( sortResults ( result ) ) . toEqual ( sortResults ( expectedResult ) ) ;
513
+ expect ( fs . readdir ) . toHaveBeenCalledTimes ( 6 ) ;
514
+ expect ( fs . readdir ) . toHaveBeenNthCalledWith ( 1 , src ) ;
515
+ expect ( fs . readdir ) . toHaveBeenNthCalledWith ( 2 , config ) ;
516
+ expect ( fs . readdir ) . toHaveBeenNthCalledWith ( 3 , path . join ( src , 'utils' ) ) ;
517
+ expect ( fs . stat ) . toHaveBeenCalledTimes (
518
+ filesSrc . length +
519
+ filesUtils . length +
520
+ filesUtilsTypes . length +
521
+ filesNodeModules . length +
522
+ filesConfig . length +
523
+ filesConfigTypes . length -
524
+ 1 , // .eslintrc
525
+ ) ;
526
+ expect ( fs . ensureDir ) . toHaveBeenCalledTimes ( 5 ) ;
527
+ expect ( fs . ensureDir ) . toHaveBeenNthCalledWith ( 1 , path . join ( output , 'config' ) ) ;
528
+ expect ( fs . ensureDir ) . toHaveBeenNthCalledWith (
529
+ 2 ,
530
+ path . join ( output , 'config' , '@types' ) ,
531
+ ) ;
532
+ expect ( fs . ensureDir ) . toHaveBeenNthCalledWith ( 3 , path . join ( output , 'src' ) ) ;
533
+ expect ( fs . ensureDir ) . toHaveBeenNthCalledWith ( 4 , path . join ( output , 'src' , 'utils' ) ) ;
534
+ expect ( fs . ensureDir ) . toHaveBeenNthCalledWith ( 5 , path . join ( output , 'src' , 'utils' ) ) ;
535
+ expect ( fs . copyFile ) . toHaveBeenCalledTimes ( expectedResult . length ) ;
536
+ expectedResult . forEach ( ( item , index ) => {
537
+ expect ( fs . copyFile ) . toHaveBeenNthCalledWith ( index + 1 , item . from , item . to ) ;
538
+ } ) ;
539
+ } ) ;
540
+
432
541
it ( 'should copy a directory and change the extensions to .mjs' , async ( ) => {
433
542
// Given
434
543
const src = path . join ( cwd , 'src' ) ;
@@ -465,7 +574,7 @@ describe('index', () => {
465
574
// When
466
575
result = await copyFiles ( input , output , useExtension , forceDirectory ) ;
467
576
// Then
468
- expect ( sortResults ( result ) ) . toEqual ( expectedResult ) ;
577
+ expect ( sortResults ( result ) ) . toEqual ( sortResults ( expectedResult ) ) ;
469
578
expect ( fs . readdir ) . toHaveBeenCalledTimes ( 2 ) ;
470
579
expect ( fs . readdir ) . toHaveBeenNthCalledWith ( 1 , src ) ;
471
580
expect ( fs . readdir ) . toHaveBeenNthCalledWith ( 2 , path . join ( src , 'utils' ) ) ;
0 commit comments