@nestjs/testing 11.1.15 → 12.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +4 -4
- package/index.js +4 -7
- package/interfaces/index.d.ts +3 -3
- package/interfaces/index.js +3 -6
- package/interfaces/mock-factory.d.ts +1 -1
- package/interfaces/mock-factory.js +1 -2
- package/interfaces/override-by-factory-options.interface.js +1 -2
- package/interfaces/override-by.interface.d.ts +2 -2
- package/interfaces/override-by.interface.js +1 -2
- package/interfaces/override-module.interface.d.ts +2 -2
- package/interfaces/override-module.interface.js +1 -2
- package/package.json +10 -2
- package/services/testing-logger.service.js +2 -6
- package/test.d.ts +2 -2
- package/test.js +5 -9
- package/testing-injector.d.ts +3 -5
- package/testing-injector.js +7 -11
- package/testing-instance-loader.d.ts +3 -4
- package/testing-instance-loader.js +2 -6
- package/testing-module.builder.d.ts +7 -7
- package/testing-module.builder.js +29 -30
- package/testing-module.d.ts +11 -7
- package/testing-module.js +21 -14
- package/tsconfig.build.json +1 -11
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './interfaces';
|
|
2
|
-
export * from './test';
|
|
3
|
-
export * from './testing-module';
|
|
4
|
-
export * from './testing-module.builder';
|
|
1
|
+
export * from './interfaces/index.js';
|
|
2
|
+
export * from './test.js';
|
|
3
|
+
export * from './testing-module.js';
|
|
4
|
+
export * from './testing-module.builder.js';
|
package/index.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*
|
|
3
2
|
* Nest @testing
|
|
4
3
|
* Copyright(c) 2017 - 2025 Kamil Mysliwiec
|
|
5
4
|
* https://nestjs.com
|
|
6
5
|
* MIT Licensed
|
|
7
6
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
tslib_1.__exportStar(require("./testing-module"), exports);
|
|
13
|
-
tslib_1.__exportStar(require("./testing-module.builder"), exports);
|
|
7
|
+
export * from './interfaces/index.js';
|
|
8
|
+
export * from './test.js';
|
|
9
|
+
export * from './testing-module.js';
|
|
10
|
+
export * from './testing-module.builder.js';
|
package/interfaces/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './mock-factory';
|
|
2
|
-
export * from './override-by-factory-options.interface';
|
|
3
|
-
export * from './override-by.interface';
|
|
1
|
+
export * from './mock-factory.js';
|
|
2
|
+
export * from './override-by-factory-options.interface.js';
|
|
3
|
+
export * from './override-by.interface.js';
|
package/interfaces/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
tslib_1.__exportStar(require("./mock-factory"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./override-by-factory-options.interface"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./override-by.interface"), exports);
|
|
1
|
+
export * from './mock-factory.js';
|
|
2
|
+
export * from './override-by-factory-options.interface.js';
|
|
3
|
+
export * from './override-by.interface.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { InjectionToken } from '@nestjs/common';
|
|
1
|
+
import type { InjectionToken } from '@nestjs/common';
|
|
2
2
|
export type MockFactory = (token?: InjectionToken) => any;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TestingModuleBuilder } from '../testing-module.builder';
|
|
2
|
-
import { OverrideByFactoryOptions } from './override-by-factory-options.interface';
|
|
1
|
+
import { TestingModuleBuilder } from '../testing-module.builder.js';
|
|
2
|
+
import { OverrideByFactoryOptions } from './override-by-factory-options.interface.js';
|
|
3
3
|
/**
|
|
4
4
|
* @publicApi
|
|
5
5
|
*/
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { TestingModuleBuilder } from '../testing-module.builder.js';
|
|
2
|
+
import type { ModuleDefinition } from '@nestjs/core/internal';
|
|
3
3
|
/**
|
|
4
4
|
* @publicApi
|
|
5
5
|
*/
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs/testing",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.0-alpha.0",
|
|
4
4
|
"description": "Nest - modern, fast, powerful node.js web framework (@testing)",
|
|
5
5
|
"author": "Kamil Mysliwiec",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./index.js",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./index.js",
|
|
11
|
+
"./*.js": "./*.js",
|
|
12
|
+
"./*": "./*.js",
|
|
13
|
+
"./interfaces": "./interfaces/index.js"
|
|
14
|
+
},
|
|
7
15
|
"homepage": "https://nestjs.com",
|
|
8
16
|
"funding": {
|
|
9
17
|
"type": "opencollective",
|
|
@@ -34,5 +42,5 @@
|
|
|
34
42
|
"optional": true
|
|
35
43
|
}
|
|
36
44
|
},
|
|
37
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "7035ecc828a2a9f752aad188871b1171663a20c2"
|
|
38
46
|
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TestingLogger = void 0;
|
|
4
|
-
const common_1 = require("@nestjs/common");
|
|
1
|
+
import { ConsoleLogger } from '@nestjs/common';
|
|
5
2
|
/**
|
|
6
3
|
* @publicApi
|
|
7
4
|
*/
|
|
8
|
-
class TestingLogger extends
|
|
5
|
+
export class TestingLogger extends ConsoleLogger {
|
|
9
6
|
constructor() {
|
|
10
7
|
super('Testing');
|
|
11
8
|
}
|
|
@@ -17,4 +14,3 @@ class TestingLogger extends common_1.ConsoleLogger {
|
|
|
17
14
|
return super.error(message, ...optionalParams);
|
|
18
15
|
}
|
|
19
16
|
}
|
|
20
|
-
exports.TestingLogger = TestingLogger;
|
package/test.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { TestingModuleBuilder, TestingModuleOptions } from './testing-module.builder.js';
|
|
2
|
+
import type { ModuleMetadata } from '@nestjs/common';
|
|
3
3
|
export declare class Test {
|
|
4
4
|
private static readonly metadataScanner;
|
|
5
5
|
static createTestingModule(metadata: ModuleMetadata, options?: TestingModuleOptions): TestingModuleBuilder;
|
package/test.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const testing_module_builder_1 = require("./testing-module.builder");
|
|
6
|
-
class Test {
|
|
1
|
+
import { TestingModuleBuilder, } from './testing-module.builder.js';
|
|
2
|
+
import { MetadataScanner } from '@nestjs/core';
|
|
3
|
+
export class Test {
|
|
4
|
+
static metadataScanner = new MetadataScanner();
|
|
7
5
|
static createTestingModule(metadata, options) {
|
|
8
|
-
return new
|
|
6
|
+
return new TestingModuleBuilder(this.metadataScanner, metadata, options);
|
|
9
7
|
}
|
|
10
8
|
}
|
|
11
|
-
exports.Test = Test;
|
|
12
|
-
Test.metadataScanner = new metadata_scanner_1.MetadataScanner();
|
package/testing-injector.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { NestContainer } from '@nestjs/core';
|
|
2
|
-
import {
|
|
3
|
-
import { InstanceWrapper } from '@nestjs/core/
|
|
4
|
-
import { Module } from '@nestjs/core/injector/module';
|
|
5
|
-
import { MockFactory } from './interfaces';
|
|
1
|
+
import type { NestContainer } from '@nestjs/core';
|
|
2
|
+
import { MockFactory } from './interfaces/index.js';
|
|
3
|
+
import { Injector, type InjectorDependencyContext, InstanceWrapper, type Module } from '@nestjs/core/internal';
|
|
6
4
|
/**
|
|
7
5
|
* @publicApi
|
|
8
6
|
*/
|
package/testing-injector.js
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TestingInjector = void 0;
|
|
4
|
-
const constants_1 = require("@nestjs/core/injector/constants");
|
|
5
|
-
const injector_1 = require("@nestjs/core/injector/injector");
|
|
6
|
-
const instance_wrapper_1 = require("@nestjs/core/injector/instance-wrapper");
|
|
1
|
+
import { STATIC_CONTEXT, Injector, InstanceWrapper, } from '@nestjs/core/internal';
|
|
7
2
|
/**
|
|
8
3
|
* @publicApi
|
|
9
4
|
*/
|
|
10
|
-
class TestingInjector extends
|
|
5
|
+
export class TestingInjector extends Injector {
|
|
6
|
+
mocker;
|
|
7
|
+
container;
|
|
11
8
|
setMocker(mocker) {
|
|
12
9
|
this.mocker = mocker;
|
|
13
10
|
}
|
|
14
11
|
setContainer(container) {
|
|
15
12
|
this.container = container;
|
|
16
13
|
}
|
|
17
|
-
async resolveComponentWrapper(moduleRef, name, dependencyContext, wrapper, contextId =
|
|
14
|
+
async resolveComponentWrapper(moduleRef, name, dependencyContext, wrapper, contextId = STATIC_CONTEXT, inquirer, keyOrIndex) {
|
|
18
15
|
try {
|
|
19
16
|
const existingProviderWrapper = await super.resolveComponentWrapper(moduleRef, name, dependencyContext, wrapper, contextId, inquirer, keyOrIndex);
|
|
20
17
|
return existingProviderWrapper;
|
|
@@ -23,7 +20,7 @@ class TestingInjector extends injector_1.Injector {
|
|
|
23
20
|
return this.mockWrapper(err, moduleRef, name, wrapper);
|
|
24
21
|
}
|
|
25
22
|
}
|
|
26
|
-
async resolveComponentHost(moduleRef, instanceWrapper, contextId =
|
|
23
|
+
async resolveComponentHost(moduleRef, instanceWrapper, contextId = STATIC_CONTEXT, inquirer) {
|
|
27
24
|
try {
|
|
28
25
|
const existingProviderWrapper = await super.resolveComponentHost(moduleRef, instanceWrapper, contextId, inquirer);
|
|
29
26
|
return existingProviderWrapper;
|
|
@@ -40,7 +37,7 @@ class TestingInjector extends injector_1.Injector {
|
|
|
40
37
|
if (!mockedInstance) {
|
|
41
38
|
throw err;
|
|
42
39
|
}
|
|
43
|
-
const newWrapper = new
|
|
40
|
+
const newWrapper = new InstanceWrapper({
|
|
44
41
|
name,
|
|
45
42
|
isAlias: false,
|
|
46
43
|
scope: wrapper.scope,
|
|
@@ -61,4 +58,3 @@ class TestingInjector extends injector_1.Injector {
|
|
|
61
58
|
return newWrapper;
|
|
62
59
|
}
|
|
63
60
|
}
|
|
64
|
-
exports.TestingInjector = TestingInjector;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { TestingInjector } from './testing-injector';
|
|
1
|
+
import { MockFactory } from './interfaces/index.js';
|
|
2
|
+
import { TestingInjector } from './testing-injector.js';
|
|
3
|
+
import { InstanceLoader, type Module } from '@nestjs/core/internal';
|
|
5
4
|
export declare class TestingInstanceLoader extends InstanceLoader<TestingInjector> {
|
|
6
5
|
createInstancesOfDependencies(modules?: Map<string, Module>, mocker?: MockFactory): Promise<void>;
|
|
7
6
|
}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.TestingInstanceLoader = void 0;
|
|
4
|
-
const instance_loader_1 = require("@nestjs/core/injector/instance-loader");
|
|
5
|
-
class TestingInstanceLoader extends instance_loader_1.InstanceLoader {
|
|
1
|
+
import { InstanceLoader } from '@nestjs/core/internal';
|
|
2
|
+
export class TestingInstanceLoader extends InstanceLoader {
|
|
6
3
|
async createInstancesOfDependencies(modules = this.container.getModules(), mocker) {
|
|
7
4
|
this.injector.setContainer(this.container);
|
|
8
5
|
mocker && this.injector.setMocker(mocker);
|
|
9
6
|
await super.createInstancesOfDependencies();
|
|
10
7
|
}
|
|
11
8
|
}
|
|
12
|
-
exports.TestingInstanceLoader = TestingInstanceLoader;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { LoggerService, ModuleMetadata } from '@nestjs/common';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import { type LoggerService, type ModuleMetadata } from '@nestjs/common';
|
|
2
|
+
import { MockFactory, OverrideBy } from './interfaces/index.js';
|
|
3
|
+
import { OverrideModule } from './interfaces/override-module.interface.js';
|
|
4
|
+
import { TestingModule } from './testing-module.js';
|
|
5
|
+
import type { NestApplicationContextOptions } from '@nestjs/common/internal';
|
|
6
|
+
import { type MetadataScanner } from '@nestjs/core';
|
|
7
|
+
import { type ModuleDefinition } from '@nestjs/core/internal';
|
|
8
8
|
/**
|
|
9
9
|
* @publicApi
|
|
10
10
|
*/
|
|
@@ -1,27 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const noop_graph_inspector_1 = require("@nestjs/core/inspector/noop-graph-inspector");
|
|
9
|
-
const uuid_factory_1 = require("@nestjs/core/inspector/uuid-factory");
|
|
10
|
-
const scanner_1 = require("@nestjs/core/scanner");
|
|
11
|
-
const testing_logger_service_1 = require("./services/testing-logger.service");
|
|
12
|
-
const testing_injector_1 = require("./testing-injector");
|
|
13
|
-
const testing_instance_loader_1 = require("./testing-instance-loader");
|
|
14
|
-
const testing_module_1 = require("./testing-module");
|
|
1
|
+
import { Logger, Module, } from '@nestjs/common';
|
|
2
|
+
import { TestingLogger } from './services/testing-logger.service.js';
|
|
3
|
+
import { TestingInjector } from './testing-injector.js';
|
|
4
|
+
import { TestingInstanceLoader } from './testing-instance-loader.js';
|
|
5
|
+
import { TestingModule } from './testing-module.js';
|
|
6
|
+
import { ApplicationConfig, NestContainer, GraphInspector, } from '@nestjs/core';
|
|
7
|
+
import { NoopGraphInspector, UuidFactory, UuidFactoryMode, DependenciesScanner, } from '@nestjs/core/internal';
|
|
15
8
|
/**
|
|
16
9
|
* @publicApi
|
|
17
10
|
*/
|
|
18
|
-
class TestingModuleBuilder {
|
|
11
|
+
export class TestingModuleBuilder {
|
|
12
|
+
metadataScanner;
|
|
13
|
+
applicationConfig = new ApplicationConfig();
|
|
14
|
+
container;
|
|
15
|
+
overloadsMap = new Map();
|
|
16
|
+
moduleOverloadsMap = new Map();
|
|
17
|
+
module;
|
|
18
|
+
testingLogger;
|
|
19
|
+
mocker;
|
|
19
20
|
constructor(metadataScanner, metadata, options) {
|
|
20
21
|
this.metadataScanner = metadataScanner;
|
|
21
|
-
this.
|
|
22
|
-
this.overloadsMap = new Map();
|
|
23
|
-
this.moduleOverloadsMap = new Map();
|
|
24
|
-
this.container = new container_1.NestContainer(this.applicationConfig, options);
|
|
22
|
+
this.container = new NestContainer(this.applicationConfig, options);
|
|
25
23
|
this.module = this.createModule(metadata);
|
|
26
24
|
}
|
|
27
25
|
setLogger(testingLogger) {
|
|
@@ -59,14 +57,14 @@ class TestingModuleBuilder {
|
|
|
59
57
|
this.applyLogger();
|
|
60
58
|
let graphInspector;
|
|
61
59
|
if (options?.snapshot) {
|
|
62
|
-
graphInspector = new
|
|
63
|
-
|
|
60
|
+
graphInspector = new GraphInspector(this.container);
|
|
61
|
+
UuidFactory.mode = UuidFactoryMode.Deterministic;
|
|
64
62
|
}
|
|
65
63
|
else {
|
|
66
|
-
graphInspector =
|
|
67
|
-
|
|
64
|
+
graphInspector = NoopGraphInspector;
|
|
65
|
+
UuidFactory.mode = UuidFactoryMode.Random;
|
|
68
66
|
}
|
|
69
|
-
const scanner = new
|
|
67
|
+
const scanner = new DependenciesScanner(this.container, this.metadataScanner, graphInspector, this.applicationConfig);
|
|
70
68
|
await scanner.scan(this.module, {
|
|
71
69
|
overrides: this.getModuleOverloads(),
|
|
72
70
|
});
|
|
@@ -74,7 +72,9 @@ class TestingModuleBuilder {
|
|
|
74
72
|
await this.createInstancesOfDependencies(graphInspector, options);
|
|
75
73
|
scanner.applyApplicationProviders();
|
|
76
74
|
const root = this.getRootModule();
|
|
77
|
-
|
|
75
|
+
const testingModule = new TestingModule(this.container, graphInspector, root, this.applicationConfig);
|
|
76
|
+
await testingModule['preloadLazyPackages']();
|
|
77
|
+
return testingModule;
|
|
78
78
|
}
|
|
79
79
|
override(typeOrToken, isProvider) {
|
|
80
80
|
const addOverload = (options) => {
|
|
@@ -111,20 +111,19 @@ class TestingModuleBuilder {
|
|
|
111
111
|
return modules.next().value;
|
|
112
112
|
}
|
|
113
113
|
async createInstancesOfDependencies(graphInspector, options) {
|
|
114
|
-
const injector = new
|
|
114
|
+
const injector = new TestingInjector({
|
|
115
115
|
preview: options?.preview ?? false,
|
|
116
116
|
});
|
|
117
|
-
const instanceLoader = new
|
|
117
|
+
const instanceLoader = new TestingInstanceLoader(this.container, injector, graphInspector);
|
|
118
118
|
await instanceLoader.createInstancesOfDependencies(this.container.getModules(), this.mocker);
|
|
119
119
|
}
|
|
120
120
|
createModule(metadata) {
|
|
121
121
|
class RootTestModule {
|
|
122
122
|
}
|
|
123
|
-
|
|
123
|
+
Module(metadata)(RootTestModule);
|
|
124
124
|
return RootTestModule;
|
|
125
125
|
}
|
|
126
126
|
applyLogger() {
|
|
127
|
-
|
|
127
|
+
Logger.overrideLogger(this.testingLogger || new TestingLogger());
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
|
-
exports.TestingModuleBuilder = TestingModuleBuilder;
|
package/testing-module.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { HttpServer, INestApplication, INestMicroservice, NestApplicationOptions, Type } from '@nestjs/common';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { ApplicationConfig } from '@nestjs/core
|
|
5
|
-
import {
|
|
6
|
-
import { Module } from '@nestjs/core/injector/module';
|
|
7
|
-
import { GraphInspector } from '@nestjs/core/inspector/graph-inspector';
|
|
1
|
+
import { type HttpServer, type INestApplication, type INestMicroservice, type NestApplicationOptions, type Type } from '@nestjs/common';
|
|
2
|
+
import { type AbstractHttpAdapter, NestApplicationContext } from '@nestjs/core';
|
|
3
|
+
import { type NestMicroserviceOptions } from '@nestjs/common/internal';
|
|
4
|
+
import type { ApplicationConfig, NestContainer, GraphInspector } from '@nestjs/core';
|
|
5
|
+
import type { Module } from '@nestjs/core/internal';
|
|
8
6
|
/**
|
|
9
7
|
* @publicApi
|
|
10
8
|
*/
|
|
@@ -12,6 +10,12 @@ export declare class TestingModule extends NestApplicationContext {
|
|
|
12
10
|
private readonly applicationConfig;
|
|
13
11
|
protected readonly graphInspector: GraphInspector;
|
|
14
12
|
constructor(container: NestContainer, graphInspector: GraphInspector, contextModule: Module, applicationConfig: ApplicationConfig, scope?: Type<any>[]);
|
|
13
|
+
/**
|
|
14
|
+
* Pre-load optional packages so that createNestApplication,
|
|
15
|
+
* createNestMicroservice and createHttpAdapter can stay synchronous.
|
|
16
|
+
* Called from TestingModuleBuilder.compile().
|
|
17
|
+
*/
|
|
18
|
+
private preloadLazyPackages;
|
|
15
19
|
private isHttpServer;
|
|
16
20
|
createNestApplication<T extends INestApplication = INestApplication>(httpAdapter: HttpServer | AbstractHttpAdapter, options?: NestApplicationOptions): T;
|
|
17
21
|
createNestApplication<T extends INestApplication = INestApplication>(options?: NestApplicationOptions): T;
|
package/testing-module.js
CHANGED
|
@@ -1,20 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const common_1 = require("@nestjs/common");
|
|
5
|
-
const load_package_util_1 = require("@nestjs/common/utils/load-package.util");
|
|
6
|
-
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
7
|
-
const core_1 = require("@nestjs/core");
|
|
1
|
+
import { Logger, } from '@nestjs/common';
|
|
2
|
+
import { NestApplication, NestApplicationContext, } from '@nestjs/core';
|
|
3
|
+
import { loadPackage, loadPackageCached, isUndefined, } from '@nestjs/common/internal';
|
|
8
4
|
/**
|
|
9
5
|
* @publicApi
|
|
10
6
|
*/
|
|
11
|
-
class TestingModule extends
|
|
7
|
+
export class TestingModule extends NestApplicationContext {
|
|
8
|
+
applicationConfig;
|
|
9
|
+
graphInspector;
|
|
12
10
|
constructor(container, graphInspector, contextModule, applicationConfig, scope = []) {
|
|
13
11
|
const options = {};
|
|
14
12
|
super(container, options, contextModule, scope);
|
|
15
13
|
this.applicationConfig = applicationConfig;
|
|
16
14
|
this.graphInspector = graphInspector;
|
|
17
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Pre-load optional packages so that createNestApplication,
|
|
18
|
+
* createNestMicroservice and createHttpAdapter can stay synchronous.
|
|
19
|
+
* Called from TestingModuleBuilder.compile().
|
|
20
|
+
*/
|
|
21
|
+
async preloadLazyPackages() {
|
|
22
|
+
// Best-effort: silently swallow if packages are not installed
|
|
23
|
+
await loadPackage('@nestjs/platform-express', 'TestingModule', () => import('@nestjs/platform-express')).catch(() => { });
|
|
24
|
+
await loadPackage('@nestjs/microservices', 'TestingModule', () => import('@nestjs/microservices')).catch(() => { });
|
|
25
|
+
}
|
|
18
26
|
isHttpServer(serverOrOptions) {
|
|
19
27
|
return !!(serverOrOptions && serverOrOptions.patch);
|
|
20
28
|
}
|
|
@@ -24,23 +32,23 @@ class TestingModule extends core_1.NestApplicationContext {
|
|
|
24
32
|
: [this.createHttpAdapter(), serverOrOptions];
|
|
25
33
|
this.applyLogger(appOptions);
|
|
26
34
|
this.container.setHttpAdapter(httpAdapter);
|
|
27
|
-
const instance = new
|
|
35
|
+
const instance = new NestApplication(this.container, httpAdapter, this.applicationConfig, this.graphInspector, appOptions);
|
|
28
36
|
return this.createAdapterProxy(instance, httpAdapter);
|
|
29
37
|
}
|
|
30
38
|
createNestMicroservice(options) {
|
|
31
|
-
const { NestMicroservice } = (
|
|
39
|
+
const { NestMicroservice } = loadPackageCached('@nestjs/microservices');
|
|
32
40
|
this.applyLogger(options);
|
|
33
41
|
return new NestMicroservice(this.container, options, this.graphInspector, this.applicationConfig);
|
|
34
42
|
}
|
|
35
43
|
createHttpAdapter(httpServer) {
|
|
36
|
-
const { ExpressAdapter } = (
|
|
44
|
+
const { ExpressAdapter } = loadPackageCached('@nestjs/platform-express');
|
|
37
45
|
return new ExpressAdapter(httpServer);
|
|
38
46
|
}
|
|
39
47
|
applyLogger(options) {
|
|
40
|
-
if (!options ||
|
|
48
|
+
if (!options || isUndefined(options.logger)) {
|
|
41
49
|
return;
|
|
42
50
|
}
|
|
43
|
-
|
|
51
|
+
Logger.overrideLogger(options.logger);
|
|
44
52
|
}
|
|
45
53
|
createAdapterProxy(app, adapter) {
|
|
46
54
|
return new Proxy(app, {
|
|
@@ -53,4 +61,3 @@ class TestingModule extends core_1.NestApplicationContext {
|
|
|
53
61
|
});
|
|
54
62
|
}
|
|
55
63
|
}
|
|
56
|
-
exports.TestingModule = TestingModule;
|
package/tsconfig.build.json
CHANGED
|
@@ -2,17 +2,7 @@
|
|
|
2
2
|
"extends": "../tsconfig.build.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
4
|
"outDir": ".",
|
|
5
|
-
"rootDir": "."
|
|
6
|
-
"paths": {
|
|
7
|
-
"@nestjs/common": ["../common"],
|
|
8
|
-
"@nestjs/common/*": ["../common/*"],
|
|
9
|
-
"@nestjs/core": ["../core"],
|
|
10
|
-
"@nestjs/core/*": ["../core/*"],
|
|
11
|
-
"@nestjs/microservices": ["../microservices"],
|
|
12
|
-
"@nestjs/microservices/*": ["../microservices/*"],
|
|
13
|
-
"@nestjs/platform-express": ["../platform-express"],
|
|
14
|
-
"@nestjs/platform-express/*": ["../platform-express/*"]
|
|
15
|
-
}
|
|
5
|
+
"rootDir": "."
|
|
16
6
|
},
|
|
17
7
|
"exclude": ["node_modules", "dist", "test/**/*", "*.spec.ts"],
|
|
18
8
|
"references": [
|