1- import * as optional from 'optional' ;
2- import { NestContainer } from '@nestjs/core/injector/container' ;
3- import { NestApplication , NestApplicationContext } from '@nestjs/core' ;
4- import { Type } from '@nestjs/common/interfaces/type.interface' ;
5- import { INestApplication , INestMicroservice } from '@nestjs/common' ;
1+ import {
2+ HttpServer ,
3+ INestApplication ,
4+ INestMicroservice ,
5+ Logger ,
6+ } from '@nestjs/common' ;
67import { MicroserviceOptions } from '@nestjs/common/interfaces/microservices/microservice-configuration.interface' ;
7- import { MicroservicesPackageNotFoundException } from '@nestjs/core/errors/exceptions/microservices-package-not-found.exception' ;
8- import { ApplicationConfig } from '@nestjs/core/application-config' ;
9- import { HttpServer } from '@nestjs/common' ;
10- import { ExpressFactory } from '@nestjs/core/adapters/express-factory' ;
11- import { ExpressAdapter } from '@nestjs/core/adapters/express-adapter' ;
12- import { FastifyAdapter } from '@nestjs/core/adapters/fastify-adapter' ;
8+ import { NestMicroserviceOptions } from '@nestjs/common/interfaces/microservices/nest-microservice-options.interface' ;
9+ import { NestApplicationContextOptions } from '@nestjs/common/interfaces/nest-application-context-options.interface' ;
1310import { NestApplicationOptions } from '@nestjs/common/interfaces/nest-application-options.interface' ;
14- import { INestFastifyApplication } from '@nestjs/common/interfaces/nest-fastify-application.interface' ;
1511import { INestExpressApplication } from '@nestjs/common/interfaces/nest-express-application.interface' ;
12+ import { INestFastifyApplication } from '@nestjs/common/interfaces/nest-fastify-application.interface' ;
13+ import { Type } from '@nestjs/common/interfaces/type.interface' ;
14+ import { NestApplication , NestApplicationContext } from '@nestjs/core' ;
15+ import { ExpressAdapter } from '@nestjs/core/adapters/express-adapter' ;
16+ import { ExpressFactory } from '@nestjs/core/adapters/express-factory' ;
17+ import { FastifyAdapter } from '@nestjs/core/adapters/fastify-adapter' ;
18+ import { ApplicationConfig } from '@nestjs/core/application-config' ;
19+ import { MicroservicesPackageNotFoundException } from '@nestjs/core/errors/exceptions/microservices-package-not-found.exception' ;
20+ import { NestContainer } from '@nestjs/core/injector/container' ;
21+ import * as optional from 'optional' ;
1622
1723const { NestMicroservice } =
1824 optional ( '@nestjs/microservices/nest-microservice' ) || ( { } as any ) ;
@@ -44,20 +50,25 @@ export class TestingModule extends NestApplicationContext {
4450 options ?: NestApplicationOptions ,
4551 ) : INestApplication & ( INestExpressApplication | INestFastifyApplication ) {
4652 httpServer = this . applyExpressAdapter ( httpServer ) ;
53+
54+ this . applyLogger ( options ) ;
4755 this . container . setApplicationRef ( httpServer ) ;
56+
4857 return new NestApplication (
4958 this . container ,
5059 httpServer ,
5160 this . applicationConfig ,
61+ options ,
5262 ) ;
5363 }
5464
5565 public createNestMicroservice (
56- options : MicroserviceOptions ,
66+ options : NestMicroserviceOptions & MicroserviceOptions ,
5767 ) : INestMicroservice {
5868 if ( ! NestMicroservice ) {
5969 throw new MicroservicesPackageNotFoundException ( ) ;
6070 }
71+ this . applyLogger ( options ) ;
6172 return new NestMicroservice (
6273 this . container ,
6374 options ,
@@ -72,4 +83,11 @@ export class TestingModule extends NestApplicationContext {
7283 }
7384 return new ExpressAdapter ( httpAdapter ) ;
7485 }
86+
87+ private applyLogger ( options : NestApplicationContextOptions | undefined ) {
88+ if ( ! options || ! options . logger ) {
89+ return undefined ;
90+ }
91+ Logger . overrideLogger ( options . logger ) ;
92+ }
7593}
0 commit comments