forked from remix-run/remix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom-entry-server-test.ts
60 lines (53 loc) · 1.71 KB
/
custom-entry-server-test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { expect, test } from "@playwright/test";
import { PlaywrightFixture } from "./helpers/playwright-fixture.js";
import type { Fixture, AppFixture } from "./helpers/create-fixture.js";
import {
createAppFixture,
createFixture,
js,
} from "./helpers/create-fixture.js";
let fixture: Fixture;
let appFixture: AppFixture;
test.beforeAll(async () => {
fixture = await createFixture({
files: {
"app/entry.server.tsx": js`
import * as React from "react";
import { RemixServer } from "@remix-run/react";
import { renderToString } from "react-dom/server";
export default function handleRequest(
request,
responseStatusCode,
responseHeaders,
remixContext
) {
let markup = renderToString(
<RemixServer context={remixContext} url={request.url} />
);
responseHeaders.set("Content-Type", "text/html");
responseHeaders.set("x-custom-header", "custom-value");
return new Response('<!doctype html>' + markup, {
headers: responseHeaders,
status: responseStatusCode,
});
}
`,
"app/routes/_index.tsx": js`
export default function Index() {
return <h1>Hello World</h1>
}
`,
},
});
appFixture = await createAppFixture(fixture);
});
test.afterAll(() => {
appFixture.close();
});
test("allows user specified entry.server", async ({ page }) => {
let app = new PlaywrightFixture(appFixture, page);
let responses = app.collectResponses((url) => url.pathname === "/");
await app.goto("/");
let header = await responses[0].headerValues("x-custom-header");
expect(header).toEqual(["custom-value"]);
});