Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nestjs e2e testing no logger output

I am using default built-in logger in NestJS form simple logging during development. But when I run e2e tests there is no logger output on console. A really need this, to see what is happening when test fails. Snippet from package.json:

"test:e2e": "jest --config ./test/jest-e2e.json"

And jest-e2e.json:

{
  "moduleFileExtensions": ["js", "json", "ts"],
  "rootDir": ".",
  "testEnvironment": "node",
  "testRegex": ".e2e-spec.ts$",
  "transform": {
    "^.+\\.(t|j)s$": "ts-jest"
  },
  "verbose": true
}
like image 627
momi Avatar asked Jun 07 '26 00:06

momi


1 Answers

It is possible to overwrite the logger on the chain after createTestingModule

const module_: TestingModule = await Test.createTestingModule({
    ...
})
    .setLogger(new Logger())
    .compile();

which is luckily a bit shorter than the method with app.useLogger.

This feature was added in https://github.com/nestjs/nest/pull/6071

As far as I can tell you'll have to do this for every single test setup.

I personally think this is ridiculous. Of course I need my logs when fixing my tests, including debug logs, and I want them without having to add some extra code

like image 145
sezanzeb Avatar answered Jun 08 '26 20:06

sezanzeb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!