@@ -401,8 +401,8 @@ for (const type of apiTypes) {
401401 const api = new fdir ( {
402402 fs : fakeFs ,
403403 } ) . crawl ( "node_modules" ) ;
404- await api [ type ] ( ) ;
405- if ( type === "withPromise" ) {
404+ await execute ( api , type ) ;
405+ if ( type === "withPromise" || type === "withIterator" ) {
406406 t . expect ( readdirStub ) . toHaveBeenCalled ( ) ;
407407 } else {
408408 t . expect ( readdirSyncStub ) . toHaveBeenCalled ( ) ;
@@ -491,3 +491,27 @@ test(`do not convert \\\\ to \\`, async (t) => {
491491 "\\\\wsl.localhost\\Ubuntu\\home\\"
492492 ) ;
493493} ) ;
494+
495+ test ( "interrupted iterator should stop yielding results" , async ( t ) => {
496+ const api = new fdir ( ) . crawl ( "./src" ) ;
497+ const iterator = api . withIterator ( ) [ Symbol . asyncIterator ] ( ) ;
498+ const results : string [ ] = [ ] ;
499+ let next = await iterator . next ( ) ;
500+ do {
501+ results . push ( next . value ) ;
502+ iterator . return ?.( ) ;
503+ } while ( next . done !== false ) ;
504+ t . expect ( results . length ) . toBe ( 1 ) ;
505+ } ) ;
506+
507+ test ( "aborted iterator should stop yielding results" , async ( t ) => {
508+ const aborter = new AbortController ( ) ;
509+ const api = new fdir ( ) . withAbortSignal ( aborter . signal ) . crawl ( "./src" ) ;
510+ const iterator = api . withIterator ( ) ;
511+ const results : string [ ] = [ ] ;
512+ for await ( const value of iterator ) {
513+ results . push ( value ) ;
514+ aborter . abort ( ) ;
515+ }
516+ t . expect ( results . length ) . toBe ( 1 ) ;
517+ } ) ;
0 commit comments