Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add and update node adapter tests #241

Merged
merged 35 commits into from
Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4e938cd
feat(express): add support for multiple 'Set-Cookie' and other multi …
mcansh Aug 10, 2021
8c93d19
test(express): add tests for createRemixHeaders
mcansh Aug 10, 2021
52d0209
test(express): add basic test for createRemixRequest
mcansh Aug 10, 2021
ba96473
test(architect): add tests for headers
mcansh Aug 10, 2021
97c515c
test(vercel): extract headers conversion function, start adding tests…
mcansh Aug 10, 2021
e7e69fd
test(vercel): shutdown server after running test
mcansh Aug 10, 2021
bbb6cd4
chore(architect): use requestContent protocol; add test for arc creat…
mcansh Aug 10, 2021
682e82d
test(architect): remove tes as I was handling it in the wrong direction
mcansh Aug 10, 2021
b97c453
chore: remove `Object.fromEntries(responseHeaders)` spreading
mcansh Aug 10, 2021
8f5f397
test(express): update createRemixHeaders to support multiple headers …
mcansh Aug 10, 2021
651f268
test(vercel): add more tests
mcansh Aug 10, 2021
f8f52ab
chore: ignore test directories when using tsc
mcansh Aug 11, 2021
01e5134
feat(architect): make multi set-cookie headers work
mcansh Aug 11, 2021
091448f
feat(vercel): make multi set-cookie headers work
mcansh Aug 11, 2021
6356ca3
test(architect): add tests for createRemixRequest
mcansh Aug 11, 2021
739084c
test(vercel): add test for createRequestHandler
mcansh Aug 11, 2021
d7cbc23
test(vercel): use supertest for better header testing
mcansh Aug 12, 2021
63017e0
chore(deps/vercel): add @types/supertest
mcansh Aug 12, 2021
a0b21a4
test(express,vercel): bring tests to parity
mcansh Aug 12, 2021
fc40826
fix(express): read port from request app settings
mcansh Aug 12, 2021
5a92783
fix(express): req.get("host") returns the port
mcansh Aug 12, 2021
c291fd7
test(express): update request mocking
mcansh Aug 12, 2021
9c640ab
Merge branch 'dev' into logan/rem-179-node-adapter-tests
mcansh Aug 12, 2021
7b8a3dd
chore: update notes
mcansh Aug 13, 2021
9b7a9b8
fix(express): im dumb
mcansh Aug 13, 2021
00512cd
feat: actually make multiple set-cookie headers work
mcansh Aug 17, 2021
94aa8e1
test: add test for multiple set cookie headers
mcansh Aug 17, 2021
863408a
test: update config snapshots due to new route
mcansh Aug 17, 2021
6589272
chore(vercel): remove extraneous setting of status code
mcansh Aug 18, 2021
bb3d237
Merge branch 'dev' into logan/rem-179-node-adapter-tests
mcansh Aug 18, 2021
8930cd3
Add space after comma
mjackson Aug 18, 2021
37631e9
Code formatting
mjackson Aug 18, 2021
1721032
feat(getDocumentHeaders): re-add support for multiple set-cookie headers
mcansh Aug 18, 2021
601d67a
test(arc,vercel): update mock import
mcansh Aug 18, 2021
7df7d19
chore: update changelog
mcansh Aug 18, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
- Updated .npmrc to minimum required version for webcrypto API (v15)
- Abstracted req and res types through the platform
- Add base64 encoding primitives to node globals (atob and btoa)
- adds and improves testing around node adapters
- fixes the ability to set multiple Set-Cookie headers

This is a history of changes to [Remix](https://remix.run).

Expand Down
7 changes: 3 additions & 4 deletions docs/guides/styling.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,11 @@ Here's some sample code to show how you might use Styled Components with Remix:
</StylesContext.Provider>
);

responseHeaders.set("Content-Type", "text/html")

