Skip to content

Commit ef580ac

Browse files
committed
test: update tests to test specific return values
Signed-off-by: Logan McAnsh <logan@mcan.sh>
1 parent 4e63b37 commit ef580ac

File tree

4 files changed

+68
-243
lines changed

4 files changed

+68
-243
lines changed

packages/remix-architect/__tests__/server-test.ts

Lines changed: 19 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ import path from "path";
33
import lambdaTester from "lambda-tester";
44
import type { APIGatewayProxyEventV2 } from "aws-lambda";
55
import {
6-
// This has been added as a global in node 15+, but we expose it here while we
7-
// support Node 14
8-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
9-
AbortController,
106
createRequestHandler as createRemixRequestHandler,
117
Response as NodeResponse,
128
} from "@remix-run/node";
@@ -210,66 +206,29 @@ describe("architect createRemixHeaders", () => {
210206

211207
it("handles simple headers", () => {
212208
let headers = createRemixHeaders({ "x-foo": "bar" });
213-
expect(headers.raw()).toMatchInlineSnapshot(`
214-
Object {
215-
"x-foo": Array [
216-
"bar",
217-
],
218-
}
219-
`);
209+
expect(headers.get("x-foo")).toBe("bar");
220210
});
221211

222212
it("handles multiple headers", () => {
223213
let headers = createRemixHeaders({ "x-foo": "bar", "x-bar": "baz" });
224-
expect(headers.raw()).toMatchInlineSnapshot(`
225-
Object {
226-
"x-bar": Array [
227-
"baz",
228-
],
229-
"x-foo": Array [
230-
"bar",
231-
],
232-
}
233-
`);
214+
expect(headers.get("x-foo")).toBe("bar");
215+
expect(headers.get("x-bar")).toBe("baz");
234216
});
235217

236218
it("handles headers with multiple values", () => {
237-
let headers = createRemixHeaders({ "x-foo": "bar, baz" });
238-
expect(headers.raw()).toMatchInlineSnapshot(`
239-
Object {
240-
"x-foo": Array [
241-
"bar, baz",
242-
],
243-
}
244-
`);
245-
});
246-
247-
it("handles headers with multiple values and multiple headers", () => {
248219
let headers = createRemixHeaders({ "x-foo": "bar, baz", "x-bar": "baz" });
249-
expect(headers.raw()).toMatchInlineSnapshot(`
250-
Object {
251-
"x-bar": Array [
252-
"baz",
253-
],
254-
"x-foo": Array [
255-
"bar, baz",
256-
],
257-
}
258-
`);
220+
expect(headers.getAll("x-foo")).toEqual(["bar", "baz"]);
221+
expect(headers.get("x-bar")).toBe("baz");
259222
});
260223

261224
it("handles multiple request cookies", () => {
262225
let headers = createRemixHeaders({}, [
263226
"__session=some_value",
264227
"__other=some_other_value",
265228
]);
266-
expect(headers.raw()).toMatchInlineSnapshot(`
267-
Object {
268-
"cookie": Array [
269-
"__session=some_value; __other=some_other_value",
270-
],
271-
}
272-
`);
229+
expect(headers.getAll("cookie")).toEqual([
230+
"__session=some_value; __other=some_other_value",
231+
]);
273232
});
274233
});
275234
});
@@ -308,31 +267,17 @@ describe("architect createRemixRequest", () => {
308267
}
309268
`);
310269

311-
expect(remixRequest.headers.raw()).toMatchInlineSnapshot(`
312-
Object {
313-
"accept": Array [
314-
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
315-
],
316-
"accept-encoding": Array [
317-
"gzip, deflate",
318-
],
319-
"accept-language": Array [
320-
"en-US,en;q=0.9",
321-
],
322-
"cookie": Array [
323-
"__session=value",
324-
],
325-
"host": Array [
326-
"localhost:3333",
327-
],
328-
"upgrade-insecure-requests": Array [
329-
"1",
330-
],
331-
"user-agent": Array [
332-
"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",
333-
],
334-
}
335-
`);
270+
expect(remixRequest.headers.get("accept")).toBe(
271+
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
272+
);
273+
expect(remixRequest.headers.get("accept-encoding")).toBe("gzip, deflate");
274+
expect(remixRequest.headers.get("accept-language")).toBe("en-US,en;q=0.9");
275+
expect(remixRequest.headers.get("cookie")).toBe("__session=value");
276+
expect(remixRequest.headers.get("host")).toBe("localhost:3333");
277+
expect(remixRequest.headers.get("upgrade-insecure-requests")).toBe("1");
278+
expect(remixRequest.headers.get("user-agent")).toBe(
279+
"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"
280+
);
336281
});
337282
});
338283

packages/remix-express/__tests__/server-test.ts

Lines changed: 18 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -163,43 +163,23 @@ describe("express createRemixHeaders", () => {
163163

164164
it("handles simple headers", () => {
165165
let headers = createRemixHeaders({ "x-foo": "bar" });
166-
expect(headers.raw()).toMatchInlineSnapshot(`
167-
Object {
168-
"x-foo": Array [
169-
"bar",
170-
],
171-
}
172-
`);
166+
expect(headers.get("x-foo")).toBe("bar");
173167
});
174168

175169
it("handles multiple headers", () => {
176170
let headers = createRemixHeaders({ "x-foo": "bar", "x-bar": "baz" });
177-
expect(headers).toMatchInlineSnapshot(`Headers {}`);
171+
expect(headers.get("x-foo")).toBe("bar");
172+
expect(headers.get("x-bar")).toBe("baz");
178173
});
179174

180175
it("handles headers with multiple values", () => {
181-
let headers = createRemixHeaders({ "x-foo": "bar, baz" });
182-
expect(headers.raw()).toMatchInlineSnapshot(`
183-
Object {
184-
"x-foo": Array [
185-
"bar, baz",
186-
],
187-
}
188-
`);
189-
});
190-
191-
it("handles headers with multiple values and multiple headers", () => {
192-
let headers = createRemixHeaders({ "x-foo": "bar, baz", "x-bar": "baz" });
193-
expect(headers.raw()).toMatchInlineSnapshot(`
194-
Object {
195-
"x-bar": Array [
196-
"baz",
197-
],
198-
"x-foo": Array [
199-
"bar, baz",
200-
],
201-
}
202-
`);
176+
let headers = createRemixHeaders({
177+
"x-foo": ["bar", "baz"],
178+
"x-bar": ["baz"],
179+
});
180+
expect(headers.getAll("x-foo")).toEqual(["bar", "baz"]);
181+
expect(headers.getAll("x-foo")).toEqual(["bar, baz"]);
182+
expect(headers.get("x-bar")).toBe("baz");
203183
});
204184

205185
it("handles multiple set-cookie headers", () => {
@@ -209,14 +189,10 @@ describe("express createRemixHeaders", () => {
209189
"__other=some_other_value; Path=/; Secure; HttpOnly; Expires=Wed, 21 Oct 2015 07:28:00 GMT; SameSite=Lax",
210190
],
211191
});
212-
expect(headers.raw()).toMatchInlineSnapshot(`
213-
Object {
214-
"set-cookie": Array [
215-
"__session=some_value; Path=/; Secure; HttpOnly; MaxAge=7200; SameSite=Lax",
216-
"__other=some_other_value; Path=/; Secure; HttpOnly; Expires=Wed, 21 Oct 2015 07:28:00 GMT; SameSite=Lax",
217-
],
218-
}
219-
`);
192+
expect(headers.getAll("set-cookie")).toEqual([
193+
"__session=some_value; Path=/; Secure; HttpOnly; MaxAge=7200; SameSite=Lax",
194+
"__other=some_other_value; Path=/; Secure; HttpOnly; Expires=Wed, 21 Oct 2015 07:28:00 GMT; SameSite=Lax",
195+
]);
220196
});
221197
});
222198
});
@@ -265,15 +241,9 @@ describe("express createRemixRequest", () => {
265241
}
266242
`);
267243

