@@ -542,6 +542,124 @@ describe('symlink stream', function() {
542
542
] , assert ) ;
543
543
} ) ;
544
544
545
+ it ( 'does not overwrite links with overwrite option set to false' , function ( done ) {
546
+ var existingContents = 'Lorem Ipsum' ;
547
+
548
+ var file = new File ( {
549
+ base : inputBase ,
550
+ path : inputPath ,
551
+ contents : null ,
552
+ } ) ;
553
+
554
+ function assert ( files ) {
555
+ var outputContents = fs . readFileSync ( outputPath , 'utf8' ) ;
556
+
557
+ expect ( files . length ) . toEqual ( 1 ) ;
558
+ expect ( outputContents ) . toEqual ( existingContents ) ;
559
+ }
560
+
561
+ // Write expected file which should not be overwritten
562
+ fs . mkdirSync ( outputBase ) ;
563
+ fs . writeFileSync ( outputPath , existingContents ) ;
564
+
565
+ pipe ( [
566
+ from . obj ( [ file ] ) ,
567
+ vfs . symlink ( outputBase , { overwrite : false } ) ,
568
+ concat ( assert ) ,
569
+ ] , done ) ;
570
+ } ) ;
571
+
572
+ it ( 'overwrites links with overwrite option set to true' , function ( done ) {
573
+ var existingContents = 'Lorem Ipsum' ;
574
+
575
+ var file = new File ( {
576
+ base : inputBase ,
577
+ path : inputPath ,
578
+ contents : null ,
579
+ } ) ;
580
+
581
+ function assert ( files ) {
582
+ var outputContents = fs . readFileSync ( outputPath , 'utf8' ) ;
583
+
584
+ expect ( files . length ) . toEqual ( 1 ) ;
585
+ expect ( outputContents ) . toEqual ( contents ) ;
586
+ }
587
+
588
+ // This should be overwritten
589
+ fs . mkdirSync ( outputBase ) ;
590
+ fs . writeFileSync ( outputPath , existingContents ) ;
591
+
592
+ pipe ( [
593
+ from . obj ( [ file ] ) ,
594
+ vfs . symlink ( outputBase , { overwrite : true } ) ,
595
+ concat ( assert ) ,
596
+ ] , done ) ;
597
+ } ) ;
598
+
599
+ it ( 'does not overwrite links with overwrite option set to a function that returns false' , function ( done ) {
600
+ var existingContents = 'Lorem Ipsum' ;
601
+
602
+ var file = new File ( {
603
+ base : inputBase ,
604
+ path : inputPath ,
605
+ contents : null ,
606
+ } ) ;
607
+
608
+ function overwrite ( f ) {
609
+ expect ( f ) . toEqual ( file ) ;
610
+ return false ;
611
+ }
612
+
613
+ function assert ( files ) {
614
+ var outputContents = fs . readFileSync ( outputPath , 'utf8' ) ;
615
+
616
+ expect ( files . length ) . toEqual ( 1 ) ;
617
+ expect ( outputContents ) . toEqual ( existingContents ) ;
618
+ }
619
+
620
+ // Write expected file which should not be overwritten
621
+ fs . mkdirSync ( outputBase ) ;
622
+ fs . writeFileSync ( outputPath , existingContents ) ;
623
+
624
+ pipe ( [
625
+ from . obj ( [ file ] ) ,
626
+ vfs . symlink ( outputBase , { overwrite : overwrite } ) ,
627
+ concat ( assert ) ,
628
+ ] , done ) ;
629
+ } ) ;
630
+
631
+ it ( 'overwrites links with overwrite option set to a function that returns true' , function ( done ) {
632
+ var existingContents = 'Lorem Ipsum' ;
633
+
634
+ var file = new File ( {
635
+ base : inputBase ,
636
+ path : inputPath ,
637
+ contents : null ,
638
+ } ) ;
639
+
640
+ function overwrite ( f ) {
641
+ expect ( f ) . toEqual ( file ) ;
642
+ return true ;
643
+ }
644
+
645
+ function assert ( files ) {
646
+ var outputContents = fs . readFileSync ( outputPath , 'utf8' ) ;
647
+
648
+ expect ( files . length ) . toEqual ( 1 ) ;
649
+ expect ( outputContents ) . toEqual ( contents ) ;
650
+ }
651
+
652
+ // This should be overwritten
653
+ fs . mkdirSync ( outputBase ) ;
654
+ fs . writeFileSync ( outputPath , existingContents ) ;
655
+
656
+ pipe ( [
657
+ from . obj ( [ file ] ) ,
658
+ vfs . symlink ( outputBase , { overwrite : overwrite } ) ,
659
+ concat ( assert ) ,
660
+ ] , done ) ;
661
+ } ) ;
662
+
545
663
it ( 'emits an end event' , function ( done ) {
546
664
var symlinkStream = vfs . symlink ( outputBase ) ;
547
665
0 commit comments