summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/070_location.ts10
-rw-r--r--cli/tests/070_location.ts.out22
-rw-r--r--cli/tests/071_location_unset.ts5
-rw-r--r--cli/tests/071_location_unset.ts.out4
-rw-r--r--cli/tests/072_location_relative_fetch.ts2
-rw-r--r--cli/tests/072_location_relative_fetch.ts.out2
-rw-r--r--cli/tests/077_fetch_empty.ts1
-rw-r--r--cli/tests/077_fetch_empty.ts.out2
-rw-r--r--cli/tests/complex_permissions_test.ts4
-rw-r--r--cli/tests/fetch/hello.txt1
-rw-r--r--cli/tests/integration_tests.rs39
-rw-r--r--cli/tests/subdir/worker_location.ts4
-rw-r--r--cli/tests/unit/fetch_test.ts11
-rw-r--r--cli/tests/unit/request_test.ts8
-rwxr-xr-xcli/tests/unit/unit_test_runner.ts1
-rw-r--r--cli/tests/workers_test.ts38
16 files changed, 130 insertions, 24 deletions
diff --git a/cli/tests/070_location.ts b/cli/tests/070_location.ts
new file mode 100644
index 000000000..62fd34af2
--- /dev/null
+++ b/cli/tests/070_location.ts
@@ -0,0 +1,10 @@
+// TODO(nayeemrmn): Add `Location` and `location` to `dlint`'s globals.
+// deno-lint-ignore-file no-undef
+console.log(Location);
+console.log(Location.prototype);
+console.log(location);
+try {
+ location.hostname = "bar";
+} catch (error) {
+ console.log(error);
+}
diff --git a/cli/tests/070_location.ts.out b/cli/tests/070_location.ts.out
new file mode 100644
index 000000000..66d470b6f
--- /dev/null
+++ b/cli/tests/070_location.ts.out
@@ -0,0 +1,22 @@
+[WILDCARD][Function: Location]
+Location { [Symbol(Symbol.toStringTag)]: "Location" }
+Location {
+ hash: [Getter/Setter],
+ host: [Getter/Setter],
+ hostname: [Getter/Setter],
+ href: [Getter/Setter],
+ origin: [Getter],
+ password: [Getter/Setter],
+ pathname: [Getter/Setter],
+ port: [Getter/Setter],
+ protocol: [Getter/Setter],
+ search: [Getter/Setter],
+ username: [Getter/Setter],
+ ancestorOrigins: [Getter],
+ assign: [Function: assign],
+ reload: [Function: reload],
+ replace: [Function: replace],
+ toString: [Function: toString]
+}
+NotSupportedError: Cannot set "location.hostname".
+[WILDCARD]
diff --git a/cli/tests/071_location_unset.ts b/cli/tests/071_location_unset.ts
new file mode 100644
index 000000000..5c0518940
--- /dev/null
+++ b/cli/tests/071_location_unset.ts
@@ -0,0 +1,5 @@
+// TODO(nayeemrmn): Add `Location` and `location` to `dlint`'s globals.
+// deno-lint-ignore-file no-undef
+console.log(Location);
+console.log(Location.prototype);
+console.log(location);
diff --git a/cli/tests/071_location_unset.ts.out b/cli/tests/071_location_unset.ts.out
new file mode 100644
index 000000000..2c030a773
--- /dev/null
+++ b/cli/tests/071_location_unset.ts.out
@@ -0,0 +1,4 @@
+[WILDCARD][Function: Location]
+Location { [Symbol(Symbol.toStringTag)]: "Location" }
+error: Uncaught ReferenceError: Access to "location", run again with --location <href>.
+[WILDCARD]
diff --git a/cli/tests/072_location_relative_fetch.ts b/cli/tests/072_location_relative_fetch.ts
new file mode 100644
index 000000000..d4764bf7f
--- /dev/null
+++ b/cli/tests/072_location_relative_fetch.ts
@@ -0,0 +1,2 @@
+const response = await fetch("fetch/hello.txt");
+console.log(await response.text());
diff --git a/cli/tests/072_location_relative_fetch.ts.out b/cli/tests/072_location_relative_fetch.ts.out
new file mode 100644
index 000000000..8151f6f88
--- /dev/null
+++ b/cli/tests/072_location_relative_fetch.ts.out
@@ -0,0 +1,2 @@
+[WILDCARD]Hello, world!
+
diff --git a/cli/tests/077_fetch_empty.ts b/cli/tests/077_fetch_empty.ts
new file mode 100644
index 000000000..b10a9094e
--- /dev/null
+++ b/cli/tests/077_fetch_empty.ts
@@ -0,0 +1 @@
+await fetch("");
diff --git a/cli/tests/077_fetch_empty.ts.out b/cli/tests/077_fetch_empty.ts.out
new file mode 100644
index 000000000..9dfccf10c
--- /dev/null
+++ b/cli/tests/077_fetch_empty.ts.out
@@ -0,0 +1,2 @@
+[WILDCARD]error: Uncaught (in promise) URIError: relative URL without a base
+[WILDCARD]
diff --git a/cli/tests/complex_permissions_test.ts b/cli/tests/complex_permissions_test.ts
index fba761a2c..002d33540 100644
--- a/cli/tests/complex_permissions_test.ts
+++ b/cli/tests/complex_permissions_test.ts
@@ -10,8 +10,8 @@ const test: { [key: string]: (...args: any[]) => void | Promise<void> } = {
Deno.writeFileSync(file, new Uint8Array(0), { append: true })
);
},
- netFetch(hosts: string[]): void {
- hosts.forEach((host) => fetch(host));
+ netFetch(urls: string[]): void {
+ urls.forEach((url) => fetch(url));
},
netListen(endpoints: string[]): void {
endpoints.forEach((endpoint) => {
diff --git a/cli/tests/fetch/hello.txt b/cli/tests/fetch/hello.txt
new file mode 100644
index 000000000..af5626b4a
--- /dev/null
+++ b/cli/tests/fetch/hello.txt
@@ -0,0 +1 @@
+Hello, world!
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs
index 68cfe0b50..aabeb1f77 100644
--- a/cli/tests/integration_tests.rs
+++ b/cli/tests/integration_tests.rs
@@ -1246,7 +1246,7 @@ fn bundle_import_map_no_check() {
.current_dir(util::root_path())
.arg("bundle")
.arg("--no-check")
- .arg("--importmap")
+ .arg("--import-map")
.arg(import_map_path)
.arg("--unstable")
.arg(import)
@@ -1689,7 +1689,7 @@ fn repl_test_pty_bad_input() {
#[test]
#[ignore]
-fn run_watch_with_importmap_and_relative_paths() {
+fn run_watch_with_import_map_and_relative_paths() {
fn create_relative_tmp_file(
directory: &TempDir,
filename: &'static str,
@@ -1722,7 +1722,7 @@ fn run_watch_with_importmap_and_relative_paths() {
.arg("run")
.arg("--unstable")
.arg("--watch")
- .arg("--importmap")
+ .arg("--import-map")
.arg(&import_map_path)
.arg(&file_to_watch)
.env("NO_COLOR", "1")
@@ -2307,6 +2307,8 @@ fn workers() {
.current_dir(util::tests_path())
.arg("test")
.arg("--reload")
+ .arg("--location")
+ .arg("http://127.0.0.1:4545/cli/tests/")
.arg("--allow-net")
.arg("--allow-read")
.arg("--unstable")
@@ -2548,6 +2550,23 @@ itest!(_067_test_no_run_type_error {
exit_code: 1,
});
+itest!(_070_location {
+ args: "run --location https://foo/bar?baz#bat 070_location.ts",
+ output: "070_location.ts.out",
+});
+
+itest!(_071_location_unset {
+ args: "run 071_location_unset.ts",
+ output: "071_location_unset.ts.out",
+ exit_code: 1,
+});
+
+itest!(_072_location_relative_fetch {
+ args: "run --location http://127.0.0.1:4545/cli/tests/ --allow-net 072_location_relative_fetch.ts",
+ output: "072_location_relative_fetch.ts.out",
+ http_server: true,
+});
+
itest!(_073_worker_error {
args: "run -A 073_worker_error.ts",
output: "073_worker_error.ts.out",
@@ -2570,6 +2589,12 @@ itest!(_076_info_json_deps_order {
output: "076_info_json_deps_order.out",
});
+itest!(_077_fetch_empty {
+ args: "run -A 077_fetch_empty.ts",
+ output: "077_fetch_empty.ts.out",
+ exit_code: 1,
+});
+
itest!(js_import_detect {
args: "run --quiet --reload js_import_detect.ts",
output: "js_import_detect.ts.out",
@@ -5200,16 +5225,14 @@ fn web_platform_tests() {
.tempfile()
.unwrap();
- let bundle = concat_bundle(
- files,
- file.path(),
- format!("window.location = {{search: \"{}\"}};\n", variant),
- );
+ let bundle = concat_bundle(files, file.path(), "".to_string());
file.write_all(bundle.as_bytes()).unwrap();
let child = util::deno_cmd()
.current_dir(test_file_path.parent().unwrap())
.arg("run")
+ .arg("--location")
+ .arg(&format!("http://web-platform-tests/?{}", variant))
.arg("-A")
.arg(file.path())
.arg(deno_core::serde_json::to_string(&expect_fail).unwrap())
diff --git a/cli/tests/subdir/worker_location.ts b/cli/tests/subdir/worker_location.ts
new file mode 100644
index 000000000..480032350
--- /dev/null
+++ b/cli/tests/subdir/worker_location.ts
@@ -0,0 +1,4 @@
+onmessage = function (): void {
+ postMessage(self.location.href);
+ close();
+};
diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts
index e5389d024..6945b2e2a 100644
--- a/cli/tests/unit/fetch_test.ts
+++ b/cli/tests/unit/fetch_test.ts
@@ -221,17 +221,6 @@ unitTest({ perms: { net: true } }, async function responseClone(): Promise<
}
});
-unitTest({ perms: { net: true } }, async function fetchEmptyInvalid(): Promise<
- void
-> {
- await assertThrowsAsync(
- async () => {
- await fetch("");
- },
- URIError,
- );
-});
-
unitTest(
{ perms: { net: true } },
async function fetchMultipartFormDataSuccess(): Promise<void> {
diff --git a/cli/tests/unit/request_test.ts b/cli/tests/unit/request_test.ts
index 8132e0184..da6a0e15b 100644
--- a/cli/tests/unit/request_test.ts
+++ b/cli/tests/unit/request_test.ts
@@ -1,5 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import { assert, assertEquals, assertThrows, unitTest } from "./test_util.ts";
+import { assert, assertEquals, unitTest } from "./test_util.ts";
unitTest(function fromInit(): void {
const req = new Request("http://foo/", {
@@ -46,8 +46,10 @@ unitTest(function methodNonString(): void {
});
unitTest(function requestRelativeUrl(): void {
- // TODO(nayeemrmn): Base from `--location` when implemented and set.
- assertThrows(() => new Request("relative-url"), TypeError, "Invalid URL.");
+ assertEquals(
+ new Request("relative-url").url,
+ "http://js-unit-tests/foo/relative-url",
+ );
});
unitTest(async function cloneRequestBodyStream(): Promise<void> {
diff --git a/cli/tests/unit/unit_test_runner.ts b/cli/tests/unit/unit_test_runner.ts
index 35a691ebd..1f347ec9a 100755
--- a/cli/tests/unit/unit_test_runner.ts
+++ b/cli/tests/unit/unit_test_runner.ts
@@ -97,6 +97,7 @@ function spawnWorkerRunner(
Deno.execPath(),
"run",
"--unstable", // TODO(ry) be able to test stable vs unstable
+ "--location=http://js-unit-tests/foo/bar",
"-A",
"cli/tests/unit/unit_test_runner.ts",
"--worker",
diff --git a/cli/tests/workers_test.ts b/cli/tests/workers_test.ts
index c35ea72f5..9cbc864bd 100644
--- a/cli/tests/workers_test.ts
+++ b/cli/tests/workers_test.ts
@@ -614,3 +614,41 @@ Deno.test("Worker with disabled permissions", async function () {
await promise;
worker.terminate();
});
+
+Deno.test({
+ name: "worker location",
+ fn: async function (): Promise<void> {
+ const promise = deferred();
+ const workerModuleHref =
+ new URL("subdir/worker_location.ts", import.meta.url).href;
+ const w = new Worker(workerModuleHref, { type: "module" });
+ w.onmessage = (e): void => {
+ assertEquals(e.data, workerModuleHref);
+ promise.resolve();
+ };
+ w.postMessage("Hello, world!");
+ await promise;
+ w.terminate();
+ },
+});
+
+Deno.test({
+ name: "worker with relative specifier",
+ fn: async function (): Promise<void> {
+ // TODO(nayeemrmn): Add `Location` and `location` to `dlint`'s globals.
+ // deno-lint-ignore no-undef
+ assertEquals(location.href, "http://127.0.0.1:4545/cli/tests/");
+ const promise = deferred();
+ const w = new Worker(
+ "./workers/test_worker.ts",
+ { type: "module", name: "tsWorker" },
+ );
+ w.onmessage = (e): void => {
+ assertEquals(e.data, "Hello, world!");
+ promise.resolve();
+ };
+ w.postMessage("Hello, world!");
+ await promise;
+ w.terminate();
+ },
+});