@@ -3,6 +3,8 @@ import sinon from "sinon";
33import esmock from "esmock" ;
44import path from "node:path" ;
55import { createAdapter } from "../../../lib/resourceFactory.js" ;
6+ import { fileURLToPath } from "node:url" ;
7+ import Resource from "../../../lib/Resource.js" ;
68
79test ( "glob resources from application.a w/ virtual base path prefix" , async ( t ) => {
810 const readerWriter = createAdapter ( {
@@ -582,3 +584,50 @@ test("byPath with useGitignore: true", async (t) => {
582584
583585 t . is ( isGitIgnoredSpy . callCount , 1 , "isGitIgnored should only be called once per FileSystem instance" ) ;
584586} ) ;
587+
588+ test ( "byGlob with a larger number of results" , async ( t ) => {
589+ const globbyStub = sinon . stub ( ) . callsFake ( async ( _patterns , _options ) => {
590+ return Array . from ( { length : 1_000_000 } ) . map ( ( _ , i ) => `/file${ i } .js` ) ;
591+ } ) ;
592+
593+ const fakeStat = {
594+ isFile : ( ) => true ,
595+ isDirectory : ( ) => false
596+ } ;
597+
598+ const FileSystem = await esmock ( "../../../lib/adapters/FileSystem.js" , {
599+ "globby" : {
600+ globby : globbyStub ,
601+ isGitIgnored : async ( ) => false
602+ } ,
603+ "graceful-fs" : {
604+ stat : ( ( filePath , cb ) => {
605+ if ( filePath . startsWith ( fsBasePath ) ) {
606+ cb ( null , fakeStat ) ;
607+ } else {
608+ cb ( { code : "ENOENT" } ) ;
609+ }
610+ } )
611+ }
612+ } ) ;
613+
614+ const fsBasePath = fileURLToPath ( new URL ( "../../tmp/virtual/large-project/" , import . meta. url ) ) ;
615+
616+ const reader = new FileSystem ( {
617+ fsBasePath,
618+ virBasePath : "/"
619+ } ) ;
620+
621+ const resources = await reader . byGlob ( "/**/*.js" ) ;
622+
623+ t . is ( resources . length , 1_000_000 ) ;
624+
625+ // Picking just one resource in between for testing
626+ const resource = resources [ 500_000 ] ;
627+
628+ t . true ( resource instanceof Resource , "Resource should be an instance of Resource" ) ;
629+ t . true (
630+ resource . getPath ( ) . startsWith ( "/file" ) && resource . getPath ( ) . endsWith ( ".js" ) ,
631+ "Resource should have correct path"
632+ ) ;
633+ } ) ;
0 commit comments