@@ -654,4 +654,94 @@ describe('winston/transports/daily-rotate-file', function () {
654
654
} ) ;
655
655
} ) ;
656
656
} ) ;
657
+
658
+ describe ( 'when zippedArchive is true' , function ( ) {
659
+ var pattern = {
660
+ pattern : '.m' ,
661
+ start : 1861947160000 , // GMT: Mon, 01 Jan 2029 07:32:50 GMT
662
+ mid : 1861947240000 , // GMT: Mon, 01 Jan 2029 07:34:00 GMT
663
+ end : 1861947760000 , // GMT: Mon, 01 Jan 2029 07:42:40 GMT
664
+ oldfile : 'test-rotation.log.32' ,
665
+ midfile : 'test-rotation.log.34' ,
666
+ newfile : 'test-rotation.log.42'
667
+ } ;
668
+
669
+ var transport ;
670
+ var rotationLogPath = path . join ( fixturesDir , 'rotations' ) ;
671
+ beforeEach ( function ( done ) {
672
+ this . time = new Date ( pattern . start ) ;
673
+ tk . travel ( this . time ) ;
674
+ rimraf . sync ( rotationLogPath ) ;
675
+ mkdirp . sync ( rotationLogPath ) ;
676
+ transport = new DailyRotateFile ( {
677
+ filename : path . join ( rotationLogPath , 'test-rotation.log' ) ,
678
+ datePattern : pattern . pattern ,
679
+ zippedArchive : true
680
+ } ) ;
681
+
682
+ done ( ) ;
683
+ } ) ;
684
+
685
+ afterEach ( function ( ) {
686
+ tk . reset ( ) ;
687
+ } ) ;
688
+
689
+ it ( 'should compress logfile without adding count to file extension if there are no files with the same name' , function ( done ) {
690
+ var self = this ;
691
+
692
+ transport . log ( 'error' , 'test message' , { } , function ( err ) {
693
+ if ( err ) {
694
+ done ( err ) ;
695
+ }
696
+ transport . log ( 'error' , 'test message' , { } , function ( err ) {
697
+ if ( err ) {
698
+ done ( err ) ;
699
+ }
700
+
701
+ var filesCreated = fs . readdirSync ( rotationLogPath ) ;
702
+ expect ( filesCreated . length ) . to . eql ( 1 ) ;
703
+ expect ( filesCreated ) . to . include ( pattern . oldfile ) ;
704
+ self . time = new Date ( pattern . mid ) ;
705
+ tk . travel ( self . time ) ;
706
+ transport . log ( 'error' , '2nd test message' , { } , function ( err ) {
707
+ if ( err ) {
708
+ done ( err ) ;
709
+ }
710
+ transport . log ( 'error' , 'test message' , { } , function ( err ) {
711
+ if ( err ) {
712
+ done ( err ) ;
713
+ }
714
+
715
+ filesCreated = fs . readdirSync ( rotationLogPath ) ;
716
+ expect ( filesCreated . length ) . to . eql ( 2 ) ;
717
+ expect ( filesCreated ) . to . include ( pattern . oldfile + '.gz' ) ;
718
+ expect ( filesCreated ) . to . include ( pattern . midfile ) ;
719
+ self . time = new Date ( pattern . end ) ;
720
+ tk . travel ( self . time ) ;
721
+ transport . log ( 'error' , '3rd test message' , { } , function ( err ) {
722
+ if ( err ) {
723
+ done ( err ) ;
724
+ }
725
+ transport . log ( 'error' , 'test message' , { } , function ( err ) {
726
+ if ( err ) {
727
+ done ( err ) ;
728
+ }
729
+
730
+ filesCreated = fs . readdirSync ( rotationLogPath ) ;
731
+ expect ( filesCreated . length ) . to . eql ( 3 ) ;
732
+ expect ( filesCreated ) . to . not . include ( pattern . newfile + '.1' ) ;
733
+ expect ( filesCreated ) . to . include ( pattern . newfile ) ;
734
+ expect ( filesCreated ) . to . include ( pattern . midfile + '.gz' ) ;
735
+ expect ( filesCreated ) . to . include ( pattern . oldfile + '.gz' ) ;
736
+ transport . close ( ) ;
737
+
738
+ done ( ) ;
739
+ } ) ;
740
+ } ) ;
741
+ } ) ;
742
+ } ) ;
743
+ } ) ;
744
+ } ) ;
745
+ } ) ;
746
+ } ) ;
657
747
} ) ;
0 commit comments