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
34 lines (30 loc) · 1.3 KB
/
Copy pathtesting-module.ts
File metadata and controls
34 lines (30 loc) · 1.3 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
27
28
29
30
31
32
33
34
import * as express from 'express';
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 = express()): INestApplication {
return new NestApplication(this.container, express);
}
public createNestMicroservice(
config: MicroserviceConfiguration,
): INestMicroservice {
if (!NestMicroservice) {
throw new MicroservicesPackageNotFoundException();
}
return new NestMicroservice(this.container, config);
}
}