Skip to content

Commit d5a1056

Browse files
committed
Initial commit
0 parents  commit d5a1056

15 files changed

+9317
-0
lines changed

.eslintrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier", "plugin:prettier/recommended"],
3+
"parser": "@typescript-eslint/parser",
4+
"plugins": ["@typescript-eslint"],
5+
"rules": {}
6+
}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
.vscode
3+
.DS_Store
4+
dist

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v20.11.0

.prettierrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"printWidth": 120
3+
}

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright (c) 2024 Sebastian Garrido
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Fastify Standard Request/Reply

__tests__/server.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import type { FastifyReply, FastifyRequest } from "fastify";
2+
import { createRequest } from "node-mocks-http";
3+
4+
import { createStandardRequest } from "../src";
5+
6+
describe("createStandardRequest", () => {
7+
it("creates a request with the correct headers", async () => {
8+
const fastifyRequest = createRequest({
9+
url: "/foo/bar",
10+
method: "GET",
11+
protocol: "http",
12+
hostname: "localhost:3000",
13+
headers: {
14+
"Cache-Control": "max-age=300, s-maxage=3600",
15+
Host: "localhost:3000",
16+
},
17+
}) as unknown as FastifyRequest;
18+
19+
const fastifyReply = { raw: { on: jest.fn() } } as unknown as FastifyReply;
20+
21+
const request = createStandardRequest(fastifyRequest, fastifyReply);
22+
23+
expect(request.headers.get("cache-control")).toBe("max-age=300, s-maxage=3600");
24+
expect(request.headers.get("host")).toBe("localhost:3000");
25+
});
26+
});

jest.config.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export default {
2+
preset: "ts-jest",
3+
testEnvironment: "node",
4+
testMatch: ["<rootDir>/**/__tests__/**/*.spec.ts"],
5+
testPathIgnorePatterns: ["/node_modules/"],
6+
transform: {
7+
// '^.+\\.[tj]sx?$' to process js/ts with `ts-jest`
8+
// '^.+\\.m?[tj]sx?$' to process js/ts/mjs/mts with `ts-jest`
9+
"^.+\\.tsx?$": [
10+
"ts-jest",
11+
{
12+
useESM: true,
13+
},
14+
],
15+
},
16+
};

0 commit comments

Comments
 (0)