Skip to content

Commit

Permalink
chore(remix-node): bump @remix-run/web-fetch to latest (remix-run#6120
Browse files Browse the repository at this point in the history
)

Signed-off-by: Logan McAnsh <[email protected]>
  • Loading branch information
mcansh authored Apr 25, 2023
1 parent e4713ea commit 37d8b7d
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 479 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
if: github.repository == 'remix-run/remix'
uses: ./.github/workflows/reusable-test.yml
with:
node_version: '["19"]'
node_version: '["latest"]'
14 changes: 5 additions & 9 deletions integration/error-data-request-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,13 @@ test.describe("ErrorBoundary", () => {
});

test("returns a 405 x-remix-error on a data fetch with a bad method", async () => {
let response = await fixture.requestData(
`/loader-return-json`,
"routes/loader-return-json",
{
expect(() =>
fixture.requestData("/loader-return-json", "routes/loader-return-json", {
method: "TRACE",
}
})
).rejects.toThrowError(
`Failed to construct 'Request': 'TRACE' HTTP method is unsupported.`
);
expect(response.status).toBe(405);
expect(response.headers.get("X-Remix-Error")).toBe("yes");
expect(await response.text()).toMatch("Unexpected Server Error");
assertConsoleError('Error: Invalid request method "TRACE"');
});

test("returns a 403 x-remix-error on a data fetch GET to a bad path", async () => {
Expand Down
153 changes: 27 additions & 126 deletions packages/remix-architect/__tests__/server-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import path from "path";
import lambdaTester from "lambda-tester";
import type { APIGatewayProxyEventV2 } from "aws-lambda";
import {
// This has been added as a global in node 15+, but we expose it here while we
// support Node 14
// eslint-disable-next-line @typescript-eslint/no-unused-vars
AbortController,
createRequestHandler as createRemixRequestHandler,
Response as NodeResponse,
} from "@remix-run/node";
Expand Down Expand Up @@ -204,145 +200,50 @@ describe("architect createRequestHandler", () => {
describe("architect createRemixHeaders", () => {
describe("creates fetch headers from architect headers", () => {
it("handles empty headers", () => {
expect(createRemixHeaders({}, undefined)).toMatchInlineSnapshot(`
Headers {
Symbol(query): Array [],
Symbol(context): null,
}
`);
let headers = createRemixHeaders({});
expect(headers.raw()).toMatchInlineSnapshot(`Object {}`);
});

it("handles simple headers", () => {
expect(createRemixHeaders({ "x-foo": "bar" }, undefined))
.toMatchInlineSnapshot(`
Headers {
Symbol(query): Array [
"x-foo",
"bar",
],
Symbol(context): null,
}
`);
let headers = createRemixHeaders({ "x-foo": "bar" });
expect(headers.get("x-foo")).toBe("bar");
});

it("handles multiple headers", () => {
expect(createRemixHeaders({ "x-foo": "bar", "x-bar": "baz" }, undefined))
.toMatchInlineSnapshot(`
Headers {
Symbol(query): Array [
"x-foo",
"bar",
"x-bar",
"baz",
],
Symbol(context): null,
}
`);
let headers = createRemixHeaders({ "x-foo": "bar", "x-bar": "baz" });
expect(headers.get("x-foo")).toBe("bar");
expect(headers.get("x-bar")).toBe("baz");
});

it("handles headers with multiple values", () => {
expect(createRemixHeaders({ "x-foo": "bar, baz" }, undefined))
.toMatchInlineSnapshot(`
Headers {
Symbol(query): Array [
"x-foo",
"bar, baz",
],
Symbol(context): null,
}
`);
});

it("handles headers with multiple values and multiple headers", () => {
expect(
createRemixHeaders({ "x-foo": "bar, baz", "x-bar": "baz" }, undefined)
).toMatchInlineSnapshot(`
Headers {
Symbol(query): Array [
"x-foo",
"bar, baz",
"x-bar",
"baz",
],
Symbol(context): null,
}
`);
let headers = createRemixHeaders({
"x-foo": "bar, baz",
"x-bar": "baz",
});
expect(headers.getAll("x-foo")).toEqual(["bar, baz"]);
expect(headers.get("x-bar")).toBe("baz");
});

it("handles cookies", () => {
expect(
createRemixHeaders({ "x-something-else": "true" }, [
"__session=some_value",
"__other=some_other_value",
])
).toMatchInlineSnapshot(`
Headers {
Symbol(query): Array [
"x-something-else",
"true",
"cookie",
"__session=some_value; __other=some_other_value",
],
Symbol(context): null,
}
`);
it("handles multiple request cookies", () => {
let headers = createRemixHeaders({}, [
"__session=some_value",
"__other=some_other_value",
]);
expect(headers.getAll("cookie")).toEqual([
"__session=some_value; __other=some_other_value",
]);
});
});
});

describe("architect createRemixRequest", () => {
it("creates a request with the correct headers", () => {
expect(
createRemixRequest(
createMockEvent({
cookies: ["__session=value"],
})
)
).toMatchInlineSnapshot(`
NodeRequest {
"agent": undefined,
"compress": true,
"counter": 0,
"follow": 20,
"highWaterMark": 16384,
"insecureHTTPParser": false,
"size": 0,
Symbol(Body internals): Object {
"body": null,
"boundary": null,
"disturbed": false,
"error": null,
"size": 0,
"type": null,
},
Symbol(Request internals): Object {
"credentials": "same-origin",
"headers": Headers {
Symbol(query): Array [
"accept",
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"accept-encoding",
"gzip, deflate",
"accept-language",
"en-US,en;q=0.9",
"cookie",
"__session=value",
"host",
"localhost:3333",
"upgrade-insecure-requests",
"1",
"user-agent",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Safari/605.1.15",
],
Symbol(context): null,
},
"method": "GET",
"parsedURL": "https://localhost:3333/",
"redirect": "follow",
"signal": AbortSignal {},
},
}
`);
let remixRequest = createRemixRequest(
createMockEvent({ cookies: ["__session=value"] })
);

expect(remixRequest.method).toBe("GET");
expect(remixRequest.headers.get("cookie")).toBe("__session=value");
});
});

Expand Down
140 changes: 31 additions & 109 deletions packages/remix-express/__tests__/server-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ describe("express createRequestHandler", () => {
});

let request = supertest(createApp());
// note: vercel's createServerWithHelpers requires a x-now-bridge-request-id
let res = await request.get("/").set({ "x-now-bridge-request-id": "2" });

let res = await request.get("/");
expect(res.status).toBe(200);
expect(res.text).toBe("hello world");
});
Expand Down Expand Up @@ -159,88 +157,41 @@ describe("express createRequestHandler", () => {
describe("express createRemixHeaders", () => {
describe("creates fetch headers from express headers", () => {
it("handles empty headers", () => {
expect(createRemixHeaders({})).toMatchInlineSnapshot(`
Headers {
Symbol(query): Array [],
Symbol(context): null,
}
`);
let headers = createRemixHeaders({});
expect(headers.raw()).toMatchInlineSnapshot(`Object {}`);
});

it("handles simple headers", () => {
expect(createRemixHeaders({ "x-foo": "bar" })).toMatchInlineSnapshot(`
Headers {
Symbol(query): Array [
"x-foo",
"bar",
],
Symbol(context): null,
}
`);
let headers = createRemixHeaders({ "x-foo": "bar" });
expect(headers.get("x-foo")).toBe("bar");
});

it("handles multiple headers", () => {
expect(createRemixHeaders({ "x-foo": "bar", "x-bar": "baz" }))
.toMatchInlineSnapshot(`
Headers {
Symbol(query): Array [
"x-foo",
"bar",
"x-bar",
"baz",
],
Symbol(context): null,
}
`);
let headers = createRemixHeaders({ "x-foo": "bar", "x-bar": "baz" });
expect(headers.get("x-foo")).toBe("bar");
expect(headers.get("x-bar")).toBe("baz");
});

it("handles headers with multiple values", () => {
expect(createRemixHeaders({ "x-foo": "bar, baz" }))
.toMatchInlineSnapshot(`
Headers {
Symbol(query): Array [
"x-foo",
"bar, baz",
],
Symbol(context): null,
}
`);
});

it("handles headers with multiple values and multiple headers", () => {
expect(createRemixHeaders({ "x-foo": "bar, baz", "x-bar": "baz" }))
.toMatchInlineSnapshot(`
Headers {
Symbol(query): Array [
"x-foo",
"bar, baz",
"x-bar",
"baz",
],
Symbol(context): null,
}
`);
let headers = createRemixHeaders({
"x-foo": ["bar", "baz"],
"x-bar": "baz",
});
expect(headers.getAll("x-foo")).toEqual(["bar", "baz"]);
expect(headers.get("x-bar")).toBe("baz");
});

it("handles multiple set-cookie headers", () => {
expect(
createRemixHeaders({
"set-cookie": [
"__session=some_value; Path=/; Secure; HttpOnly; MaxAge=7200; SameSite=Lax",
"__other=some_other_value; Path=/; Secure; HttpOnly; MaxAge=3600; SameSite=Lax",
],
})
).toMatchInlineSnapshot(`
Headers {
Symbol(query): Array [
"set-cookie",
"__session=some_value; Path=/; Secure; HttpOnly; MaxAge=7200; SameSite=Lax",
"set-cookie",
"__other=some_other_value; Path=/; Secure; HttpOnly; MaxAge=3600; SameSite=Lax",
],
Symbol(context): null,
}
`);
let headers = createRemixHeaders({
"set-cookie": [
"__session=some_value; Path=/; Secure; HttpOnly; MaxAge=7200; SameSite=Lax",
"__other=some_other_value; Path=/; Secure; HttpOnly; Expires=Wed, 21 Oct 2015 07:28:00 GMT; SameSite=Lax",
],
});
expect(headers.getAll("set-cookie")).toEqual([
"__session=some_value; Path=/; Secure; HttpOnly; MaxAge=7200; SameSite=Lax",
"__other=some_other_value; Path=/; Secure; HttpOnly; Expires=Wed, 21 Oct 2015 07:28:00 GMT; SameSite=Lax",
]);
});
});
});
Expand All @@ -259,41 +210,12 @@ describe("express createRemixRequest", () => {
});
let expressResponse = createResponse();

expect(createRemixRequest(expressRequest, expressResponse))
.toMatchInlineSnapshot(`
NodeRequest {
"agent": undefined,
"compress": true,
"counter": 0,
"follow": 20,
"highWaterMark": 16384,
"insecureHTTPParser": false,
"size": 0,
Symbol(Body internals): Object {
"body": null,
"boundary": null,
"disturbed": false,
"error": null,
"size": 0,
"type": null,
},
Symbol(Request internals): Object {
"credentials": "same-origin",
"headers": Headers {
Symbol(query): Array [
"cache-control",
"max-age=300, s-maxage=3600",
"host",
"localhost:3000",
],
Symbol(context): null,
},
"method": "GET",
"parsedURL": "http://localhost:3000/foo/bar",
"redirect": "follow",
"signal": AbortSignal {},
},
}
`);
let remixRequest = createRemixRequest(expressRequest, expressResponse);

expect(remixRequest.method).toBe("GET");
expect(remixRequest.headers.get("cache-control")).toBe(
"max-age=300, s-maxage=3600"
);
expect(remixRequest.headers.get("host")).toBe("localhost:3000");
});
});
Loading

0 comments on commit 37d8b7d

Please sign in to comment.