Skip to content

Commit

Permalink
minor tweaks to get benchmarks running
Browse files Browse the repository at this point in the history
- switched to `http-status-codes` to match whats used in gatsby-plugin-fastify
  • Loading branch information
tsdexter committed Mar 17, 2023
1 parent 0883b8f commit abd1fe5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
19 changes: 10 additions & 9 deletions integration-tests/plugin-fastify/benchmark.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const StatusCodes = require("http-status-codes");
const Benchmark = require("benchmark");
const {
getServerConfig,
setConfig,
ConfigKeyEnum,
getConfig,
} = require("gatsby-plugin-fastify/utils/config");
const { serveGatsby } = require("gatsby-plugin-fastify/plugins/gatsby");
} = require("gatsby-plugin-fastify/dist/utils/config");
const { serveGatsby } = require("gatsby-plugin-fastify/dist/plugins/gatsby");
const Fastify = require("fastify");

Benchmark.options.minSamples = 500;
Expand Down Expand Up @@ -37,7 +38,7 @@ setConfig(
const serverConfig = getServerConfig();
setConfig(ConfigKeyEnum.SERVER, serverConfig);

function expectResp(def, path, code = 200) {
function expectResp(def, path, code = StatusCodes.OK) {
return (res) => {
if (res.statusCode !== code) {
console.log(`Expected status code ${code}, got ${res.statusCode} from ${path}`);
Expand Down Expand Up @@ -158,7 +159,7 @@ function expectResp(def, path, code = 200) {
method: "GET",
url: "/nonExistentRoute",
})
.then(expectResp(def, "/nonExistentRoute", 404));
.then(expectResp(def, "/nonExistentRoute", StatusCodes.NOT_FOUND));
},
})
.add("Serve 500", {
Expand All @@ -169,7 +170,7 @@ function expectResp(def, path, code = 200) {
method: "GET",
url: "/ssrBad/",
})
.then(expectResp(def, "/ssrBad/", 500));
.then(expectResp(def, "/ssrBad/", StatusCodes.INTERNAL_SERVER_ERROR));
},
})
.add("Serve Redirect", {
Expand All @@ -180,7 +181,7 @@ function expectResp(def, path, code = 200) {
method: "GET",
url: "/perm-redirect/",
})
.then(expectResp(def, "/perm-redirect/", 301));
.then(expectResp(def, "/perm-redirect/", StatusCodes.PERMANENT_REDIRECT));
},
})
.add("Serve Reverse Proxy", {
Expand All @@ -191,7 +192,7 @@ function expectResp(def, path, code = 200) {
method: "GET",
url: "/example-proxy/",
})
.then(expectResp(def, "/example-proxy/", 200));
.then(expectResp(def, "/example-proxy/", StatusCodes.OK));
},
})
.add("Serve Function", {
Expand All @@ -202,7 +203,7 @@ function expectResp(def, path, code = 200) {
method: "GET",
url: "/api/test",
})
.then(expectResp(def, "/api/test", 200));
.then(expectResp(def, "/api/test", StatusCodes.OK));
},
})
.add("Serve Splat Function", {
Expand All @@ -213,7 +214,7 @@ function expectResp(def, path, code = 200) {
method: "GET",
url: "/api/test1/thisShouldWork",
})
.then(expectResp(def, "/api/test1/thisShouldWork", 200));
.then(expectResp(def, "/api/test1/thisShouldWork", StatusCodes.OK));
},
})
.on("cycle", function (event) {
Expand Down
1 change: 1 addition & 0 deletions integration-tests/plugin-fastify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"gatsby-source-faker": "^5.7.0",
"gatsby-source-filesystem": "^5.7.0",
"gatsby-transformer-sharp": "^5.7.0",
"pino-pretty": "^10.0.0",
"postcss": "^8.4.21",
"react": "^18.2.0",
"react-dom": "^18.2.0"
Expand Down

0 comments on commit abd1fe5

Please sign in to comment.