-
Notifications
You must be signed in to change notification settings - Fork 1
/
mod.test.ts
53 lines (43 loc) · 1.18 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
import { stub } from "https://deno.land/[email protected]/testing/mock.ts";
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
Deno.test("it generates bindings for llvm-14", async () => {
await stubWrites(async () => {
const path = chdir("./examples/llvm-c-14");
await import(`${path}/build.ts`);
});
});
Deno.test("it generates bindings for sqlite3", async () => {
await stubWrites(async () => {
const path = chdir("./examples/sqlite3");
await import(`${path}/build.ts`);
});
});
Deno.test("it generates bindings for lua", async () => {
await stubWrites(async () => {
const path = chdir("./examples/lua");
await import(`${path}/build.ts`);
});
});
// utils
async function stubWrites(fn: () => unknown) {
const writeTextFile = stub(
Deno,
"writeTextFile",
async (path, dataToWrite) => {
const data = await Deno.readTextFile(path);
assertEquals(dataToWrite, data);
},
);
try {
await fn();
} finally {
writeTextFile.restore();
}
}
function chdir(path: string) {
const resolvedPath = import.meta
.resolve(path)
.slice("file://".length);
Deno.chdir(resolvedPath);
return resolvedPath;
}