diff --git a/packages/core/src/tests/GenericFileSystem.test.ts b/packages/core/src/tests/GenericFileSystem.test.ts index d86d6c18efff30309aa76a0c862d3afd9941f330..4ae75633255e6999ccf7453c7219081210675189 100644 --- a/packages/core/src/tests/GenericFileSystem.test.ts +++ b/packages/core/src/tests/GenericFileSystem.test.ts @@ -3,6 +3,7 @@ import { getNodeFS, InMemoryFileSystem, exists, + walk, } from "../storage/FileSystem"; import os from "os"; import path from "path"; @@ -99,3 +100,34 @@ describe.each<FileSystemUnderTest>([ }); }); }); + +describe("Test walk for Node.js fs", () => { + const fs = getNodeFS(); + let tempDir: string; + + beforeAll(async () => { + tempDir = await nodeFS.mkdtemp(path.join(os.tmpdir(), "jest-")); + await fs.writeFile(`${tempDir}/test.txt`, "Hello, world!"); + await fs.mkdir(`${tempDir}/subDir`); + await fs.writeFile(`${tempDir}/subDir/test2.txt`, "Hello, again!"); + }); + + it("walks directory", async () => { + const expectedFiles = new Set([ + `${tempDir}/subDir/test2.txt`, + `${tempDir}/test.txt`, + ]); + + const actualFiles = new Set<string>(); + for await (let file of walk(fs, tempDir)) { + expect(file).toBeTruthy(); + actualFiles.add(file); + } + + expect(expectedFiles).toEqual(actualFiles); + }); + + afterAll(async () => { + await nodeFS.rm(tempDir, { recursive: true }); + }); +});