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
45 lines (41 loc) · 1.49 KB
/
Copy pathtesting-module.ts
File metadata and controls
45 lines (41 loc) · 1.49 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
35
36
37
38
39
40
41
42
43
44
45
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';
import { ApplicationConfig } from '@nestjs/core/application-config';
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(
expressInstance: any = express(),
): INestApplication {
return new NestApplication(
this.container,
expressInstance,
new ApplicationConfig(),
);
}
public createNestMicroservice(
config: MicroserviceConfiguration,
): INestMicroservice {
if (!NestMicroservice) {
throw new MicroservicesPackageNotFoundException();
}
return new NestMicroservice(
this.container,
config,
new ApplicationConfig(),
);
}
}