I am using Tap with Fastify inject to test my Server implementation. If I run my test cases using yarn run test, it executes all the test and evaluates correctly. However, it never shuts down to show the summary. Instead, I need to manually enter the keyboard interrupt in the terminal to stop the tests and get the result summary.
My observation is that the const responseData = DataUrl() function inside the route, that processes the request before sending the output, is causing the problem. This function when removed solves my issue. Although, its very rudimentary for this demo, I have a lot of logic inside DataUrl() function
How can I fix this?
Here is my output
RUNS src/__tests__/dataurl.test.ts 1 failed of 1 20.431s
Asserts: 1 pass 0 fail 1 of 1 complete
Suites: 1 pass 0 fail 1 of 2 complete
Package.json
"scripts": {
"test": "tap --node-arg=--require=ts-node/register"
},
Route implementation
fastifyServer.post("/dataurl", async (request, response) => {
const responseData = DataUrl();
response
.code(200)
.header("Content-Type", "application/json; charset=utf-8")
.send(responseData);
});
DataUrl function (in another file)
export const DataUrl = (): string => {
return "hello";
};
Test implementation
test("Check data url", async (t) => {
const fastify = app();
t.after(async () => await fastify.close());
const res = await fastify.inject({
url: "/dataurl",
method: "POST",
});
console.log(res);
t.equal(res.statusCode, 204);
});