-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.test.ts
37 lines (31 loc) · 1016 Bytes
/
functions.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import * as functional from "./functions.ts";
const __dirname = new URL(".", import.meta.url).pathname;
const collectFileNames = async (path: string, paths: string[] = []) => {
for await (const dirEntry of Deno.readDir(path)) {
if (dirEntry.isFile) {
paths.push(dirEntry.name);
} else if (dirEntry.isDirectory) {
collectFileNames(dirEntry.name, paths);
}
}
return paths;
};
const filterTestFiles = (fileNames: string[]) =>
fileNames.filter(
(name) => !name.includes(".test.") && !name.includes("index"),
);
const sortFiles = (files: string[]) => files.sort();
const getModuleList = () =>
collectFileNames(__dirname + "./functions")
.then(filterTestFiles)
.then(sortFiles)
.catch((reason) => {
throw reason;
});
Deno.test("functions.ts", async () => {
assertEquals(
Object.keys(functional).map((file) => file + ".ts").sort(),
await getModuleList(),
);
});