-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathfshelper.js
More file actions
24 lines (19 loc) · 890 Bytes
/
fshelper.js
File metadata and controls
24 lines (19 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import {readdir, readFile} from "node:fs/promises";
import path from "node:path";
export async function findFiles(dirPath) {
const files = await readdir(dirPath, {withFileTypes: true, recursive: true});
return files.filter((file) => file.isFile()).map((file) => path.join(file.parentPath || file.path, file.name));
}
export async function readFileContent(filePath) {
return await readFile(filePath, {encoding: "utf8"});
}
export async function directoryDeepEqual(t, destPath, expectedPath) {
const dest = (await readdir(destPath, {recursive: true})).sort();
const expected = (await readdir(expectedPath, {recursive: true})).sort();
t.deepEqual(dest, expected);
}
export async function fileEqual(t, destPath, expectedPath) {
const destContent = await readFileContent(destPath);
const expectedContent = await readFileContent(expectedPath);
t.is(destContent, expectedContent);
}