fastify/fastify-cli

fastify-cli: print log messages during test

已關閉

#546 建立於 2022年9月3日

 (1 則留言) (0 個反應) (0 位負責人)JavaScript (174 個分叉)github user discovery
good first issuesemver-minor

倉庫指標

星標
 (726 顆星)
PR 合併指標
 (平均合併 54分鐘) (30 天內合併 3 個 PR)

描述

You have already researched for similar issues?

Yes, nothing found

What are you trying to achieve, or the steps to reproduce?

I'm trying to see the fastify.log statements that get printed during my test. This only seems possible if fastify is logging to stderr instead of stdout (where it is swallowed by tap). I'm trying to instantiate a custom logger by using the build method of the helper from fastify-cli:

test("default root route", async (t) => {
  const app = await build({
    logger: {
      transport: {
        target: 'pino-pretty',
        options: {
          colorize: true,
          destination: 2,
        },
      },
    });
  const res = await app.inject({
    url: "/processor",
  });
  t.same(JSON.parse(res.payload), { root: true });
});

If I pass the configuration block to Fastify(...) and build the server myself, it will instantiate the logger correctly.

What was the result you received?

The log was still to stdout and tap swallowed it.

What did you expect?

I would expect fastify to log to stderr and show the messages during a npm run test

Context

  • node version: 16.16.17
  • fastify version: >= 5.3.0
  • os: Mac
  • any other relevant information:

I can create a demo repo if that helps?

貢獻者指南