@@ -587,6 +587,128 @@ describe('Node Sentinel File Watcher', function() {
587587 } )
588588 ] ) ;
589589 } ) ;
590+
591+ it ( 'Report error on rename watched folder' , async function ( ) {
592+ const inPath = path . join ( workDir , 'test4' ) ;
593+ const renamed = path . join ( workDir , 'test4_renamed' ) ;
594+ let errorOk = false ;
595+ let watch = await nsfw (
596+ inPath ,
597+ ( ) => { } ,
598+ {
599+ errorCallback : ( error ) => {
600+ errorOk = error . message === 'Service shutdown: root path changed (renamed or deleted)' ;
601+ }
602+ }
603+ ) ;
604+ try {
605+ await watch . start ( ) ;
606+ await sleep ( TIMEOUT_PER_STEP ) ;
607+ await fse . rename ( inPath , renamed ) ;
608+ await sleep ( TIMEOUT_PER_STEP ) ;
609+
610+ assert . ok ( errorOk ) ;
611+ } finally {
612+ try {
613+ await watch . stop ( ) ;
614+ } catch ( err ) { /* do nothing */ }
615+ watch = null ;
616+ }
617+ } ) ;
618+
619+ if ( process . platform !== 'win32' ) {
620+ it ( 'Report error on delete watched folder' , async function ( ) {
621+ const inPath = path . join ( workDir , 'test5' ) ;
622+ let errorMsg = '' ;
623+ let watch = await nsfw (
624+ inPath ,
625+ ( ) => { } ,
626+ {
627+ errorCallback : ( error ) => {
628+ errorMsg = error . message ;
629+ }
630+ }
631+ ) ;
632+ try {
633+ await sleep ( 100 ) ;
634+ await watch . start ( ) ;
635+ await sleep ( TIMEOUT_PER_STEP ) ;
636+ await fse . remove ( inPath ) ;
637+ await sleep ( TIMEOUT_PER_STEP ) ;
638+
639+ assert . equal ( errorMsg , 'Service shutdown: root path changed (renamed or deleted)' ) ;
640+ } finally {
641+ try {
642+ await watch . stop ( ) ;
643+ } catch ( err ) { /* do nothing */ }
644+ watch = null ;
645+ }
646+ } ) ;
647+
648+ it ( 'Report error on rename parent of the watched folder' , async function ( ) {
649+ const parentPath = path . join ( workDir , 'test4' ) ;
650+ const renamed = path . join ( workDir , 'test4_renamed' ) ;
651+ const inPath = path . join ( parentPath , 'test4_watched' ) ;
652+ let errorOk = false ;
653+ let watch ;
654+ try {
655+ await fse . mkdir ( inPath ) ;
656+ await sleep ( TIMEOUT_PER_STEP ) ;
657+ watch = await nsfw (
658+ inPath ,
659+ ( ) => { } ,
660+ {
661+ errorCallback : ( error ) => {
662+ errorOk = error . message === 'Service shutdown: root path changed (renamed or deleted)' ;
663+ }
664+ }
665+ ) ;
666+ await watch . start ( ) ;
667+ await sleep ( TIMEOUT_PER_STEP ) ;
668+ await fse . rename ( parentPath , renamed ) ;
669+ await sleep ( TIMEOUT_PER_STEP ) ;
670+
671+ assert . ok ( errorOk ) ;
672+ } finally {
673+ try {
674+ await watch . stop ( ) ;
675+ } catch ( err ) { /* do nothing */ }
676+ watch = null ;
677+ }
678+ } ) ;
679+
680+ it ( 'Report error on delete parent of the watched folder' , async function ( ) {
681+ const parentPath = path . join ( workDir , 'test4' ) ;
682+ const inPath = path . join ( parentPath , 'test4_watched' ) ;
683+ let errorOk = false ;
684+ let watch ;
685+ try {
686+ await fse . mkdir ( inPath ) ;
687+ await sleep ( TIMEOUT_PER_STEP ) ;
688+ watch = await nsfw (
689+ inPath ,
690+ ( ) => { } ,
691+ {
692+ errorCallback : ( error ) => {
693+ errorOk = error . message === 'Service shutdown: root path changed (renamed or deleted)' ;
694+ }
695+ }
696+ ) ;
697+ await watch . start ( ) ;
698+ await sleep ( TIMEOUT_PER_STEP ) ;
699+ await fse . remove ( parentPath ) ;
700+ await sleep ( TIMEOUT_PER_STEP ) ;
701+
702+ assert . ok ( errorOk ) ;
703+ } finally {
704+ try {
705+ await watch . stop ( ) ;
706+ } catch ( err ) { /* do nothing */ }
707+ watch = null ;
708+ }
709+ } ) ;
710+ }
711+
590712 } ) ;
591713
592714 describe ( 'Stress' , function ( ) {
0 commit comments