1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const common_1 = require("@nestjs/common");
|
4 | const load_package_util_1 = require("@nestjs/common/utils/load-package.util");
|
5 | const core_1 = require("@nestjs/core");
|
6 | class TestingModule extends core_1.NestApplicationContext {
|
7 | constructor(container, scope, contextModule, applicationConfig) {
|
8 | super(container, scope, contextModule);
|
9 | this.applicationConfig = applicationConfig;
|
10 | }
|
11 | createNestApplication(httpAdapter, options) {
|
12 | httpAdapter = httpAdapter || this.createHttpAdapter();
|
13 | this.applyLogger(options);
|
14 | this.container.setHttpAdapter(httpAdapter);
|
15 | const instance = new core_1.NestApplication(this.container, httpAdapter, this.applicationConfig, options);
|
16 | return this.createAdapterProxy(instance, httpAdapter);
|
17 | }
|
18 | createNestMicroservice(options) {
|
19 | const { NestMicroservice } = load_package_util_1.loadPackage('@nestjs/microservices', 'TestingModule', () => require('@nestjs/microservices'));
|
20 | this.applyLogger(options);
|
21 | return new NestMicroservice(this.container, options, this.applicationConfig);
|
22 | }
|
23 | createHttpAdapter(httpServer) {
|
24 | const { ExpressAdapter } = load_package_util_1.loadPackage('@nestjs/platform-express', 'NestFactory', () => require('@nestjs/platform-express'));
|
25 | return new ExpressAdapter(httpServer);
|
26 | }
|
27 | applyLogger(options) {
|
28 | if (!options || !options.logger) {
|
29 | return;
|
30 | }
|
31 | common_1.Logger.overrideLogger(options.logger);
|
32 | }
|
33 | createAdapterProxy(app, adapter) {
|
34 | return new Proxy(app, {
|
35 | get: (receiver, prop) => {
|
36 | if (!(prop in receiver) && prop in adapter) {
|
37 | return adapter[prop];
|
38 | }
|
39 | return receiver[prop];
|
40 | },
|
41 | });
|
42 | }
|
43 | }
|
44 | exports.TestingModule = TestingModule;
|