-
Notifications
You must be signed in to change notification settings - Fork 18
/
util_test.ts
81 lines (74 loc) · 2.61 KB
/
util_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
81
import { assertEquals, assertThrows } from "./test_deps.ts";
import { join } from "./deps.ts";
import {
byteSize,
checkUniqueEntrypoints,
getDependencies,
getLocalDependencies,
getLocalDependencyPaths,
md5,
} from "./util.ts";
const normalize = (p: string) => join(p);
Deno.test("md5 - returns md5 of the given data", () => {
assertEquals(md5("a"), "0cc175b9c0f1b6a831c399e269772661");
assertEquals(md5("b"), "92eb5ffee6ae2fec3ad71c777531578f");
assertEquals(md5("c"), "4a8a08f09d37b73795649038408b5f33");
});
Deno.test("getDependencies - returns dependency specifiers", async () => {
const cwd = Deno.cwd();
assertEquals(
(await getDependencies("testdata/foo.js")).map(normalize),
[
"file://" + join(cwd, "testdata/bar.js"),
"file://" + join(cwd, "testdata/baz.js"),
"file://" + join(cwd, "testdata/foo.js"),
"https://deno.land/[email protected]/_util/assert.ts",
"https://deno.land/[email protected]/_util/os.ts",
"https://deno.land/[email protected]/path/_constants.ts",
"https://deno.land/[email protected]/path/_interface.ts",
"https://deno.land/[email protected]/path/_util.ts",
"https://deno.land/[email protected]/path/common.ts",
"https://deno.land/[email protected]/path/glob.ts",
"https://deno.land/[email protected]/path/mod.ts",
"https://deno.land/[email protected]/path/posix.ts",
"https://deno.land/[email protected]/path/separator.ts",
"https://deno.land/[email protected]/path/win32.ts",
].map(normalize),
);
});
Deno.test("getLocalDependencies - returns local dependency specifiers", async () => {
const cwd = Deno.cwd();
assertEquals(
(await getLocalDependencies("testdata/foo.js")).map(normalize),
[
"file://" + join(cwd, "testdata/bar.js"),
"file://" + join(cwd, "testdata/baz.js"),
"file://" + join(cwd, "testdata/foo.js"),
].map(normalize),
);
});
Deno.test("getLocalDependencyPaths - returns local dependency paths", async () => {
const cwd = Deno.cwd();
assertEquals(
(await getLocalDependencyPaths("testdata/foo.js")).map(normalize),
[
join(cwd, "testdata/bar.js"),
join(cwd, "testdata/baz.js"),
join(cwd, "testdata/foo.js"),
].map(normalize),
);
});
Deno.test("byteSize", () => {
assertEquals(byteSize(345), `345B`);
assertEquals(byteSize(1700), `1.66KB`);
assertEquals(byteSize(1300000), `1.24MB`);
});
Deno.test("checkUniqueEntrypoints", () => {
assertThrows(() => {
checkUniqueEntrypoints(["index.html", "bar/index.html"]);
});
assertThrows(() => {
checkUniqueEntrypoints(["foo/index.html", "bar/index.html"]);
});
checkUniqueEntrypoints(["index.html", "foo.html", "bar.html"]); // doesn't throw
});