-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.test.ts
48 lines (44 loc) · 1.37 KB
/
index.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
/* eslint-disable yield-star-spacing */
import { readdir } from "node:fs/promises";
import { expect, it, describe } from "vitest";
import data from ".." assert { type: "json" };
function* walk(obj: any, path: string[] = []): Generator<[string[], any]> {
for (const key in obj) {
const value = obj[key];
const currentPath = [...path, key];
if (typeof value === "object") {
yield [currentPath, value];
if (key !== "__compat") {
yield* walk(value, currentPath);
}
}
}
}
const skipKeys = new Set([
"api",
"javascript",
"javascript.builtins",
"api.ReadableStream",
"api.WebSocket",
"api.ReadableStreamDefaultReader",
"api.PerformanceResourceTiming",
"javascript.builtins.Intl.NumberFormat.NumberFormat.options_parameter",
"javascript.builtins.Intl.RelativeTimeFormat.RelativeTimeFormat.options_parameter",
]);
describe("runtime-compat-data", () => {
it("generates valid data", async () => {
const keys = await readdir(
new URL("../../../generator/runtimes", import.meta.url),
);
for (const [path, value] of walk(data)) {
const key = path.join(".");
if (path.at(-1) === "__compat") {
expect(Object.keys(value.support ?? {}), `${key}.support`).toEqual(
keys,
);
} else if (!skipKeys.has(key)) {
expect("__compat" in value, key).toBeTruthy();
}
}
});
});