summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2020-11-02 13:51:56 +1100
committerGitHub <noreply@github.com>2020-11-02 13:51:56 +1100
commitfdcc78500cc1aff8c87d76abd1692e79977ac9cc (patch)
treeb3ce97db2d23344c9469d9488097601058b5e0e5 /cli/tests
parent3558769d4654aad478804e506ccdcac38881dac1 (diff)
refactor(cli): migrate runtime compile/bundle to new infrastructure (#8192)
Fixes #8060
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/compiler_api_test.ts135
-rw-r--r--cli/tests/compiler_js_error.ts1
-rw-r--r--cli/tests/compiler_js_error.ts.out4
-rw-r--r--cli/tests/integration_tests.rs6
-rw-r--r--cli/tests/lib_ref.ts6
-rw-r--r--cli/tests/lib_ref.ts.out2
-rw-r--r--cli/tests/lib_runtime_api.ts6
-rw-r--r--cli/tests/lib_runtime_api.ts.out2
8 files changed, 55 insertions, 107 deletions
diff --git a/cli/tests/compiler_api_test.ts b/cli/tests/compiler_api_test.ts
index a845e58c6..a236a3f3f 100644
--- a/cli/tests/compiler_api_test.ts
+++ b/cli/tests/compiler_api_test.ts
@@ -14,12 +14,11 @@ Deno.test({
});
assert(diagnostics == null);
assert(actual);
- assertEquals(Object.keys(actual), [
- "/bar.js.map",
- "/bar.js",
- "/foo.js.map",
- "/foo.js",
- ]);
+ const keys = Object.keys(actual).sort();
+ assert(keys[0].endsWith("/bar.ts.js"));
+ assert(keys[1].endsWith("/bar.ts.js.map"));
+ assert(keys[2].endsWith("/foo.ts.js"));
+ assert(keys[3].endsWith("/foo.ts.js.map"));
},
});
@@ -29,10 +28,10 @@ Deno.test({
const [diagnostics, actual] = await Deno.compile("./subdir/mod1.ts");
assert(diagnostics == null);
assert(actual);
- const keys = Object.keys(actual);
+ const keys = Object.keys(actual).sort();
assertEquals(keys.length, 6);
- assert(keys[0].endsWith("print_hello.js.map"));
- assert(keys[1].endsWith("print_hello.js"));
+ assert(keys[0].endsWith("cli/tests/subdir/mod1.ts.js"));
+ assert(keys[1].endsWith("cli/tests/subdir/mod1.ts.js.map"));
},
});
@@ -51,8 +50,11 @@ Deno.test({
);
assert(diagnostics == null);
assert(actual);
- assertEquals(Object.keys(actual), ["/foo.js"]);
- assert(actual["/foo.js"].startsWith("define("));
+ const keys = Object.keys(actual);
+ assertEquals(keys.length, 1);
+ const key = keys[0];
+ assert(key.endsWith("/foo.ts.js"));
+ assert(actual[key].startsWith("define("));
},
});
@@ -60,9 +62,9 @@ Deno.test({
name: "Deno.compile() - pass lib in compiler options",
async fn() {
const [diagnostics, actual] = await Deno.compile(
- "/foo.ts",
+ "file:///foo.ts",
{
- "/foo.ts": `console.log(document.getElementById("foo"));
+ "file:///foo.ts": `console.log(document.getElementById("foo"));
console.log(Deno.args);`,
},
{
@@ -71,45 +73,37 @@ Deno.test({
);
assert(diagnostics == null);
assert(actual);
- assertEquals(Object.keys(actual), ["/foo.js.map", "/foo.js"]);
- },
-});
-
-Deno.test({
- name: "Deno.compile() - pass outDir in compiler options",
- async fn() {
- const [diagnostics, actual] = await Deno.compile(
- "src/foo.ts",
- {
- "src/foo.ts": "console.log('Hello world')",
- },
- {
- outDir: "./lib",
- },
+ assertEquals(
+ Object.keys(actual).sort(),
+ ["file:///foo.ts.js", "file:///foo.ts.js.map"],
);
- assert(diagnostics == null);
- assert(actual);
- assertEquals(Object.keys(actual), ["lib/foo.js.map", "lib/foo.js"]);
},
});
-Deno.test({
- name: "Deno.compile() - properly handles .d.ts files",
- async fn() {
- const [diagnostics, actual] = await Deno.compile(
- "/foo.ts",
- {
- "/foo.ts": `console.log(Foo.bar);`,
- },
- {
- types: ["./subdir/foo_types.d.ts"],
- },
- );
- assert(diagnostics == null);
- assert(actual);
- assertEquals(Object.keys(actual), ["/foo.js.map", "/foo.js"]);
- },
-});
+// TODO(@kitsonk) figure the "right way" to restore support for types
+// Deno.test({
+// name: "Deno.compile() - properly handles .d.ts files",
+// async fn() {
+// const [diagnostics, actual] = await Deno.compile(
+// "/foo.ts",
+// {
+// "/foo.ts": `console.log(Foo.bar);`,
+// "/foo_types.d.ts": `declare namespace Foo {
+// const bar: string;
+// }`,
+// },
+// {
+// types: ["/foo_types.d.ts"],
+// },
+// );
+// assert(diagnostics == null);
+// assert(actual);
+// assertEquals(
+// Object.keys(actual).sort(),
+// ["file:///foo.ts.js", "file:///file.ts.js.map"],
+// );
+// },
+// });
Deno.test({
name: "Deno.transpileOnly()",
@@ -150,8 +144,7 @@ Deno.test({
"/bar.ts": `export const bar = "bar";\n`,
});
assert(diagnostics == null);
- assert(actual.includes(`__instantiate("foo", false)`));
- assert(actual.includes(`__exp["bar"]`));
+ assert(actual.includes(`const bar = "bar"`));
},
});
@@ -160,26 +153,7 @@ Deno.test({
async fn() {
const [diagnostics, actual] = await Deno.bundle("./subdir/mod1.ts");
assert(diagnostics == null);
- assert(actual.includes(`__instantiate("mod1", false)`));
- assert(actual.includes(`__exp["printHello3"]`));
- },
-});
-
-Deno.test({
- name: "Deno.bundle() - compiler config effects emit",
- async fn() {
- const [diagnostics, actual] = await Deno.bundle(
- "/foo.ts",
- {
- "/foo.ts": `// random comment\nexport * from "./bar.ts";\n`,
- "/bar.ts": `export const bar = "bar";\n`,
- },
- {
- removeComments: true,
- },
- );
- assert(diagnostics == null);
- assert(!actual.includes(`random`));
+ assert(actual.length);
},
});
@@ -191,22 +165,7 @@ Deno.test({
"/bar.js": `export const bar = "bar";\n`,
});
assert(diagnostics == null);
- assert(actual.includes(`System.register("bar",`));
- },
-});
-
-Deno.test({
- name: "Deno.bundle - pre ES2017 uses ES5 loader",
- async fn() {
- const [diagnostics, actual] = await Deno.bundle(
- "/foo.ts",
- {
- "/foo.ts": `console.log("hello world!")\n`,
- },
- { target: "es2015" },
- );
- assert(diagnostics == null);
- assert(actual.includes(`var __awaiter = `));
+ assert(actual.includes(`const bar = "bar"`));
},
});
@@ -226,8 +185,8 @@ Deno.test({
name: "Deno.compile() - SWC diagnostics",
async fn() {
await assertThrowsAsync(async () => {
- await Deno.compile("main.js", {
- "main.js": `
+ await Deno.compile("/main.js", {
+ "/main.js": `
export class Foo {
constructor() {
console.log("foo");
diff --git a/cli/tests/compiler_js_error.ts b/cli/tests/compiler_js_error.ts
deleted file mode 100644
index 0b981ae3a..000000000
--- a/cli/tests/compiler_js_error.ts
+++ /dev/null
@@ -1 +0,0 @@
-Deno.compile("main.js", { "main.js": "console.log(foo);" });
diff --git a/cli/tests/compiler_js_error.ts.out b/cli/tests/compiler_js_error.ts.out
deleted file mode 100644
index ef6ed7e80..000000000
--- a/cli/tests/compiler_js_error.ts.out
+++ /dev/null
@@ -1,4 +0,0 @@
-Check [WILDCARD]compiler_js_error.ts
-error: Uncaught (in promise) Error: Error in TS compiler:
-AssertionError: Unexpected skip of the emit.
-[WILDCARD]
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs
index 979a2ffad..64ef69ba1 100644
--- a/cli/tests/integration_tests.rs
+++ b/cli/tests/integration_tests.rs
@@ -3001,12 +3001,6 @@ itest!(deno_doc_import_map {
output: "doc/use_import_map.out",
});
-itest!(compiler_js_error {
- args: "run --unstable compiler_js_error.ts",
- output: "compiler_js_error.ts.out",
- exit_code: 1,
-});
-
itest!(import_file_with_colon {
args: "run --quiet --reload import_file_with_colon.ts",
output: "import_file_with_colon.ts.out",
diff --git a/cli/tests/lib_ref.ts b/cli/tests/lib_ref.ts
index 0a4ce3fc7..7b7bc4eca 100644
--- a/cli/tests/lib_ref.ts
+++ b/cli/tests/lib_ref.ts
@@ -1,7 +1,7 @@
const [errors, program] = await Deno.compile(
- "main.ts",
+ "/main.ts",
{
- "main.ts":
+ "/main.ts":
`/// <reference lib="dom" />\n\ndocument.getElementById("foo");\nDeno.args;`,
},
{
@@ -11,4 +11,4 @@ const [errors, program] = await Deno.compile(
);
console.log(errors);
-console.log(Object.keys(program));
+console.log(Object.keys(program).sort());
diff --git a/cli/tests/lib_ref.ts.out b/cli/tests/lib_ref.ts.out
index 9f8c62d8a..7aee0cc58 100644
--- a/cli/tests/lib_ref.ts.out
+++ b/cli/tests/lib_ref.ts.out
@@ -1,2 +1,2 @@
undefined
-[ "main.js.map", "main.js" ]
+[ "file:///[WILDCARD]main.ts.js", "file:///[WILDCARD]main.ts.js.map" ]
diff --git a/cli/tests/lib_runtime_api.ts b/cli/tests/lib_runtime_api.ts
index 788288f72..fc00825e9 100644
--- a/cli/tests/lib_runtime_api.ts
+++ b/cli/tests/lib_runtime_api.ts
@@ -1,7 +1,7 @@
const [errors, program] = await Deno.compile(
- "main.ts",
+ "/main.ts",
{
- "main.ts": `document.getElementById("foo");`,
+ "/main.ts": `document.getElementById("foo");`,
},
{
lib: ["dom", "esnext"],
@@ -9,4 +9,4 @@ const [errors, program] = await Deno.compile(
);
console.log(errors);
-console.log(Object.keys(program));
+console.log(Object.keys(program).sort());
diff --git a/cli/tests/lib_runtime_api.ts.out b/cli/tests/lib_runtime_api.ts.out
index 9f8c62d8a..7aee0cc58 100644
--- a/cli/tests/lib_runtime_api.ts.out
+++ b/cli/tests/lib_runtime_api.ts.out
@@ -1,2 +1,2 @@
undefined
-[ "main.js.map", "main.js" ]
+[ "file:///[WILDCARD]main.ts.js", "file:///[WILDCARD]main.ts.js.map" ]