summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/integration/js_unit_tests.rs14
-rw-r--r--cli/tests/unit/websocket_test.ts61
2 files changed, 70 insertions, 5 deletions
diff --git a/cli/tests/integration/js_unit_tests.rs b/cli/tests/integration/js_unit_tests.rs
index a13db02d7..f110f8aa6 100644
--- a/cli/tests/integration/js_unit_tests.rs
+++ b/cli/tests/integration/js_unit_tests.rs
@@ -112,12 +112,22 @@ util::unit_test_factory!(
fn js_unit_test(test: String) {
let _g = util::http_server();
- let mut deno = util::deno_cmd()
+ let mut deno = util::deno_cmd();
+ let deno = deno
.current_dir(util::root_path())
.arg("test")
.arg("--unstable")
.arg("--location=http://js-unit-tests/foo/bar")
- .arg("--no-prompt")
+ .arg("--no-prompt");
+
+ // TODO(mmastrac): it would be better to just load a test CA for all tests
+ let deno = if test == "websocket_test" {
+ deno.arg("--unsafely-ignore-certificate-errors")
+ } else {
+ deno
+ };
+
+ let mut deno = deno
.arg("-A")
.arg(util::tests_path().join("unit").join(format!("{test}.ts")))
.stderr(Stdio::piped())
diff --git a/cli/tests/unit/websocket_test.ts b/cli/tests/unit/websocket_test.ts
index 11f0fd7dc..b761cd118 100644
--- a/cli/tests/unit/websocket_test.ts
+++ b/cli/tests/unit/websocket_test.ts
@@ -21,7 +21,7 @@ Deno.test(async function websocketConstructorTakeURLObjectAsParameter() {
const promise = deferred();
const ws = new WebSocket(new URL("ws://localhost:4242/"));
assertEquals(ws.url, "ws://localhost:4242/");
- ws.onerror = () => fail();
+ ws.onerror = (e) => promise.reject(e);
ws.onopen = () => ws.close();
ws.onclose = () => {
promise.resolve();
@@ -29,13 +29,66 @@ Deno.test(async function websocketConstructorTakeURLObjectAsParameter() {
await promise;
});
+Deno.test(async function websocketSendLargePacket() {
+ const promise = deferred();
+ const ws = new WebSocket(new URL("wss://localhost:4243/"));
+ assertEquals(ws.url, "wss://localhost:4243/");
+ ws.onerror = (e) => promise.reject(e);
+ ws.onopen = () => {
+ ws.send("a".repeat(65000));
+ };
+ ws.onmessage = () => {
+ ws.close();
+ };
+ ws.onclose = () => {
+ promise.resolve();
+ };
+ await promise;
+});
+
+Deno.test(async function websocketSendLargeBinaryPacket() {
+ const promise = deferred();
+ const ws = new WebSocket(new URL("wss://localhost:4243/"));
+ assertEquals(ws.url, "wss://localhost:4243/");
+ ws.onerror = (e) => promise.reject(e);
+ ws.onopen = () => {
+ ws.send(new Uint8Array(65000));
+ };
+ ws.onmessage = (msg) => {
+ console.log(msg);
+ ws.close();
+ };
+ ws.onclose = () => {
+ promise.resolve();
+ };
+ await promise;
+});
+
+Deno.test(async function websocketSendLargeBlobPacket() {
+ const promise = deferred();
+ const ws = new WebSocket(new URL("wss://localhost:4243/"));
+ assertEquals(ws.url, "wss://localhost:4243/");
+ ws.onerror = (e) => promise.reject(e);
+ ws.onopen = () => {
+ ws.send(new Blob(["a".repeat(65000)]));
+ };
+ ws.onmessage = (msg) => {
+ console.log(msg);
+ ws.close();
+ };
+ ws.onclose = () => {
+ promise.resolve();
+ };
+ await promise;
+});
+
// https://github.com/denoland/deno/pull/17762
// https://github.com/denoland/deno/issues/17761
Deno.test(async function websocketPingPong() {
const promise = deferred();
const ws = new WebSocket("ws://localhost:4245/");
assertEquals(ws.url, "ws://localhost:4245/");
- ws.onerror = () => fail();
+ ws.onerror = (e) => promise.reject(e);
ws.onmessage = (e) => {
ws.send(e.data);
};
@@ -144,7 +197,9 @@ Deno.test({
const ws = new WebSocket(serveUrl);
assertEquals(ws.url, serveUrl);
ws.onerror = () => fail();
- ws.onmessage = () => ws.send("bye");
+ ws.onmessage = (m: MessageEvent) => {
+ if (m.data == "Hello") ws.send("bye");
+ };
ws.onclose = () => {
promise.resolve();
};