Skip to content
Snippets Groups Projects
Commit 93c44e1b authored by Sourabh Desai's avatar Sourabh Desai
Browse files

small unit test for walk method

parent 66b6fe51
No related branches found
No related tags found
No related merge requests found
......@@ -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 });
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment