Very Popular
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159import { assertEquals as equals } from "../deps/assert.ts";import { getImportMap, isPlainObject, merge, sha1 } from "../core/utils.ts";
Deno.test("merge options", () => { interface Options { foo: string; foo2?: string; }
const defaults: Options = { foo: "bar", }; const user: Partial<Options> = { foo2: "bar2", }; const expected: Options = { foo: "bar", foo2: "bar2", };
equals(expected, merge(defaults, user));});
Deno.test("merge inner options", () => { interface Options { foo: string; foo2: SubOptions; }
interface SubOptions { bar1: string; bar2?: string; bar3?: string; }
const defaults: Options = { foo: "bar", foo2: { bar1: "bar1", bar2: "bar2", }, }; const user: Partial<Options> = { foo: "new bar", foo2: { bar1: "new bar1", bar3: "bar3", }, }; const expected = { foo: "new bar", foo2: { bar1: "new bar1", bar2: "bar2", bar3: "bar3", }, };
equals(expected, merge(defaults, user));});
Deno.test("isPlainObject", () => { equals(isPlainObject({}), true); equals(isPlainObject(new URL("http://localhost")), false); equals(isPlainObject([]), false); equals(isPlainObject(new Map()), false); equals(isPlainObject(new Set()), false); equals(isPlainObject(Symbol.for("foo")), false);});
Deno.test("sha1 function", async () => { const data = "Hello World"; const dataUint8 = new TextEncoder().encode(data); const expected = "\nMUοΏ½οΏ½xοΏ½\x02/οΏ½p\x19wοΏ½οΏ½@οΏ½ΔοΏ½";
equals(await sha1(data), expected); equals(await sha1(dataUint8), expected);});
Deno.test("import map", () => { const map = getImportMap();
equals(map.imports["lume"], new URL("../mod.ts", import.meta.url).href); equals(map.imports["lume/"], new URL("../", import.meta.url).href); equals(map.imports["lume/"], new URL("../", import.meta.url).href);
equals(map, { imports: { "lume": new URL("../mod.ts", import.meta.url).href, "lume/": new URL("../", import.meta.url).href, "https://deno.land/x/lume/": new URL("../", import.meta.url).href, }, });});
Deno.test("merge import map", async () => { const map = await getImportMap({ imports: { "lume": "https://lume.land/lume.ts", "std/": "https://deno.land/std@0.121.0/", "/": "./", }, scopes: { "foo/": { "std/": "https://deno.land/std@0.121.0/foo/", "/": "./foo/", }, }, });
equals(map, { imports: { "lume": "https://lume.land/lume.ts", "lume/": new URL("../", import.meta.url).href, "https://deno.land/x/lume/": new URL("../", import.meta.url).href, "std/": "https://deno.land/std@0.121.0/", "/": "./", }, scopes: { "foo/": { "std/": "https://deno.land/std@0.121.0/foo/", "/": "./foo/", }, }, });});Deno.test("merge and resolve import map", async () => { const path = new URL("./assets/import_map.json", import.meta.url); const map = await getImportMap({ imports: { "lume": "https://lume.land/lume.ts", "std/": "https://deno.land/std@0.121.0/", "/": "./", }, scopes: { "foo/": { "std/": "https://deno.land/std@0.121.0/foo/", "/": "./foo/", }, }, }, path);
equals(map, { imports: { "lume": "https://lume.land/lume.ts", "lume/": new URL("../", import.meta.url).href, "https://deno.land/x/lume/": new URL("../", import.meta.url).href, "std/": "https://deno.land/std@0.121.0/", "/": new URL("./assets/", import.meta.url).href, }, scopes: { "foo/": { "std/": "https://deno.land/std@0.121.0/foo/", "/": new URL("./assets/foo/", import.meta.url).href, }, }, });});