-
Notifications
You must be signed in to change notification settings - Fork 16
/
file_fetcher_test.ts
80 lines (75 loc) · 2.11 KB
/
file_fetcher_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2018-2024 the Deno authors. MIT license.
import { DenoDir } from "./deno_dir.ts";
import { assertRejects, createGraph } from "./deps_test.ts";
import { FileFetcher } from "./file_fetcher.ts";
Deno.test({
name: "FileFetcher",
async fn() {
const denoDir = new DenoDir();
const fileFetcher = new FileFetcher(() => denoDir.createHttpCache());
const graph = await createGraph("https://deno.land/x/[email protected]/mod.ts", {
load(specifier) {
return fileFetcher.fetch(new URL(specifier));
},
});
// deno-lint-ignore no-console
console.log(graph);
},
});
Deno.test({
name: "FileFetcher - bad checksum no cache",
async fn() {
const denoDir = new DenoDir();
const fileFetcher = new FileFetcher(() => denoDir.createHttpCache());
{
// should error
await assertRejects(async () => {
await fileFetcher.fetchOnce(
new URL("https://deno.land/x/[email protected]/mod.ts"),
{
checksum: "bad",
},
);
});
// ok for good checksum
await fileFetcher.fetchOnce(
new URL("https://deno.land/x/[email protected]/mod.ts"),
{
checksum:
"7a1b5169ef702e96dd994168879dbcbd8af4f639578b6300cbe1c6995d7f3f32",
},
);
}
},
});
Deno.test({
name: "FileFetcher - bad checksum reload",
async fn() {
const denoDir = new DenoDir();
const fileFetcher = new FileFetcher(() => denoDir.createHttpCache());
await assertRejects(async () => {
await fileFetcher.fetchOnce(
new URL("https://deno.land/x/[email protected]/mod.ts"),
{
cacheSetting: "reload",
checksum: "bad",
},
);
});
},
});
Deno.test({
name: "FileFetcher - good checksum reload",
async fn() {
const denoDir = new DenoDir();
const fileFetcher = new FileFetcher(() => denoDir.createHttpCache());
await fileFetcher.fetchOnce(
new URL("https://deno.land/x/[email protected]/mod.ts"),
{
cacheSetting: "reload",
checksum:
"7a1b5169ef702e96dd994168879dbcbd8af4f639578b6300cbe1c6995d7f3f32",
},
);
},
});