-
Notifications
You must be signed in to change notification settings - Fork 16
/
test.ts
61 lines (56 loc) · 1.49 KB
/
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
// Copyright 2018-2024 the Deno authors. MIT license.
import { assertEquals } from "@std/assert";
import { createGraph } from "@deno/graph";
import { join } from "@std/path";
import { createCache } from "./mod.ts";
import { assert } from "./util.ts";
Deno.test({
name: "createCache()",
async fn() {
const cache = createCache();
const { load } = cache;
for (let i = 0; i < 2; i++) {
const graph = await createGraph(
"https://deno.land/x/oak@v10.5.1/mod.ts",
{
load,
},
);
assertEquals(graph.modules.length, 59);
}
},
});
Deno.test({
name: "createCache() - local vendor folder",
async fn() {
await withTempDir(async (tempDir) => {
const vendorRoot = join(tempDir, "vendor");
const cache = createCache({
vendorRoot,
});
for (let i = 0; i < 2; i++) {
const { load } = cache;
const graph = await createGraph(
"https://deno.land/x/oak@v10.5.1/mod.ts",
{
load,
},
);
assertEquals(graph.modules.length, 59);
assert(Deno.statSync(vendorRoot).isDirectory);
assert(
Deno.statSync(join(vendorRoot, "deno.land", "x", "oak@v10.5.1"))
.isDirectory,
);
}
});
},
});
async function withTempDir(fn: (tempDir: string) => Promise<void>) {
const tempDir = Deno.makeTempDirSync();
try {
return await fn(tempDir);
} finally {
Deno.removeSync(tempDir, { recursive: true });
}
}