Skip to content

Commit

Permalink
add TopLevelAwaitModulePlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
timreichen authored Apr 18, 2021
1 parent c76e819 commit 32331f4
Show file tree
Hide file tree
Showing 67 changed files with 5,932 additions and 4,341 deletions.
11 changes: 11 additions & 0 deletions _util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,14 @@ export function size(size: number) {
const unit = units[index];
return `${Math.ceil(number)}${unit}`;
}

export async function readTextFile(path: string | URL) {
try {
return await Deno.readTextFile(path);
} catch (error) {
if (error instanceof Deno.errors.NotFound) {
error.message += `: ${path}`;
}
throw error;
}
}
160 changes: 96 additions & 64 deletions _util_test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals } from "./test_deps.ts";
import { assertEquals, tests } from "./test_deps.ts";
import {
addRelativePrefix,
ensureExtension,
Expand All @@ -7,72 +7,104 @@ import {
removeRelativePrefix,
} from "./_util.ts";

Deno.test({
name: "[_util] isURL",
fn: () => {
assertEquals(isURL("http://url.com"), true);
assertEquals(isURL("http://url.com/path"), true);
assertEquals(isURL("https://url.com"), true);
assertEquals(isURL("https://url.com/path"), true);
tests({
name: "_util",
tests: () => [
{
name: "isURL",
fn: () => {
assertEquals(isURL("http://url.com"), true);
assertEquals(isURL("http://url.com/path"), true);
assertEquals(isURL("https://url.com"), true);
assertEquals(isURL("https://url.com/path"), true);

assertEquals(isURL("file://path"), true);
assertEquals(isURL("."), false);
assertEquals(isURL("./"), false);
assertEquals(isURL("./relative/path"), false);
assertEquals(isURL("/absolute/path"), false);
},
});
assertEquals(isURL("file://path"), true);
assertEquals(isURL("."), false);
assertEquals(isURL("./"), false);
assertEquals(isURL("./relative/path"), false);
assertEquals(isURL("/absolute/path"), false);
},
},

Deno.test({
name: "[_util] addRelativePrefix",
fn: () => {
assertEquals(addRelativePrefix("a.ts"), "./a.ts");
assertEquals(addRelativePrefix("./a.ts"), "./a.ts");
assertEquals(removeRelativePrefix("http://url.com"), "http://url.com");
assertEquals(removeRelativePrefix("https://url.com"), "https://url.com");
assertEquals(removeRelativePrefix("file://url.com"), "file://url.com");
},
});
{
name: "addRelativePrefix",
fn: () => {
assertEquals(addRelativePrefix("a.ts"), "./a.ts");
assertEquals(addRelativePrefix("./a.ts"), "./a.ts");
assertEquals(removeRelativePrefix("http://url.com"), "http://url.com");
assertEquals(
removeRelativePrefix("https://url.com"),
"https://url.com",
);
assertEquals(removeRelativePrefix("file://url.com"), "file://url.com");
},
},

Deno.test({
name: "[_util] removeRelativePrefix",
fn: () => {
assertEquals(removeRelativePrefix("a.ts"), "a.ts");
assertEquals(removeRelativePrefix("./a.ts"), "a.ts");
assertEquals(removeRelativePrefix("http://url.com"), "http://url.com");
assertEquals(removeRelativePrefix("https://url.com"), "https://url.com");
assertEquals(removeRelativePrefix("file://url.com"), "file://url.com");
},
});
{
name: "removeRelativePrefix",
fn: () => {
assertEquals(removeRelativePrefix("a.ts"), "a.ts");
assertEquals(removeRelativePrefix("./a.ts"), "a.ts");
assertEquals(removeRelativePrefix("http://url.com"), "http://url.com");
assertEquals(
removeRelativePrefix("https://url.com"),
"https://url.com",
);
assertEquals(removeRelativePrefix("file://url.com"), "file://url.com");
},
},

Deno.test({
name: "[_util] removeExtension",
fn: () => {
assertEquals(removeExtension("a.ts"), "a");
assertEquals(removeExtension("./a.ts"), "./a");
assertEquals(removeExtension("a.js"), "a");
assertEquals(removeExtension("http://url.com/a.ts"), "http://url.com/a");
assertEquals(removeExtension("https://url.com/a.ts"), "https://url.com/a");
assertEquals(removeExtension("file://url.com/a.ts"), "file://url.com/a");
},
});
{
name: "removeExtension",
fn: () => {
assertEquals(removeExtension("a.ts"), "a");
assertEquals(removeExtension("./a.ts"), "./a");
assertEquals(removeExtension("a.js"), "a");
assertEquals(
removeExtension("http://url.com/a.ts"),
"http://url.com/a",
);
assertEquals(
removeExtension("https://url.com/a.ts"),
"https://url.com/a",
);
assertEquals(
removeExtension("file://url.com/a.ts"),
"file://url.com/a",
);
},
},

Deno.test({
name: "[_util] ensureExtension",
fn: () => {
assertEquals(ensureExtension("a.ts", ".ts"), "a.ts");
assertEquals(ensureExtension("a", ".js"), "a.js");
assertEquals(ensureExtension("a.ts", ".js"), "a.ts");
assertEquals(ensureExtension("a", ".ts"), "a.ts");
assertEquals(ensureExtension(".", ".ts"), ".");
assertEquals(ensureExtension("./", ".ts"), "./");
assertEquals(ensureExtension("http://url.com", ".ts"), "http://url.com");
assertEquals(ensureExtension("https://url.com", ".ts"), "https://url.com");
assertEquals(ensureExtension("file://url.com", ".ts"), "file://url.com");
assertEquals(
ensureExtension("./relative/path", ".ts"),
"./relative/path.ts",
);
assertEquals(ensureExtension("/absolute/path", ".ts"), "/absolute/path");
},
{
name: "ensureExtension",
fn: () => {
assertEquals(ensureExtension("a.ts", ".ts"), "a.ts");
assertEquals(ensureExtension("a", ".js"), "a.js");
assertEquals(ensureExtension("a.ts", ".js"), "a.ts");
assertEquals(ensureExtension("a", ".ts"), "a.ts");
assertEquals(ensureExtension(".", ".ts"), ".");
assertEquals(ensureExtension("./", ".ts"), "./");
assertEquals(
ensureExtension("http://url.com", ".ts"),
"http://url.com",
);
assertEquals(
ensureExtension("https://url.com", ".ts"),
"https://url.com",
);
assertEquals(
ensureExtension("file://url.com", ".ts"),
"file://url.com",
);
assertEquals(
ensureExtension("./relative/path", ".ts"),
"./relative/path.ts",
);
assertEquals(
ensureExtension("/absolute/path", ".ts"),
"/absolute/path",
);
},
},
],
});
Loading

0 comments on commit 32331f4

Please sign in to comment.