@@ -12,6 +12,14 @@ import Transport from "winston-transport";
1212import logger from "../lib/util/logger" ;
1313import * as settings from "../lib/util/settings" ;
1414
15+ vi . mock ( "rimraf" , async ( importOriginal ) => {
16+ const actual = await importOriginal < typeof import ( "rimraf" ) > ( ) ;
17+ return {
18+ ...actual ,
19+ rimrafSync : vi . fn ( actual . rimrafSync ) ,
20+ } ;
21+ } ) ;
22+
1523describe ( "Logger" , ( ) => {
1624 let consoleWriteSpy : MockInstance ;
1725 const dir = tmp . dirSync ( ) ;
@@ -59,6 +67,24 @@ describe("Logger", () => {
5967 expect ( fs . readdirSync ( dir . name ) . length ) . toBe ( 10 ) ;
6068 } ) ;
6169
70+ it ( "Should handle cleanup error" , ( ) => {
71+ for ( const d of fs . readdirSync ( dir . name ) ) {
72+ rimrafSync ( path . join ( dir . name , d ) ) ;
73+ }
74+
75+ for ( let i = 0 ; i < 20 ; i ++ ) {
76+ fs . mkdirSync ( path . join ( dir . name , `log_${ i } ` ) ) ;
77+ }
78+
79+ vi . mocked ( rimrafSync ) . mockImplementationOnce ( ( ) => {
80+ throw new Error ( "EACCES: permission denied" ) ;
81+ } ) ;
82+
83+ const errorSpy = vi . spyOn ( logger , "error" ) ;
84+ logger . init ( ) ;
85+ expect ( errorSpy ) . toHaveBeenCalledWith ( expect . stringMatching ( / F a i l e d t o r e m o v e o l d l o g d i r e c t o r y ' .* ' : E r r o r : E A C C E S : p e r m i s s i o n d e n i e d / ) ) ;
86+ } ) ;
87+
6288 it ( "Should cleanup (15 folders setting)" , ( ) => {
6389 for ( const d of fs . readdirSync ( dir . name ) ) {
6490 rimrafSync ( path . join ( dir . name , d ) ) ;
0 commit comments