Skip to content

Commit

Permalink
feat: support fastify v4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs committed May 26, 2022
1 parent 0acd5de commit f5fe049
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 36 deletions.
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,23 @@
"devDependencies": {
"@commitlint/cli": "^17.0.1",
"@commitlint/config-conventional": "^17.0.0",
"eslint": "^8.9.0",
"eslint": "^8.16.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.4.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jest": "^26.1.1",
"eslint-plugin-jsdoc": "^39.2.9",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^26.2.2",
"eslint-plugin-jsdoc": "^39.3.1",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-security": "^1.4.0",
"eslint-plugin-security": "^1.5.0",
"eslint-plugin-security-node": "^1.1.1",
"fastify": "^3.27.2",
"fastify-3": "npm:fastify@^3.29.0",
"fastify-4": "npm:fastify@^4.0.0-rc.3",
"husky": "^8.0.1",
"jest": "^28.0.3",
"jest": "^28.1.0",
"license-checker": "^25.0.1",
"prettier": "^2.5.1"
"prettier": "^2.6.2"
},
"dependencies": {
"fastify-plugin": "^3.0.0"
"fastify-plugin": "^3.0.1"
}
}
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ async function plugin(server) {
});
}

module.exports = fp(plugin, { fastify: "3.x", name: "fastify-disablecache" });
module.exports = fp(plugin, { fastify: ">=3.x", name: "fastify-disablecache" });
54 changes: 29 additions & 25 deletions src/index.test.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
const Fastify = require("fastify");
const plugin = require(".");

describe("Disablecache Plugin", () => {
describe("Response Headers", () => {
let server;
const fastifyVersion = ["fastify-3", "fastify-4"];

beforeAll(async () => {
server = Fastify();
server.register(plugin);
fastifyVersion.forEach((version) => {
describe(`${version} - Response Headers`, () => {
let server;

server.get("/", (req, res) => {
res.send("ok");
});
beforeAll(async () => {
// eslint-disable-next-line
server = require(version)();
server.register(plugin);

await server.ready();
});
server.get("/", (req, res) => {
res.send("ok");
});

afterAll(async () => {
await server.close();
});
await server.ready();
});

test("Should set relevant cache response headers", async () => {
const response = await server.inject({
method: "GET",
url: "/",
afterAll(async () => {
await server.close();
});

expect(response.payload).toBe("ok");
expect(response.headers).toMatchObject({
"cache-control": "no-store, max-age=0, must-revalidate",
expires: "0",
pragma: "no-cache",
"surrogate-control": "no-store",
test("Should set relevant cache response headers", async () => {
const response = await server.inject({
method: "GET",
url: "/",
});

expect(response.payload).toBe("ok");
expect(response.headers).toMatchObject({
"cache-control": "no-store, max-age=0, must-revalidate",
expires: "0",
pragma: "no-cache",
"surrogate-control": "no-store",
});
expect(response.statusCode).toBe(200);
});
expect(response.statusCode).toBe(200);
});
});
});

0 comments on commit f5fe049

Please sign in to comment.