-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
mod_test.ts
62 lines (57 loc) · 1.78 KB
/
mod_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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { assertArrayIncludes } from "@std/assert";
import { basename, globToRegExp } from "@std/path";
import { parse } from "@std/jsonc";
import { ensure } from "./ensure.ts";
import { is } from "./is/mod.ts";
const excludes = [
"mod.ts",
"_*.ts",
"*_bench.ts",
"*_test.ts",
];
Deno.test("JSR exports must have all `as` modules", async () => {
const moduleNames = await listModuleNames(
new URL(import.meta.resolve("./as")),
);
const jsrExports = await loadJsrExports();
assertArrayIncludes(Object.entries(jsrExports.exports), [
["./as", "./as/mod.ts"],
...moduleNames.map((
v,
) => [`./as/${v.replaceAll("_", "-")}`, `./as/${v}.ts`]),
]);
});
Deno.test("JSR exports must have all `is` modules", async () => {
const moduleNames = await listModuleNames(
new URL(import.meta.resolve("./is")),
);
const jsrExports = await loadJsrExports();
assertArrayIncludes(Object.entries(jsrExports.exports), [
["./is", "./is/mod.ts"],
...moduleNames.map((
v,
) => [`./is/${v.replaceAll("_", "-")}`, `./is/${v}.ts`]),
]);
});
async function listModuleNames(path: URL | string): Promise<string[]> {
const patterns = excludes.map((p) => globToRegExp(p));
const names: string[] = [];
for await (const entry of Deno.readDir(path)) {
if (!entry.isFile || !entry.name.endsWith(".ts")) continue;
if (patterns.some((p) => p.test(entry.name))) continue;
names.push(basename(entry.name, ".ts"));
}
return names;
}
async function loadJsrExports(): Promise<{ exports: Record<string, string> }> {
const text = await Deno.readTextFile(
new URL(import.meta.resolve("./deno.jsonc")),
);
const json = ensure(
parse(text),
is.ObjectOf({
exports: is.RecordOf(is.String, is.String),
}),
);
return { exports: json.exports };
}