summaryrefslogtreecommitdiff
path: root/cli/js/tests/fetch_test.ts
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-03-10 16:38:02 +0100
committerGitHub <noreply@github.com>2020-03-10 16:38:02 +0100
commitfbc4731256a698c07d0d842575d3678d7dc58715 (patch)
treefd085bf832513989f3fa0cf73287fe3e520309a5 /cli/js/tests/fetch_test.ts
parent62f4a2a788a46af88e47472738d1a98fa247b9b0 (diff)
refactor: uncomment tests broken tests, use skip (#4311)
* uncomment broken tests, use skip: - net_test.ts - url_test.ts - fetch_test.ts
Diffstat (limited to 'cli/js/tests/fetch_test.ts')
-rw-r--r--cli/js/tests/fetch_test.ts193
1 files changed, 114 insertions, 79 deletions
diff --git a/cli/js/tests/fetch_test.ts b/cli/js/tests/fetch_test.ts
index 5ebef92d9..dd988267e 100644
--- a/cli/js/tests/fetch_test.ts
+++ b/cli/js/tests/fetch_test.ts
@@ -203,15 +203,18 @@ unitTest(
}
);
-// The feature below is not implemented, but the test should work after implementation
-/*
-unitTest({ perms: { net: true} }, async function fetchWithInfRedirection(): Promise<
- void
-> {
- const response = await fetch("http://localhost:4549/cli/tests"); // will redirect to the same place
- assertEquals(response.status, 0); // network error
-});
-*/
+unitTest(
+ {
+ // FIXME(bartlomieju):
+ // The feature below is not implemented, but the test should work after implementation
+ skip: true,
+ perms: { net: true }
+ },
+ async function fetchWithInfRedirection(): Promise<void> {
+ const response = await fetch("http://localhost:4549/cli/tests"); // will redirect to the same place
+ assertEquals(response.status, 0); // network error
+ }
+);
unitTest(
{ perms: { net: true } },
@@ -320,11 +323,14 @@ unitTest({ perms: { net: true } }, async function fetchUserAgent(): Promise<
// at Object.assertEquals (file:///C:/deno/js/testing/util.ts:29:11)
// at fetchPostBodyString (file
-/*
function bufferServer(addr: string): Deno.Buffer {
- const listener = Deno.listen(addr);
+ const [hostname, port] = addr.split(":");
+ const listener = Deno.listen({
+ hostname,
+ port: Number(port)
+ }) as Deno.Listener;
const buf = new Deno.Buffer();
- listener.accept().then(async conn => {
+ listener.accept().then(async (conn: Deno.Conn) => {
const p1 = buf.readFrom(conn);
const p2 = conn.write(
new TextEncoder().encode(
@@ -344,75 +350,104 @@ function bufferServer(addr: string): Deno.Buffer {
return buf;
}
-unitTest({ perms: { net: true} }, async function fetchRequest():Promise<void> {
- const addr = "127.0.0.1:4501";
- const buf = bufferServer(addr);
- const response = await fetch(`http://${addr}/blah`, {
- method: "POST",
- headers: [["Hello", "World"], ["Foo", "Bar"]]
- });
- assertEquals(response.status, 404);
- assertEquals(response.headers.get("Content-Length"), "2");
-
- const actual = new TextDecoder().decode(buf.bytes());
- const expected = [
- "POST /blah HTTP/1.1\r\n",
- "hello: World\r\n",
- "foo: Bar\r\n",
- `host: ${addr}\r\n\r\n`
- ].join("");
- assertEquals(actual, expected);
-});
+unitTest(
+ {
+ // FIXME(bartlomieju)
+ skip: true,
+ perms: { net: true }
+ },
+ async function fetchRequest(): Promise<void> {
+ const addr = "127.0.0.1:4501";
+ const buf = bufferServer(addr);
+ const response = await fetch(`http://${addr}/blah`, {
+ method: "POST",
+ headers: [
+ ["Hello", "World"],
+ ["Foo", "Bar"]
+ ]
+ });
+ assertEquals(response.status, 404);
+ assertEquals(response.headers.get("Content-Length"), "2");
+
+ const actual = new TextDecoder().decode(buf.bytes());
+ const expected = [
+ "POST /blah HTTP/1.1\r\n",
+ "hello: World\r\n",
+ "foo: Bar\r\n",
+ `host: ${addr}\r\n\r\n`
+ ].join("");
+ assertEquals(actual, expected);
+ }
+);
-unitTest({ perms: { net: true} }, async function fetchPostBodyString():Promise<void> {
- const addr = "127.0.0.1:4502";
- const buf = bufferServer(addr);
- const body = "hello world";
- const response = await fetch(`http://${addr}/blah`, {
- method: "POST",
- headers: [["Hello", "World"], ["Foo", "Bar"]],
- body
- });
- assertEquals(response.status, 404);
- assertEquals(response.headers.get("Content-Length"), "2");
-
- const actual = new TextDecoder().decode(buf.bytes());
- const expected = [
- "POST /blah HTTP/1.1\r\n",
- "hello: World\r\n",
- "foo: Bar\r\n",
- `host: ${addr}\r\n`,
- `content-length: ${body.length}\r\n\r\n`,
- body
- ].join("");
- assertEquals(actual, expected);
-});
+unitTest(
+ {
+ // FIXME(bartlomieju)
+ skip: true,
+ perms: { net: true }
+ },
+ async function fetchPostBodyString(): Promise<void> {
+ const addr = "127.0.0.1:4502";
+ const buf = bufferServer(addr);
+ const body = "hello world";
+ const response = await fetch(`http://${addr}/blah`, {
+ method: "POST",
+ headers: [
+ ["Hello", "World"],
+ ["Foo", "Bar"]
+ ],
+ body
+ });
+ assertEquals(response.status, 404);
+ assertEquals(response.headers.get("Content-Length"), "2");
+
+ const actual = new TextDecoder().decode(buf.bytes());
+ const expected = [
+ "POST /blah HTTP/1.1\r\n",
+ "hello: World\r\n",
+ "foo: Bar\r\n",
+ `host: ${addr}\r\n`,
+ `content-length: ${body.length}\r\n\r\n`,
+ body
+ ].join("");
+ assertEquals(actual, expected);
+ }
+);
-unitTest({ perms: { net: true} }, async function fetchPostBodyTypedArray():Promise<void> {
- const addr = "127.0.0.1:4503";
- const buf = bufferServer(addr);
- const bodyStr = "hello world";
- const body = new TextEncoder().encode(bodyStr);
- const response = await fetch(`http://${addr}/blah`, {
- method: "POST",
- headers: [["Hello", "World"], ["Foo", "Bar"]],
- body
- });
- assertEquals(response.status, 404);
- assertEquals(response.headers.get("Content-Length"), "2");
-
- const actual = new TextDecoder().decode(buf.bytes());
- const expected = [
- "POST /blah HTTP/1.1\r\n",
- "hello: World\r\n",
- "foo: Bar\r\n",
- `host: ${addr}\r\n`,
- `content-length: ${body.byteLength}\r\n\r\n`,
- bodyStr
- ].join("");
- assertEquals(actual, expected);
-});
-*/
+unitTest(
+ {
+ // FIXME(bartlomieju)
+ skip: true,
+ perms: { net: true }
+ },
+ async function fetchPostBodyTypedArray(): Promise<void> {
+ const addr = "127.0.0.1:4503";
+ const buf = bufferServer(addr);
+ const bodyStr = "hello world";
+ const body = new TextEncoder().encode(bodyStr);
+ const response = await fetch(`http://${addr}/blah`, {
+ method: "POST",
+ headers: [
+ ["Hello", "World"],
+ ["Foo", "Bar"]
+ ],
+ body
+ });
+ assertEquals(response.status, 404);
+ assertEquals(response.headers.get("Content-Length"), "2");
+
+ const actual = new TextDecoder().decode(buf.bytes());
+ const expected = [
+ "POST /blah HTTP/1.1\r\n",
+ "hello: World\r\n",
+ "foo: Bar\r\n",
+ `host: ${addr}\r\n`,
+ `content-length: ${body.byteLength}\r\n\r\n`,
+ bodyStr
+ ].join("");
+ assertEquals(actual, expected);
+ }
+);
unitTest(
{