268-
expect(remixRequest.headers.raw()).toMatchInlineSnapshot(`
269-
Object {
270-
"cache-control": Array [
271-
"max-age=300, s-maxage=3600",
272-
],
273-
"host": Array [
274-
"localhost:3000",
275-
],
276-
}
277-
`);
244+
expect(remixRequest.headers.get("cache-control")).toBe(
245+
"max-age=300, s-maxage=3600"
246+
);
247+
expect(remixRequest.headers.get("host")).toBe("localhost:3000");
278248
});
279249
});

packages/remix-netlify/__tests__/server-test.ts

Lines changed: 13 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -227,57 +227,22 @@ describe("netlify createRemixHeaders", () => {
227227

228228
it("handles simple headers", () => {
229229
let headers = createRemixHeaders({ "x-foo": ["bar"] });
230-
expect(headers.raw()).toMatchInlineSnapshot(`
231-
Object {
232-
"x-foo": Array [
233-
"bar",
234-
],
235-
}
236-
`);
230+
expect(headers.get("x-foo")).toBe("bar");
237231
});
238232

239233
it("handles multiple headers", () => {
240234
let headers = createRemixHeaders({ "x-foo": ["bar"], "x-bar": ["baz"] });
241-
expect(headers.raw()).toMatchInlineSnapshot(`
242-
Object {
243-
"x-bar": Array [
244-
"baz",
245-
],
246-
"x-foo": Array [
247-
"bar",
248-
],
249-
}
250-
`);
235+
expect(headers.get("x-foo")).toBe("bar");
236+
expect(headers.get("x-bar")).toBe("baz");
251237
});
252238

253239
it("handles headers with multiple values", () => {
254-
let headers = createRemixHeaders({ "x-foo": ["bar", "baz"] });
255-
expect(headers.raw()).toMatchInlineSnapshot(`
256-
Object {
257-
"x-foo": Array [
258-
"bar",
259-
"baz",
260-
],
261-
}
262-
`);
263-
});
264-
265-
it("handles headers with multiple values and multiple headers", () => {
266240
let headers = createRemixHeaders({
267241
"x-foo": ["bar", "baz"],
268242
"x-bar": ["baz"],
269243
});
270-
expect(headers.raw()).toMatchInlineSnapshot(`
271-
Object {
272-
"x-bar": Array [
273-
"baz",
274-
],
275-
"x-foo": Array [
276-
"bar",
277-
"baz",
278-
],
279-
}
280-
`);
244+
expect(headers.getAll("x-foo")).toEqual(["bar", "baz"]);
245+
expect(headers.get("x-bar")).toBe("baz");
281246
});
282247

283248
it("handles multiple set-cookie headers", () => {
@@ -287,27 +252,20 @@ describe("netlify createRemixHeaders", () => {
287252
"__other=some_other_value; Path=/; Secure; HttpOnly; Expires=Wed, 21 Oct 2015 07:28:00 GMT; SameSite=Lax",
288253
],
289254
});
290-
expect(headers.raw()).toMatchInlineSnapshot(`
291-
Object {
292-
"set-cookie": Array [
293-
"__session=some_value; Path=/; Secure; HttpOnly; MaxAge=7200; SameSite=Lax",
294-
"__other=some_other_value; Path=/; Secure; HttpOnly; Expires=Wed, 21 Oct 2015 07:28:00 GMT; SameSite=Lax",
295-
],
296-
}
297-
`);
255+
expect(headers.getAll("set-cookie")).toEqual([
256+
"__session=some_value; Path=/; Secure; HttpOnly; MaxAge=7200; SameSite=Lax",
257+
"__other=some_other_value; Path=/; Secure; HttpOnly; Expires=Wed, 21 Oct 2015 07:28:00 GMT; SameSite=Lax",
258+
]);
298259
});
299260
});
300261
});
301262

302263
describe("netlify createRemixRequest", () => {
303264
it("creates a request with the correct headers", () => {
304265
let remixRequest = createRemixRequest(
305-
createMockEvent({
306-
multiValueHeaders: {
307-
Cookie: ["__session=value", "__other=value"],
308-
},
309-
})
266+
createMockEvent({ multiValueHeaders: { Cookie: ["__session=value"] } })
310267
);
268+
311269
expect(remixRequest).toMatchInlineSnapshot(`
312270
NodeRequest {
313271
"agent": undefined,
@@ -335,14 +293,8 @@ describe("netlify createRemixRequest", () => {
335293
},
336294
}
337295
`);
338-
expect(remixRequest.headers.raw()).toMatchInlineSnapshot(`
339-
Object {
340-
"cookie": Array [
341-
"__session=value",
342-
"__other=value",
343-
],
344-
}
345-
`);
296+
297+
expect(remixRequest.headers.get("cookie")).toBe("__session=value");
346298
});
347299
});
348300

0 commit comments

Comments
 (0)