Skip to content

Instantly share code, notes, and snippets.

@seriousme
Created September 19, 2024 17:21
Show Gist options
  • Save seriousme/a1456b1c0432d1029561025c6bdc4095 to your computer and use it in GitHub Desktop.
Save seriousme/a1456b1c0432d1029561025c6bdc4095 to your computer and use it in GitHub Desktop.
Reproduction of 'FST_ERR_LOG_INVALID_LOGGER_CONFIG' issue in fastify@5.0.0
import { strict as assert } from "node:assert/strict";
// just test the basics to aid debugging
import { test } from "node:test";
import Fastify from "fastify";
const opts = {
schema: {
querystring: {
type: "object",
properties: {
hello: { type: "string" },
},
required: ["hello"],
},
},
};
const noStrict = {
ajv: {
customOptions: {
strict: false,
},
},
};
test("basic fastify works", async (t) => {
const fastify = Fastify(noStrict);
async function routes(fastify) {
fastify.get("/", async () => {
return { hello: "world" };
});
}
fastify.register(routes);
const res = await fastify.inject({
method: "GET",
url: "/",
});
assert.equal(res.statusCode, 200);
});
test("fastify validation works", async (t) => {
const fastify = Fastify(noStrict);
async function routes(fastify) {
fastify.get("/", opts, async (request) => {
return { hello: request.query.hello };
});
}
fastify.register(routes);
{
const res = await fastify.inject({
method: "GET",
url: "/?hello=world",
});
assert.equal(res.body, '{"hello":"world"}', "expected value");
assert.equal(res.statusCode, 200, "expected HTTP code");
}
{
const res = await fastify.inject({
method: "GET",
url: "/?ello=world",
});
assert.equal(res.statusCode, 400, "expected HTTP code");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment