@@ -7,6 +7,9 @@ import { convertSlashes } from "../src/utils";
77import picomatch from "picomatch" ;
88import { apiTypes , APITypes , cwd , restricted , root , execute } from "./utils" ;
99
10+ // AbortController is not present on Node v14
11+ const hasAbortController = "AbortController" in globalThis ;
12+
1013beforeEach ( ( ) => {
1114 mock . restore ( ) ;
1215} ) ;
@@ -410,9 +413,9 @@ for (const type of apiTypes) {
410413 } ) ;
411414}
412415
413- // AbortController is not present on Node v14
414- if ( "AbortController" in globalThis ) {
415- test ( `[async] crawl directory & use abort signal to abort` , async ( t ) => {
416+ test . runIf ( hasAbortController ) (
417+ `[async] crawl directory & use abort signal to abort` ,
418+ async ( t ) => {
416419 const totalFiles = new fdir ( ) . onlyCounts ( ) . crawl ( "node_modules" ) . sync ( ) ;
417420 const abortController = new AbortController ( ) ;
418421 const api = new fdir ( )
@@ -424,8 +427,8 @@ if ("AbortController" in globalThis) {
424427 . crawl ( "node_modules" ) ;
425428 const files = await api . withPromise ( ) ;
426429 t . expect ( files . length ) . toBeLessThan ( totalFiles . files ) ;
427- } ) ;
428- }
430+ }
431+ ) ;
429432
430433test ( `paths should never start with ./` , async ( t ) => {
431434 const apis = [
@@ -504,14 +507,17 @@ test("interrupted iterator should stop yielding results", async (t) => {
504507 t . expect ( results . length ) . toBe ( 1 ) ;
505508} ) ;
506509
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 ( ) ;
510+ test . runIf ( hasAbortController ) (
511+ "aborted iterator should stop yielding results" ,
512+ async ( t ) => {
513+ const aborter = new AbortController ( ) ;
514+ const api = new fdir ( ) . withAbortSignal ( aborter . signal ) . crawl ( "./src" ) ;
515+ const iterator = api . withIterator ( ) ;
516+ const results : string [ ] = [ ] ;
517+ for await ( const value of iterator ) {
518+ results . push ( value ) ;
519+ aborter . abort ( ) ;
520+ }
521+ t . expect ( results . length ) . toBe ( 1 ) ;
515522 }
516- t . expect ( results . length ) . toBe ( 1 ) ;
517- } ) ;
523+ ) ;
0 commit comments