/
server_helpers_test.ts
34 lines (31 loc) · 1.53 KB
/
server_helpers_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
import { assertEquals } from "std/testing/asserts.ts";
import { applyImportMap, restoreUrl, toLocalPath } from "../server/helpers.ts";
Deno.test("lib/helpers.ts: toLocalPath", () => {
assertEquals(toLocalPath("https://foo.com/lib@0.1.0?action"), "/-/foo.com/lib@0.1.0?action");
assertEquals(toLocalPath("https://deno.land/x/aleph@0.1.0/"), "/-/deno.land/x/aleph@0.1.0");
assertEquals(toLocalPath("http://foo.com/bar?lang=us-en"), "/-/http_foo.com/bar?lang=us-en");
assertEquals(toLocalPath("http://foo.com:8080/bar"), "/-/http_foo.com_8080/bar");
assertEquals(toLocalPath("file://foo/bar/"), "file://foo/bar/");
assertEquals(toLocalPath("/foo/bar/"), "/foo/bar/");
});
Deno.test("lib/helpers.ts: restoreUrl", () => {
assertEquals(restoreUrl("/-/foo.com/lib@0.1.0?action"), "https://foo.com/lib@0.1.0?action");
assertEquals(restoreUrl("/-/deno.land/x/aleph@0.1.0"), "https://deno.land/x/aleph@0.1.0");
assertEquals(restoreUrl("/-/http_foo.com/bar?lang=us-en"), "http://foo.com/bar?lang=us-en");
assertEquals(restoreUrl("/-/http_foo.com_8080/bar"), "http://foo.com:8080/bar");
});
Deno.test("lib/helpers.ts: applyImportMap", () => {
const importMap = {
__filename: "",
imports: {
"aleph": "https://deno.land/x/aleph/mod.ts",
"aleph/": "https://deno.land/x/aleph/",
},
scopes: {},
};
assertEquals(applyImportMap("aleph", importMap), "https://deno.land/x/aleph/mod.ts");
assertEquals(
applyImportMap("aleph/framework/react/mod.ts", importMap),
"https://deno.land/x/aleph/framework/react/mod.ts",
);
});