summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2024-07-18 00:37:31 +0100
committerGitHub <noreply@github.com>2024-07-18 01:37:31 +0200
commit7b33623b1d70803b43e511a58666a73dd0b2ed67 (patch)
tree2d900f2be67caebf6a886d6e06a340b095e636cc /tests
parentf4b9d8586215fc07c28998e5d896fefa876139b7 (diff)
Reland "refactor(fetch): reimplement fetch with hyper instead of reqwest" (#24593)
Originally landed in https://github.com/denoland/deno/commit/f6fd6619e708a515831f707438368d81b0c9aa56. Reverted in https://github.com/denoland/deno/pull/24574. This reland contains a fix that sends "Accept: */*" header for calls made from "FileFetcher". Absence of this header made downloading source code from JSR broken. This is tested by ensuring this header is present in the test server that servers JSR packages. --------- Co-authored-by: Sean McArthur <sean@seanmonstar.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
-rw-r--r--tests/util/server/src/servers/jsr_registry.rs11
11 files changed, 44 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;
diff --git a/tests/util/server/src/servers/jsr_registry.rs b/tests/util/server/src/servers/jsr_registry.rs
index ce1a34ac9..affd2c30e 100644
--- a/tests/util/server/src/servers/jsr_registry.rs
+++ b/tests/util/server/src/servers/jsr_registry.rs
@@ -139,6 +139,17 @@ async fn registry_server_handler(
return Ok(res);
}
+ let accept_header = req
+ .headers()
+ .get("accept")
+ .and_then(|s| s.to_str().ok())
+ .unwrap_or_default();
+ if accept_header != "*/*" {
+ let res = Response::builder()
+ .status(StatusCode::BAD_REQUEST)
+ .body(UnsyncBoxBody::new(Empty::new()))?;
+ return Ok(res);
+ }
// serve the registry package files
let mut file_path = tests_path().join("registry").join("jsr").to_path_buf();
file_path.push(