@@ -771,13 +771,13 @@ describe('Promises API', () => {
771771 vol . fromJSON ( {
772772 '/foo' : 'bar' ,
773773 } ) ;
774-
774+
775775 const watcher = promises . watch ( '/foo' ) ;
776776 expect ( typeof watcher [ Symbol . asyncIterator ] ) . toBe ( 'function' ) ;
777777 expect ( typeof watcher . next ) . toBe ( 'function' ) ;
778778 expect ( typeof watcher . return ) . toBe ( 'function' ) ;
779779 expect ( typeof watcher . throw ) . toBe ( 'function' ) ;
780-
780+
781781 // Clean up
782782 if ( watcher . return ) {
783783 await watcher . return ( ) ;
@@ -790,10 +790,10 @@ describe('Promises API', () => {
790790 vol . fromJSON ( {
791791 '/foo' : 'bar' ,
792792 } ) ;
793-
793+
794794 const watcher = promises . watch ( '/foo' ) ;
795795 const events : Array < { eventType : string ; filename : string | Buffer } > = [ ] ;
796-
796+
797797 // Start watching
798798 const watchPromise = ( async ( ) => {
799799 const iterator = watcher [ Symbol . asyncIterator ] ( ) ;
@@ -805,15 +805,15 @@ describe('Promises API', () => {
805805 await iterator . return ( ) ;
806806 }
807807 } ) ( ) ;
808-
808+
809809 // Give watcher time to start
810810 await new Promise ( resolve => setTimeout ( resolve , 10 ) ) ;
811-
811+
812812 // Modify the file
813813 vol . writeFileSync ( '/foo' , 'baz' ) ;
814-
814+
815815 await watchPromise ;
816-
816+
817817 expect ( events ) . toHaveLength ( 1 ) ;
818818 expect ( events [ 0 ] . eventType ) . toBe ( 'change' ) ;
819819 expect ( events [ 0 ] . filename ) . toBe ( 'foo' ) ;
@@ -825,13 +825,13 @@ describe('Promises API', () => {
825825 vol . fromJSON ( {
826826 '/foo' : 'bar' ,
827827 } ) ;
828-
828+
829829 const abortController = new AbortController ( ) ;
830830 const watcher = promises . watch ( '/foo' , { signal : abortController . signal } ) ;
831-
831+
832832 // Abort immediately
833833 abortController . abort ( ) ;
834-
834+
835835 const iterator = watcher [ Symbol . asyncIterator ] ( ) ;
836836 const result = await iterator . next ( ) ;
837837 expect ( result . done ) . toBe ( true ) ;
@@ -843,18 +843,18 @@ describe('Promises API', () => {
843843 vol . fromJSON ( {
844844 '/foo' : 'bar' ,
845845 } ) ;
846-
846+
847847 const watcher = promises . watch ( '/foo' , { maxQueue : 1 , overflow : 'ignore' } ) ;
848-
848+
849849 // Generate multiple events quickly
850850 vol . writeFileSync ( '/foo' , 'change1' ) ;
851851 vol . writeFileSync ( '/foo' , 'change2' ) ;
852852 vol . writeFileSync ( '/foo' , 'change3' ) ;
853-
853+
854854 const iterator = watcher [ Symbol . asyncIterator ] ( ) ;
855855 const result1 = await iterator . next ( ) ;
856856 expect ( result1 . done ) . toBe ( false ) ;
857-
857+
858858 if ( iterator . return ) {
859859 await iterator . return ( ) ;
860860 }
@@ -866,103 +866,14 @@ describe('Promises API', () => {
866866 vol . fromJSON ( {
867867 '/foo' : 'bar' ,
868868 } ) ;
869-
869+
870870 const watcher = promises . watch ( '/foo' , { maxQueue : 1 , overflow : 'throw' } ) ;
871-
871+
872872 // This test is tricky because we need to ensure the overflow happens
873873 // We can't easily test this synchronously, so we'll skip for now
874874 if ( watcher . return ) {
875875 await watcher . return ( ) ;
876876 }
877877 } ) ;
878878 } ) ;
879-
880- describe ( 'watchFile(filename[, options])' , ( ) => {
881- it ( 'Returns an AsyncIterableIterator' , async ( ) => {
882- const vol = new Volume ( ) ;
883- const { promises } = vol ;
884- vol . fromJSON ( {
885- '/foo' : 'bar' ,
886- } ) ;
887-
888- const watcher = promises . watchFile ( '/foo' ) ;
889- expect ( typeof watcher [ Symbol . asyncIterator ] ) . toBe ( 'function' ) ;
890- expect ( typeof watcher . next ) . toBe ( 'function' ) ;
891- expect ( typeof watcher . return ) . toBe ( 'function' ) ;
892- expect ( typeof watcher . throw ) . toBe ( 'function' ) ;
893-
894- // Clean up
895- if ( watcher . return ) {
896- await watcher . return ( ) ;
897- }
898- } ) ;
899-
900- it ( 'Emits stat change events when file is modified' , async ( ) => {
901- const vol = new Volume ( ) ;
902- const { promises } = vol ;
903- vol . fromJSON ( {
904- '/foo' : 'bar' ,
905- } ) ;
906-
907- const watcher = promises . watchFile ( '/foo' , { interval : 1 } ) ;
908- const events : Array < { curr : any ; prev : any } > = [ ] ;
909-
910- // Start watching
911- const watchPromise = ( async ( ) => {
912- const iterator = watcher [ Symbol . asyncIterator ] ( ) ;
913- const result = await iterator . next ( ) ;
914- if ( ! result . done ) {
915- events . push ( result . value ) ;
916- }
917- if ( iterator . return ) {
918- await iterator . return ( ) ;
919- }
920- } ) ( ) ;
921-
922- // Give watcher time to start
923- await new Promise ( resolve => setTimeout ( resolve , 10 ) ) ;
924-
925- // Modify the file
926- vol . writeFileSync ( '/foo' , 'modified content' ) ;
927-
928- await watchPromise ;
929-
930- expect ( events ) . toHaveLength ( 1 ) ;
931- expect ( events [ 0 ] . curr ) . toBeDefined ( ) ;
932- expect ( events [ 0 ] . prev ) . toBeDefined ( ) ;
933- expect ( events [ 0 ] . curr . isFile ( ) ) . toBe ( true ) ;
934- expect ( events [ 0 ] . prev . isFile ( ) ) . toBe ( true ) ;
935- } ) ;
936-
937- it ( 'Works with for-await loops' , async ( ) => {
938- const vol = new Volume ( ) ;
939- const { promises } = vol ;
940- vol . fromJSON ( {
941- '/test.txt' : 'initial' ,
942- } ) ;
943-
944- const watcher = promises . watch ( '/test.txt' ) ;
945- const events : Array < { eventType : string ; filename : string | Buffer } > = [ ] ;
946-
947- // Start the for-await loop
948- const watchPromise = ( async ( ) => {
949- for await ( const event of watcher ) {
950- events . push ( event ) ;
951- if ( events . length >= 2 ) {
952- break ;
953- }
954- }
955- } ) ( ) ;
956-
957- // Generate events
958- setTimeout ( ( ) => vol . writeFileSync ( '/test.txt' , 'change1' ) , 10 ) ;
959- setTimeout ( ( ) => vol . writeFileSync ( '/test.txt' , 'change2' ) , 15 ) ;
960-
961- await watchPromise ;
962-
963- expect ( events ) . toHaveLength ( 2 ) ;
964- expect ( events [ 0 ] . eventType ) . toBe ( 'change' ) ;
965- expect ( events [ 1 ] . eventType ) . toBe ( 'change' ) ;
966- } ) ;
967- } ) ;
968879} ) ;
0 commit comments