Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

490
Visualizações
Nest.js Testing Error: Using the "extends Logger" instruction is not allowed in Nest v8. Please, use "extends ConsoleLogger" instead

Here's the problem I have:

I am using my custom Logger in Nest.js:

export class ReportLogger extends ConsoleLogger {
  verbose(message: string) {
    console.log('【Verbose】Reporting', message);
    super.verbose.apply(this, arguments);
  }

  log(message: string) {
    console.log('【Log】Reporting', message);
    super.log.apply(this, arguments);
  }
}

And the log.interceptor.ts file:

export class LogInterceptor implements NestInterceptor {
  constructor(private reportLogger: ReportLogger) {
    this.reportLogger.setContext('LogInterceptor');
  }

  intercept(context: ExecutionContext, next: CallHandler) {
    const http = context.switchToHttp();
    const request = http.getRequest();

    const now = Date.now();
    return next
      .handle()
      .pipe(
        tap(() =>
          this.reportLogger.log(
            `${request.method} ${request.url} ${Date.now() - now}ms`,
          ),
        ),
      );
  }
}

And here's the main.ts file:

async function bootstrap() {
  const reportLogger = new ReportLogger();

  const app = await NestFactory.create<NestExpressApplication>(AppModule, {
    cors: {
      origin: ['http://localhost', 'http://localhost:3000'],
      credentials: true,
    },
    bufferLogs: true,
    logger: reportLogger,
  });

  app.useGlobalInterceptors(
    new LogInterceptor(reportLogger),
  );

  setupSwagger(app);

  await app.listen(4200);
}

When I run npm run start:dev to run the Nest App on dev, everything works fine. But when I run npm run test:e2e or npm run test on testing, it shows this error:

  Using the "extends Logger" instruction is not allowed in Nest v8. Please, use "extends ConsoleLogger" instead.

      10 |     const moduleFixture: TestingModule = await Test.createTestingModule({
      11 |       imports: [AppModule],
    > 12 |     }).compile();
         |        ^
      13 |
      14 |     app = moduleFixture.createNestApplication();
      15 |     await app.init();

I read the Nest.js doc again, and found the Logging breaking change in the docs. But the question is I have already made my ReportLogger extends ConsoleLogger, why this error shows again? And why it only shows in testing?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

even with "@nestjs/testing": "^8.0.7" this issue still occurs

class Logger implements LoggerService { ... }

await Test.createTestingModule({
  imports: [ApiModule],
})
  .setLogger(new Logger())
  .compile();

setting logger instance solves that error on my side

over 4 years ago · Santiago Trujillo Relatório

0

I have faced the same problem after upgrading NestJS to version 8.

Later on, I found that package @nestjs/testing had previous version installed and was not upgraded to the latest version. The reason is, previous version of NestJS testing module is using the old Logger.

In order to fix this issue, you just need to upgrade the NestJS testing module.

Run this command for Latest version:

npm i @nestjs/testing@latest

OR specific version

npm i @nestjs/testing@8.0.6 // <--- Change the NestJS version here

After this, just build and run test cases again.

External Links:

  • NestJS Testing NPM
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda