diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2021-01-06 13:22:38 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-06 13:22:38 +1100 |
commit | 54240c22af6233d1d977d469868b0d9050cad6da (patch) | |
tree | 81af9892f8728852387fad9c2d243ab933de927f /cli/tests | |
parent | 60c9c857584bf5180dd0f7b937683dd9691aef84 (diff) |
feat(cli): support data urls (#8866)
Closes: #5059
Co-authored-by: Valentin Anger <syrupthinker@gryphno.de>
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/import_data_url.ts | 12 | ||||
-rw-r--r-- | cli/tests/import_data_url.ts.out | 3 | ||||
-rw-r--r-- | cli/tests/import_data_url_error_stack.ts | 3 | ||||
-rw-r--r-- | cli/tests/import_data_url_error_stack.ts.out | 5 | ||||
-rw-r--r-- | cli/tests/import_data_url_import_relative.ts | 4 | ||||
-rw-r--r-- | cli/tests/import_data_url_import_relative.ts.out | 1 | ||||
-rw-r--r-- | cli/tests/import_data_url_imports.ts | 4 | ||||
-rw-r--r-- | cli/tests/import_data_url_imports.ts.out | 1 | ||||
-rw-r--r-- | cli/tests/import_data_url_jsx.ts | 10 | ||||
-rw-r--r-- | cli/tests/import_data_url_jsx.ts.out | 1 | ||||
-rw-r--r-- | cli/tests/import_dynamic_data_url.ts | 14 | ||||
-rw-r--r-- | cli/tests/import_dynamic_data_url.ts.out | 3 | ||||
-rw-r--r-- | cli/tests/integration_tests.rs | 33 | ||||
-rw-r--r-- | cli/tests/unsupported_dynamic_import_scheme.out | 3 | ||||
-rw-r--r-- | cli/tests/workers_test.ts | 21 |
15 files changed, 117 insertions, 1 deletions
diff --git a/cli/tests/import_data_url.ts b/cli/tests/import_data_url.ts new file mode 100644 index 000000000..258514a5e --- /dev/null +++ b/cli/tests/import_data_url.ts @@ -0,0 +1,12 @@ +// export const a = "a"; + +// export enum A { +// A, +// B, +// C, +// } +import * as a from "data:application/typescript;base64,ZXhwb3J0IGNvbnN0IGEgPSAiYSI7CgpleHBvcnQgZW51bSBBIHsKICBBLAogIEIsCiAgQywKfQo="; + +console.log(a.a); +console.log(a.A); +console.log(a.A.A); diff --git a/cli/tests/import_data_url.ts.out b/cli/tests/import_data_url.ts.out new file mode 100644 index 000000000..bfa0b9d94 --- /dev/null +++ b/cli/tests/import_data_url.ts.out @@ -0,0 +1,3 @@ +a +{ "0": "A", "1": "B", "2": "C", A: 0, B: 1, C: 2 } +0 diff --git a/cli/tests/import_data_url_error_stack.ts b/cli/tests/import_data_url_error_stack.ts new file mode 100644 index 000000000..022e49fe1 --- /dev/null +++ b/cli/tests/import_data_url_error_stack.ts @@ -0,0 +1,3 @@ +import { a } from "data:application/typescript;base64,ZW51bSBBIHsKICBBLAogIEIsCiAgQywKIH0KIAogZXhwb3J0IGZ1bmN0aW9uIGEoKSB7CiAgIHRocm93IG5ldyBFcnJvcihgSGVsbG8gJHtBLkN9YCk7CiB9CiA="; + +a(); diff --git a/cli/tests/import_data_url_error_stack.ts.out b/cli/tests/import_data_url_error_stack.ts.out new file mode 100644 index 000000000..ca8b906da --- /dev/null +++ b/cli/tests/import_data_url_error_stack.ts.out @@ -0,0 +1,5 @@ +error: Uncaught Error: Hello 2 + throw new Error(`Hello ${A.C}`); + ^ + at a (72554b3efdc211ba4aa0b62629589f048e7d4afe7b0576f35ff340ce0ea8f9b8.ts:8:10) + at import_data_url_error_stack.ts:3:1 diff --git a/cli/tests/import_data_url_import_relative.ts b/cli/tests/import_data_url_import_relative.ts new file mode 100644 index 000000000..23947fe60 --- /dev/null +++ b/cli/tests/import_data_url_import_relative.ts @@ -0,0 +1,4 @@ +// export { a } from "./a.ts"; +import * as a from "data:application/javascript;base64,ZXhwb3J0IHsgYSB9IGZyb20gIi4vYS50cyI7Cg=="; + +console.log(a); diff --git a/cli/tests/import_data_url_import_relative.ts.out b/cli/tests/import_data_url_import_relative.ts.out new file mode 100644 index 000000000..5123f2fe4 --- /dev/null +++ b/cli/tests/import_data_url_import_relative.ts.out @@ -0,0 +1 @@ +error: invalid URL: relative URL with a cannot-be-a-base base diff --git a/cli/tests/import_data_url_imports.ts b/cli/tests/import_data_url_imports.ts new file mode 100644 index 000000000..f25c2c389 --- /dev/null +++ b/cli/tests/import_data_url_imports.ts @@ -0,0 +1,4 @@ +// export { printHello } from "http://localhost:4545/cli/tests/subdir/mod2.ts"; +import { printHello } from "data:application/typescript;base64,ZXhwb3J0IHsgcHJpbnRIZWxsbyB9IGZyb20gImh0dHA6Ly9sb2NhbGhvc3Q6NDU0NS9jbGkvdGVzdHMvc3ViZGlyL21vZDIudHMiOwo="; + +printHello(); diff --git a/cli/tests/import_data_url_imports.ts.out b/cli/tests/import_data_url_imports.ts.out new file mode 100644 index 000000000..e965047ad --- /dev/null +++ b/cli/tests/import_data_url_imports.ts.out @@ -0,0 +1 @@ +Hello diff --git a/cli/tests/import_data_url_jsx.ts b/cli/tests/import_data_url_jsx.ts new file mode 100644 index 000000000..1881211f9 --- /dev/null +++ b/cli/tests/import_data_url_jsx.ts @@ -0,0 +1,10 @@ +import render from "data:text/jsx;base64,ZXhwb3J0IGRlZmF1bHQgZnVuY3Rpb24oKSB7CiAgcmV0dXJuIDxkaXY+SGVsbG8gRGVubyE8L2Rpdj4KfQo="; + +// deno-lint-ignore no-explicit-any +(globalThis as any).React = { + createElement(...args: unknown[]) { + console.log(...args); + }, +}; + +render(); diff --git a/cli/tests/import_data_url_jsx.ts.out b/cli/tests/import_data_url_jsx.ts.out new file mode 100644 index 000000000..c1c85f250 --- /dev/null +++ b/cli/tests/import_data_url_jsx.ts.out @@ -0,0 +1 @@ +div null Hello Deno! diff --git a/cli/tests/import_dynamic_data_url.ts b/cli/tests/import_dynamic_data_url.ts new file mode 100644 index 000000000..53a0fbcd3 --- /dev/null +++ b/cli/tests/import_dynamic_data_url.ts @@ -0,0 +1,14 @@ +// export const a = "a"; + +// export enum A { +// A, +// B, +// C, +// } +const a = await import( + "data:application/typescript;base64,ZXhwb3J0IGNvbnN0IGEgPSAiYSI7CgpleHBvcnQgZW51bSBBIHsKICBBLAogIEIsCiAgQywKfQo=" +); + +console.log(a.a); +console.log(a.A); +console.log(a.A.A); diff --git a/cli/tests/import_dynamic_data_url.ts.out b/cli/tests/import_dynamic_data_url.ts.out new file mode 100644 index 000000000..bfa0b9d94 --- /dev/null +++ b/cli/tests/import_dynamic_data_url.ts.out @@ -0,0 +1,3 @@ +a +{ "0": "A", "1": "B", "2": "C", A: 0, B: 1, C: 2 } +0 diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index f4081a7ea..624f17df1 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -3412,6 +3412,39 @@ itest!(deno_doc_import_map { output: "doc/use_import_map.out", }); +itest!(import_data_url_error_stack { + args: "run --quiet --reload import_data_url_error_stack.ts", + output: "import_data_url_error_stack.ts.out", + exit_code: 1, +}); + +itest!(import_data_url_import_relative { + args: "run --quiet --reload import_data_url_import_relative.ts", + output: "import_data_url_import_relative.ts.out", + exit_code: 1, +}); + +itest!(import_data_url_imports { + args: "run --quiet --reload import_data_url_imports.ts", + output: "import_data_url_imports.ts.out", + http_server: true, +}); + +itest!(import_data_url_jsx { + args: "run --quiet --reload import_data_url_jsx.ts", + output: "import_data_url_jsx.ts.out", +}); + +itest!(import_data_url { + args: "run --quiet --reload import_data_url.ts", + output: "import_data_url.ts.out", +}); + +itest!(import_dynamic_data_url { + args: "run --quiet --reload import_dynamic_data_url.ts", + output: "import_dynamic_data_url.ts.out", +}); + 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/unsupported_dynamic_import_scheme.out b/cli/tests/unsupported_dynamic_import_scheme.out index 434f14c4c..9160f935f 100644 --- a/cli/tests/unsupported_dynamic_import_scheme.out +++ b/cli/tests/unsupported_dynamic_import_scheme.out @@ -1,5 +1,6 @@ error: Uncaught (in promise) TypeError: Unsupported scheme "xxx" for module "xxx:". Supported schemes: [ + "data", + "file", "http", "https", - "file", ] diff --git a/cli/tests/workers_test.ts b/cli/tests/workers_test.ts index d907c97a9..3bfe0181a 100644 --- a/cli/tests/workers_test.ts +++ b/cli/tests/workers_test.ts @@ -47,6 +47,27 @@ Deno.test({ }); Deno.test({ + name: "worker from data url", + async fn() { + const promise = deferred(); + const tsWorker = new Worker( + "data:application/typescript;base64,aWYgKHNlbGYubmFtZSAhPT0gInRzV29ya2VyIikgewogIHRocm93IEVycm9yKGBJbnZhbGlkIHdvcmtlciBuYW1lOiAke3NlbGYubmFtZX0sIGV4cGVjdGVkIHRzV29ya2VyYCk7Cn0KCm9ubWVzc2FnZSA9IGZ1bmN0aW9uIChlKTogdm9pZCB7CiAgcG9zdE1lc3NhZ2UoZS5kYXRhKTsKICBjbG9zZSgpOwp9Owo=", + { type: "module", name: "tsWorker" }, + ); + + tsWorker.onmessage = (e): void => { + assertEquals(e.data, "Hello World"); + promise.resolve(); + }; + + tsWorker.postMessage("Hello World"); + + await promise; + tsWorker.terminate(); + }, +}); + +Deno.test({ name: "worker nested", fn: async function (): Promise<void> { const promise = deferred(); |