forked from nestjs/nest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting-module.ts
More file actions
26 lines (22 loc) · 1.26 KB
/
Copy pathtesting-module.ts
File metadata and controls
26 lines (22 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import * as optional from 'optional';
import { NestContainer } from '@nestjs/core/injector/container';
import { NestModuleMetatype } from '@nestjs/common/interfaces/modules/module-metatype.interface';
import { NestApplication, NestApplicationContext } from '@nestjs/core';
import { INestApplication, INestMicroservice } from '@nestjs/common';
import { MicroserviceConfiguration } from '@nestjs/common/interfaces/microservices/microservice-configuration.interface';
import { MicroservicesPackageNotFoundException } from '@nestjs/core/errors/exceptions/microservices-package-not-found.exception';
const { NestMicroservice } = optional('@nestjs/microservices/nest-microservice') || {} as any;
export class TestingModule extends NestApplicationContext {
constructor(container: NestContainer, scope: NestModuleMetatype[], contextModule) {
super(container, scope, contextModule);
}
public createNestApplication(express?): INestApplication {
return new NestApplication(this.container, express);
}
public createNestMicroservice(config: MicroserviceConfiguration): INestMicroservice {
if (!NestMicroservice) {
throw new MicroservicesPackageNotFoundException();
}
return new NestMicroservice(this.container, config);
}
}