return new Response("<!DOCTYPE html>" + markup, {
status: responseStatusCode,
headers: {
...Object.fromEntries(responseHeaders),
"Content-Type": "text/html"
}
headers: responseHeaders
});
}
```
Expand Down
7 changes: 3 additions & 4 deletions fixtures/gists-app/app/entry.server.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ export default function handleRequest(
<RemixServer context={remixContext} url={request.url} />
);

responseHeaders.set("Content-Type", "text/html");

return new Response("<!DOCTYPE html>" + markup, {
status: responseStatusCode,
headers: {
...Object.fromEntries(responseHeaders),
"Content-Type": "text/html"
}
headers: responseHeaders
});
}
3 changes: 3 additions & 0 deletions fixtures/gists-app/app/routes/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ export default function Index() {
Render error in nested route with ErrorBoundary
</Link>
</li>
<li>
<Link to="/multiple-set-cookies">Multiple Set Cookie Headers</Link>
</li>

<li>
<Link to="prefs">Preferences</Link>
Expand Down
41 changes: 41 additions & 0 deletions fixtures/gists-app/app/routes/multiple-set-cookies.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as React from "react";
import type {
ActionFunction,
LoaderFunction,
MetaFunction,
RouteComponent
} from "remix";
import { redirect, json, Form } from "remix";
import { Headers } from "@remix-run/node";

let loader: LoaderFunction = async ({ request }) => {
let headers = new Headers();
headers.append("Set-Cookie", "foo=bar");
headers.append("Set-Cookie", "bar=baz");
return json({}, { headers });
};

let action: ActionFunction = async () => {
let headers = new Headers();
headers.append("Set-Cookie", "another=one");
headers.append("Set-Cookie", "how-about=two");
return redirect("/multiple-set-cookies", { headers });
};

let meta: MetaFunction = () => ({
title: "Multi Set Cookie Headers"
});

let MultipleSetCookiesPage: RouteComponent = () => {
return (
<>
<p>👋</p>
<Form method="post">
<button type="submit">Add cookies</button>
</Form>
</>
);
};

export default MultipleSetCookiesPage;
export { action, loader, meta };
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ exports[`the server HTML for the root URL is correct 1`] = `
>Render error in nested route with ErrorBoundary</a
>
</li>
<li><a href=\\"/multiple-set-cookies\\">Multiple Set Cookie Headers</a></li>
<li><a href=\\"/prefs\\">Preferences</a></li>
</ul>
</nav>
Expand Down
36 changes: 36 additions & 0 deletions fixtures/gists-app/tests/multiple-set-cookies-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { Browser, Page } from "puppeteer";
import puppeteer from "puppeteer";

import { collectResponses } from "./utils";

const testPort = 3000;
const testServer = `http://localhost:${testPort}`;

describe("can set multiple set cookies headers", () => {
let browser: Browser;
let page: Page;

beforeEach(async () => {
browser = await puppeteer.launch();
page = await browser.newPage();
});

afterEach(() => browser.close());

describe("loader headers", () => {
it("are correct", async () => {
let responses = collectResponses(
page,
url => url.pathname === "/multiple-set-cookies"
);

await page.goto(`${testServer}/multiple-set-cookies`);

expect(responses).toHaveLength(1);
expect(responses[0].headers()["set-cookie"]).toMatchInlineSnapshot(`
"foo=bar
bar=baz"
`);
});
});
});
7 changes: 3 additions & 4 deletions fixtures/tutorial/app/entry.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ export default function handleRequest(
<RemixServer context={remixContext} url={request.url} />
);

responseHeaders.set("Content-Type", "text/html");

return new Response("<!DOCTYPE html>" + markup, {
status: responseStatusCode,
headers: {
...Object.fromEntries(responseHeaders),
"Content-Type": "text/html"
}
headers: responseHeaders
});
}
25 changes: 19 additions & 6 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ module.exports = {
testEnvironment: "node",
testMatch: ["<rootDir>/packages/remix-dev/**/*-test.[jt]s?(x)"]
},
{
displayName: "express",
testEnvironment: "node",
testMatch: ["<rootDir>/packages/remix-express/**/*-test.[jt]s?(x)"],
setupFiles: ["<rootDir>/jest/setupNodeGlobals.ts"]
},
{
displayName: "node",
testEnvironment: "node",
Expand All @@ -25,6 +19,25 @@ module.exports = {
],
setupFiles: ["<rootDir>/jest/setupNodeGlobals.ts"]
},
// Node Adapters
{
displayName: "architect",
testEnvironment: "node",
testMatch: ["<rootDir>/packages/remix-architect/**/*-test.[jt]s?(x)"]
},
{
displayName: "express",
testEnvironment: "node",
testMatch: ["<rootDir>/packages/remix-express/**/*-test.[jt]s?(x)"],
setupFiles: ["<rootDir>/jest/setupNodeGlobals.ts"]
},
{
displayName: "vercel",
testEnvironment: "node",
testMatch: ["<rootDir>/packages/remix-vercel/**/*-test.[jt]s?(x)"],
setupFiles: ["<rootDir>/jest/setupNodeGlobals.ts"]
},
// Fixture Apps
{
displayName: "gists-app",
testEnvironment: "node",
Expand Down
Loading