-
Notifications
You must be signed in to change notification settings - Fork 16
/
cache_test.ts
47 lines (39 loc) · 1.32 KB
/
cache_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
// Copyright 2018-2024 the Deno authors. MIT license.
import { FetchCacher } from "./cache.ts";
import { DenoDir } from "./deno_dir.ts";
import { FileFetcher } from "./file_fetcher.ts";
import { createGraph } from "@deno/graph";
import { assertEquals } from "@std/assert";
async function setup() {
const tempdir = await Deno.makeTempDir({
prefix: "deno_cache_dir_cache_test",
});
const denoDir = new DenoDir(tempdir);
const fileFetcher = new FileFetcher(
() => {
return denoDir.createHttpCache();
},
"use",
true,
);
return new FetchCacher(fileFetcher);
}
Deno.test("FetchCacher#load works with createGraph to deal with a JSR package", async () => {
const fetchCacher = await setup();
const graph = await createGraph("jsr:@deno/[email protected]", {
load: fetchCacher.load,
});
assertEquals(graph.roots, ["jsr:@deno/[email protected]"]);
assertEquals(
graph.redirects["jsr:@deno/[email protected]"],
"https://jsr.io/@deno/gfm/0.9.0/mod.ts",
);
});
Deno.test("FetchCacher#load works with createGraph to deal with a deno.land/x package", async () => {
const fetchCacher = await setup();
const graph = await createGraph("https://deno.land/x/[email protected]/mod.ts", {
load: fetchCacher.load,
});
assertEquals(graph.roots, ["https://deno.land/x/[email protected]/mod.ts"]);
assertEquals(graph.redirects, {});
});