summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/integration/run_tests.rs190
-rw-r--r--cli/tests/testdata/webstorage/config_a.jsonc3
-rw-r--r--cli/tests/testdata/webstorage/config_b.jsonc3
-rw-r--r--cli/tests/testdata/webstorage/fixture.ts2
-rw-r--r--cli/tests/testdata/webstorage/logger.ts1
-rw-r--r--cli/tests/testdata/webstorage/serialization.ts4
-rw-r--r--cli/tests/testdata/webstorage/serialization.ts.out3
-rw-r--r--cli/tests/testdata/webstorage/setter.ts1
8 files changed, 203 insertions, 4 deletions
diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs
index 1d033d9e2..d4e7ccf72 100644
--- a/cli/tests/integration/run_tests.rs
+++ b/cli/tests/integration/run_tests.rs
@@ -237,10 +237,192 @@ itest!(_071_location_unset {
});
itest!(_072_location_relative_fetch {
- args: "run --location http://127.0.0.1:4545/ --allow-net 072_location_relative_fetch.ts",
- output: "072_location_relative_fetch.ts.out",
- http_server: true,
- });
+ args: "run --location http://127.0.0.1:4545/ --allow-net 072_location_relative_fetch.ts",
+ output: "072_location_relative_fetch.ts.out",
+ http_server: true,
+});
+
+// tests the serialization of webstorage (both localStorage and sessionStorage)
+itest!(webstorage_serialization {
+ args: "run webstorage/serialization.ts",
+ output: "webstorage/serialization.ts.out",
+});
+
+// tests to ensure that when `--location` is set, all code shares the same
+// localStorage cache based on the origin of the location URL.
+#[test]
+fn webstorage_location_shares_origin() {
+ let deno_dir = util::new_deno_dir();
+
+ let mut deno_cmd = util::deno_cmd_with_deno_dir(deno_dir.path());
+ let output = deno_cmd
+ .current_dir(util::testdata_path())
+ .arg("run")
+ .arg("--location")
+ .arg("https://example.com/a.ts")
+ .arg("webstorage/fixture.ts")
+ .stdout(std::process::Stdio::piped())
+ .spawn()
+ .unwrap()
+ .wait_with_output()
+ .unwrap();
+ assert!(output.status.success());
+ assert_eq!(output.stdout, b"Storage { length: 0 }\n");
+
+ let mut deno_cmd = util::deno_cmd_with_deno_dir(deno_dir.path());
+ let output = deno_cmd
+ .current_dir(util::testdata_path())
+ .arg("run")
+ .arg("--location")
+ .arg("https://example.com/b.ts")
+ .arg("webstorage/logger.ts")
+ .stdout(std::process::Stdio::piped())
+ .spawn()
+ .unwrap()
+ .wait_with_output()
+ .unwrap();
+ assert!(output.status.success());
+ assert_eq!(output.stdout, b"Storage { length: 1, hello: \"deno\" }\n");
+}
+
+// test to ensure that when a --config file is set, but no --location, that
+// storage persists against unique configuration files.
+#[test]
+fn webstorage_config_file() {
+ let deno_dir = util::new_deno_dir();
+
+ let mut deno_cmd = util::deno_cmd_with_deno_dir(deno_dir.path());
+ let output = deno_cmd
+ .current_dir(util::testdata_path())
+ .arg("run")
+ .arg("--config")
+ .arg("webstorage/config_a.jsonc")
+ .arg("webstorage/fixture.ts")
+ .stdout(std::process::Stdio::piped())
+ .spawn()
+ .unwrap()
+ .wait_with_output()
+ .unwrap();
+ assert!(output.status.success());
+ assert_eq!(output.stdout, b"Storage { length: 0 }\n");
+
+ let mut deno_cmd = util::deno_cmd_with_deno_dir(deno_dir.path());
+ let output = deno_cmd
+ .current_dir(util::testdata_path())
+ .arg("run")
+ .arg("--config")
+ .arg("webstorage/config_b.jsonc")
+ .arg("webstorage/logger.ts")
+ .stdout(std::process::Stdio::piped())
+ .spawn()
+ .unwrap()
+ .wait_with_output()
+ .unwrap();
+ assert!(output.status.success());
+ assert_eq!(output.stdout, b"Storage { length: 0 }\n");
+
+ let mut deno_cmd = util::deno_cmd_with_deno_dir(deno_dir.path());
+ let output = deno_cmd
+ .current_dir(util::testdata_path())
+ .arg("run")
+ .arg("--config")
+ .arg("webstorage/config_a.jsonc")
+ .arg("webstorage/logger.ts")
+ .stdout(std::process::Stdio::piped())
+ .spawn()
+ .unwrap()
+ .wait_with_output()
+ .unwrap();
+ assert!(output.status.success());
+ assert_eq!(output.stdout, b"Storage { length: 1, hello: \"deno\" }\n");
+}
+
+// tests to ensure `--config` does not effect persisted storage when a
+// `--location` is provided.
+#[test]
+fn webstorage_location_precedes_config() {
+ let deno_dir = util::new_deno_dir();
+
+ let mut deno_cmd = util::deno_cmd_with_deno_dir(deno_dir.path());
+ let output = deno_cmd
+ .current_dir(util::testdata_path())
+ .arg("run")
+ .arg("--location")
+ .arg("https://example.com/a.ts")
+ .arg("--config")
+ .arg("webstorage/config_a.jsonc")
+ .arg("webstorage/fixture.ts")
+ .stdout(std::process::Stdio::piped())
+ .spawn()
+ .unwrap()
+ .wait_with_output()
+ .unwrap();
+ assert!(output.status.success());
+ assert_eq!(output.stdout, b"Storage { length: 0 }\n");
+
+ let mut deno_cmd = util::deno_cmd_with_deno_dir(deno_dir.path());
+ let output = deno_cmd
+ .current_dir(util::testdata_path())
+ .arg("run")
+ .arg("--location")
+ .arg("https://example.com/b.ts")
+ .arg("--config")
+ .arg("webstorage/config_b.jsonc")
+ .arg("webstorage/logger.ts")
+ .stdout(std::process::Stdio::piped())
+ .spawn()
+ .unwrap()
+ .wait_with_output()
+ .unwrap();
+ assert!(output.status.success());
+ assert_eq!(output.stdout, b"Storage { length: 1, hello: \"deno\" }\n");
+}
+
+// test to ensure that when there isn't a configuration or location, that the
+// main module is used to determine how to persist storage data.
+#[test]
+fn webstorage_main_module() {
+ let deno_dir = util::new_deno_dir();
+
+ let mut deno_cmd = util::deno_cmd_with_deno_dir(deno_dir.path());
+ let output = deno_cmd
+ .current_dir(util::testdata_path())
+ .arg("run")
+ .arg("webstorage/fixture.ts")
+ .stdout(std::process::Stdio::piped())
+ .spawn()
+ .unwrap()
+ .wait_with_output()
+ .unwrap();
+ assert!(output.status.success());
+ assert_eq!(output.stdout, b"Storage { length: 0 }\n");
+
+ let mut deno_cmd = util::deno_cmd_with_deno_dir(deno_dir.path());
+ let output = deno_cmd
+ .current_dir(util::testdata_path())
+ .arg("run")
+ .arg("webstorage/logger.ts")
+ .stdout(std::process::Stdio::piped())
+ .spawn()
+ .unwrap()
+ .wait_with_output()
+ .unwrap();
+ assert!(output.status.success());
+ assert_eq!(output.stdout, b"Storage { length: 0 }\n");
+
+ let mut deno_cmd = util::deno_cmd_with_deno_dir(deno_dir.path());
+ let output = deno_cmd
+ .current_dir(util::testdata_path())
+ .arg("run")
+ .arg("webstorage/fixture.ts")
+ .stdout(std::process::Stdio::piped())
+ .spawn()
+ .unwrap()
+ .wait_with_output()
+ .unwrap();
+ assert!(output.status.success());
+ assert_eq!(output.stdout, b"Storage { length: 1, hello: \"deno\" }\n");
+}
itest!(_075_import_local_query_hash {
args: "run 075_import_local_query_hash.ts",
diff --git a/cli/tests/testdata/webstorage/config_a.jsonc b/cli/tests/testdata/webstorage/config_a.jsonc
new file mode 100644
index 000000000..875cb6001
--- /dev/null
+++ b/cli/tests/testdata/webstorage/config_a.jsonc
@@ -0,0 +1,3 @@
+{
+ "compilerOptions": {}
+}
diff --git a/cli/tests/testdata/webstorage/config_b.jsonc b/cli/tests/testdata/webstorage/config_b.jsonc
new file mode 100644
index 000000000..875cb6001
--- /dev/null
+++ b/cli/tests/testdata/webstorage/config_b.jsonc
@@ -0,0 +1,3 @@
+{
+ "compilerOptions": {}
+}
diff --git a/cli/tests/testdata/webstorage/fixture.ts b/cli/tests/testdata/webstorage/fixture.ts
new file mode 100644
index 000000000..cf4bd9f1f
--- /dev/null
+++ b/cli/tests/testdata/webstorage/fixture.ts
@@ -0,0 +1,2 @@
+import "./logger.ts";
+import "./setter.ts";
diff --git a/cli/tests/testdata/webstorage/logger.ts b/cli/tests/testdata/webstorage/logger.ts
new file mode 100644
index 000000000..3898c4445
--- /dev/null
+++ b/cli/tests/testdata/webstorage/logger.ts
@@ -0,0 +1 @@
+console.log(window.localStorage);
diff --git a/cli/tests/testdata/webstorage/serialization.ts b/cli/tests/testdata/webstorage/serialization.ts
new file mode 100644
index 000000000..f3791d355
--- /dev/null
+++ b/cli/tests/testdata/webstorage/serialization.ts
@@ -0,0 +1,4 @@
+window.sessionStorage.setItem("hello", "deno");
+
+console.log(window.localStorage);
+console.log(window.sessionStorage);
diff --git a/cli/tests/testdata/webstorage/serialization.ts.out b/cli/tests/testdata/webstorage/serialization.ts.out
new file mode 100644
index 000000000..fea76aa43
--- /dev/null
+++ b/cli/tests/testdata/webstorage/serialization.ts.out
@@ -0,0 +1,3 @@
+[WILDCARD]
+Storage {[WILDCARD]
+Storage { length: 1, hello: "deno" }
diff --git a/cli/tests/testdata/webstorage/setter.ts b/cli/tests/testdata/webstorage/setter.ts
new file mode 100644
index 000000000..ec6d474f5
--- /dev/null
+++ b/cli/tests/testdata/webstorage/setter.ts
@@ -0,0 +1 @@
+window.localStorage.setItem("hello", "deno");