summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSean McArthur <sean@seanmonstar.com>2024-07-12 15:51:37 -0700
committerGitHub <noreply@github.com>2024-07-13 00:51:37 +0200
commitf6fd6619e708a515831f707438368d81b0c9aa56 (patch)
tree9c65c76613330a22c5a88c017752a9aa7e0951ac /tests
parent2fca4f11fe22a5d49326b6bf5b3ef039403eb0df (diff)
refactor(fetch): reimplement fetch with hyper instead of reqwest (#24237)
This commit re-implements `ext/fetch` and all dependent crates using `hyper` and `hyper-util`, instead of `reqwest`. The reasoning is that we want to have greater control and access to low level `hyper` APIs when implementing `fetch` API as well as `node:http` module. --------- Co-authored-by: Bartek IwaƄczuk <biwanczuk@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/Cargo.toml1
-rw-r--r--tests/integration/inspector_tests.rs2
-rw-r--r--tests/integration/npm_tests.rs2
-rw-r--r--tests/integration/run_tests.rs2
-rw-r--r--tests/integration/serve_tests.rs1
-rw-r--r--tests/specs/cert/localhost_unsafe_ssl/localhost_unsafe_ssl.ts.out2
-rw-r--r--tests/testdata/run/fetch_async_error_stack.ts.out2
-rw-r--r--tests/unit/fetch_test.ts28
-rw-r--r--tests/unit/http_test.ts16
-rw-r--r--tests/unit/serve_test.ts4
10 files changed, 33 insertions, 27 deletions
diff --git a/tests/Cargo.toml b/tests/Cargo.toml
index 9d513571b..34cffbb40 100644
--- a/tests/Cargo.toml
+++ b/tests/Cargo.toml
@@ -53,6 +53,7 @@ once_cell.workspace = true
os_pipe.workspace = true
pretty_assertions.workspace = true
regex.workspace = true
+reqwest.workspace = true
serde.workspace = true
test_util.workspace = true
tokio.workspace = true
diff --git a/tests/integration/inspector_tests.rs b/tests/integration/inspector_tests.rs
index 57831ab46..fa1b3a9d8 100644
--- a/tests/integration/inspector_tests.rs
+++ b/tests/integration/inspector_tests.rs
@@ -6,7 +6,7 @@ use deno_core::error::AnyError;
use deno_core::serde_json;
use deno_core::serde_json::json;
use deno_core::url;
-use deno_fetch::reqwest;
+
use fastwebsockets::FragmentCollector;
use fastwebsockets::Frame;
use fastwebsockets::WebSocket;
diff --git a/tests/integration/npm_tests.rs b/tests/integration/npm_tests.rs
index 82f0697d5..dba519087 100644
--- a/tests/integration/npm_tests.rs
+++ b/tests/integration/npm_tests.rs
@@ -3,7 +3,7 @@
use deno_core::serde_json;
use deno_core::serde_json::json;
use deno_core::serde_json::Value;
-use deno_fetch::reqwest;
+
use pretty_assertions::assert_eq;
use test_util as util;
use test_util::itest;
diff --git a/tests/integration/run_tests.rs b/tests/integration/run_tests.rs
index d4d1fea2e..6a9b47b1a 100644
--- a/tests/integration/run_tests.rs
+++ b/tests/integration/run_tests.rs
@@ -11,7 +11,7 @@ use std::sync::Arc;
use bytes::Bytes;
use deno_core::serde_json::json;
use deno_core::url;
-use deno_fetch::reqwest;
+
use deno_tls::rustls;
use deno_tls::rustls::ClientConnection;
use deno_tls::rustls_pemfile;
diff --git a/tests/integration/serve_tests.rs b/tests/integration/serve_tests.rs
index 85de068c9..3d64ce3a3 100644
--- a/tests/integration/serve_tests.rs
+++ b/tests/integration/serve_tests.rs
@@ -2,7 +2,6 @@
use std::io::Read;
-use deno_fetch::reqwest;
use pretty_assertions::assert_eq;
use regex::Regex;
use test_util as util;
diff --git a/tests/specs/cert/localhost_unsafe_ssl/localhost_unsafe_ssl.ts.out b/tests/specs/cert/localhost_unsafe_ssl/localhost_unsafe_ssl.ts.out
index 3067fffae..f98c7e4e4 100644
--- a/tests/specs/cert/localhost_unsafe_ssl/localhost_unsafe_ssl.ts.out
+++ b/tests/specs/cert/localhost_unsafe_ssl/localhost_unsafe_ssl.ts.out
@@ -1,3 +1,3 @@
DANGER: TLS certificate validation is disabled for: deno.land
-error: Import 'https://localhost:5545/subdir/mod2.ts' failed: error sending request for url (https://localhost:5545/subdir/mod2.ts)
+error: Import 'https://localhost:5545/subdir/mod2.ts' failed: client error[WILDCARD]
at file:///[WILDCARD]/cafile_url_imports.ts:[WILDCARD]
diff --git a/tests/testdata/run/fetch_async_error_stack.ts.out b/tests/testdata/run/fetch_async_error_stack.ts.out
index e8169228f..06d92d15a 100644
--- a/tests/testdata/run/fetch_async_error_stack.ts.out
+++ b/tests/testdata/run/fetch_async_error_stack.ts.out
@@ -1,4 +1,4 @@
-error: Uncaught (in promise) TypeError: error sending request for url[WILDCARD]
+error: Uncaught (in promise) TypeError: client error[WILDCARD]
await fetch("https://nonexistent.deno.land/");
^[WILDCARD]
at async fetch (ext:[WILDCARD])
diff --git a/tests/unit/fetch_test.ts b/tests/unit/fetch_test.ts
index b549be9a4..bc3822d99 100644
--- a/tests/unit/fetch_test.ts
+++ b/tests/unit/fetch_test.ts
@@ -67,7 +67,7 @@ Deno.test(
await fetch(`http://localhost:${port}`);
},
TypeError,
- "error sending request for url",
+ "client error (Connect)",
);
},
);
@@ -80,7 +80,7 @@ Deno.test(
await fetch("http://nil/");
},
TypeError,
- "error sending request for url",
+ "client error (Connect)",
);
},
);
@@ -688,7 +688,7 @@ Deno.test(
"accept: */*\r\n",
"accept-language: *\r\n",
`user-agent: Deno/${Deno.version.deno}\r\n`,
- "accept-encoding: gzip, br\r\n",
+ "accept-encoding: gzip,br\r\n",
`host: ${addr}\r\n\r\n`,
].join("");
assertEquals(actual, expected);
@@ -720,7 +720,7 @@ Deno.test(
"accept: text/html\r\n",
"accept-language: en-US\r\n",
`user-agent: Deno/${Deno.version.deno}\r\n`,
- "accept-encoding: gzip, br\r\n",
+ "accept-encoding: gzip,br\r\n",
`host: ${addr}\r\n\r\n`,
].join("");
assertEquals(actual, expected);
@@ -750,15 +750,16 @@ Deno.test(
const actual = new TextDecoder().decode((await bufPromise).bytes());
const expected = [
"POST /blah HTTP/1.1\r\n",
+ `content-length: ${body.length}\r\n`,
"hello: World\r\n",
"foo: Bar\r\n",
"content-type: text/plain;charset=UTF-8\r\n",
"accept: */*\r\n",
"accept-language: *\r\n",
`user-agent: Deno/${Deno.version.deno}\r\n`,
- "accept-encoding: gzip, br\r\n",
+ "accept-encoding: gzip,br\r\n",
`host: ${addr}\r\n`,
- `content-length: ${body.length}\r\n\r\n`,
+ `\r\n`,
body,
].join("");
assertEquals(actual, expected);
@@ -789,14 +790,15 @@ Deno.test(
const actual = new TextDecoder().decode((await bufPromise).bytes());
const expected = [
"POST /blah HTTP/1.1\r\n",
+ `content-length: ${body.byteLength}\r\n`,
"hello: World\r\n",
"foo: Bar\r\n",
"accept: */*\r\n",
"accept-language: *\r\n",
`user-agent: Deno/${Deno.version.deno}\r\n`,
- "accept-encoding: gzip, br\r\n",
+ "accept-encoding: gzip,br\r\n",
`host: ${addr}\r\n`,
- `content-length: ${body.byteLength}\r\n\r\n`,
+ `\r\n`,
bodyStr,
].join("");
assertEquals(actual, expected);
@@ -827,7 +829,7 @@ Deno.test(
"accept: */*\r\n",
"accept-language: *\r\n",
`user-agent: Deno/${Deno.version.deno}\r\n`,
- "accept-encoding: gzip, br\r\n",
+ "accept-encoding: gzip,br\r\n",
`host: ${addr}\r\n\r\n`,
].join("");
assertEquals(actual, expected);
@@ -859,7 +861,7 @@ Deno.test(
"accept: */*\r\n",
"accept-language: *\r\n",
`user-agent: Deno/${Deno.version.deno}\r\n`,
- "accept-encoding: gzip, br\r\n\r\n",
+ "accept-encoding: gzip,br\r\n\r\n",
].join("");
assertEquals(actual, expected);
},
@@ -1226,7 +1228,7 @@ Deno.test(
"accept: */*\r\n",
"accept-language: *\r\n",
`user-agent: Deno/${Deno.version.deno}\r\n`,
- "accept-encoding: gzip, br\r\n",
+ "accept-encoding: gzip,br\r\n",
`host: ${addr}\r\n`,
`transfer-encoding: chunked\r\n\r\n`,
"B\r\n",
@@ -1824,7 +1826,7 @@ Deno.test(
await fetch(`http://${addr}/`);
},
TypeError,
- "error sending request",
+ "client error",
);
listener.close();
@@ -1880,7 +1882,7 @@ Deno.test(
await response.arrayBuffer();
},
Error,
- "error decoding response body",
+ "body",
);
listener.close();
diff --git a/tests/unit/http_test.ts b/tests/unit/http_test.ts
index eddb1520b..03c30965f 100644
--- a/tests/unit/http_test.ts
+++ b/tests/unit/http_test.ts
@@ -2572,9 +2572,11 @@ for (const compression of [true, false]) {
const result = await reader.read();
assert(!result.done);
assertEquals(result.value, new Uint8Array([65]));
- const err = await assertRejects(() => reader.read());
- assert(err instanceof TypeError);
- assert(err.message.includes("error decoding response body"));
+ await assertRejects(
+ () => reader.read(),
+ TypeError,
+ "body",
+ );
const httpConn = await server;
httpConn.close();
@@ -2608,9 +2610,11 @@ for (const compression of [true, false]) {
const result = await reader.read();
assert(!result.done);
assertEquals(result.value, new Uint8Array([65]));
- const err = await assertRejects(() => reader.read());
- assert(err instanceof TypeError);
- assert(err.message.includes("error decoding response body"));
+ await assertRejects(
+ () => reader.read(),
+ TypeError,
+ "body",
+ );
const httpConn = await server;
httpConn.close();
diff --git a/tests/unit/serve_test.ts b/tests/unit/serve_test.ts
index 4239221be..ee87d8189 100644
--- a/tests/unit/serve_test.ts
+++ b/tests/unit/serve_test.ts
@@ -3522,7 +3522,7 @@ Deno.test(
fail();
} catch (clientError) {
assert(clientError instanceof TypeError);
- assert(clientError.message.includes("error sending request for url"));
+ assert(clientError.message.includes("client error"));
} finally {
ac.abort();
await server.finished;
@@ -3570,7 +3570,7 @@ Deno.test({
fail();
} catch (clientError) {
assert(clientError instanceof TypeError);
- assert(clientError.message.includes("error sending request for url"));
+ assert(clientError.message.includes("client error"));
} finally {
ac.abort();
await server.finished;