@nexus-ioc/testing 0.4.2 → 0.7.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/README.md +53 -6
- package/dist/{core → cjs/core}/hash-testing-util.js +1 -1
- package/dist/cjs/core/hash-testing-util.js.map +1 -0
- package/dist/cjs/core/testing-container.js +126 -0
- package/dist/cjs/core/testing-container.js.map +1 -0
- package/dist/cjs/core/testing-creator.js.map +1 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/interfaces/index.js.map +1 -0
- package/dist/cjs/interfaces/module-testing-container.interface.js.map +1 -0
- package/dist/esm/core/hash-testing-util.js +25 -0
- package/dist/esm/core/hash-testing-util.js.map +1 -0
- package/dist/esm/core/testing-container.js +122 -0
- package/dist/esm/core/testing-container.js.map +1 -0
- package/dist/esm/core/testing-creator.js +9 -0
- package/dist/esm/core/testing-creator.js.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/interfaces/index.js +2 -0
- package/dist/esm/interfaces/index.js.map +1 -0
- package/dist/esm/interfaces/module-testing-container.interface.js +2 -0
- package/dist/esm/interfaces/module-testing-container.interface.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/{core → types/core}/hash-testing-util.d.ts +2 -2
- package/dist/types/core/testing-container.d.ts +52 -0
- package/dist/types/interfaces/module-testing-container.interface.d.ts +23 -0
- package/package.json +42 -19
- package/dist/core/hash-testing-util.js.map +0 -1
- package/dist/core/testing-container.d.ts +0 -25
- package/dist/core/testing-container.js +0 -78
- package/dist/core/testing-container.js.map +0 -1
- package/dist/core/testing-creator.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/interfaces/index.js.map +0 -1
- package/dist/interfaces/module-testing-container.interface.d.ts +0 -5
- package/dist/interfaces/module-testing-container.interface.js.map +0 -1
- /package/dist/{core → cjs/core}/testing-creator.js +0 -0
- /package/dist/{index.js → cjs/index.js} +0 -0
- /package/dist/{interfaces → cjs/interfaces}/index.js +0 -0
- /package/dist/{interfaces → cjs/interfaces}/module-testing-container.interface.js +0 -0
- /package/dist/{core → types/core}/testing-creator.d.ts +0 -0
- /package/dist/{index.d.ts → types/index.d.ts} +0 -0
- /package/dist/{interfaces → types/interfaces}/index.d.ts +0 -0
package/README.md
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
](https://www.npmjs.com/package/@nexus-ioc/testing)
|
|
4
|
+
[](https://www.npmjs.com/package/@nexus-ioc/testing)
|
|
5
|
+
[](https://www.npmjs.com/package/@nexus-ioc/testing)
|
|
6
|
+
[](https://github.com/Isqanderm/ioc/blob/main/LICENSE)
|
|
7
|
+
[](https://bundlephobia.com/package/@nexus-ioc/testing)
|
|
8
|
+
[](https://github.com/Isqanderm/ioc/actions/workflows/ci.yml)
|
|
9
|
+
[](https://codecov.io/gh/Isqanderm/ioc)
|
|
10
|
+
[](https://libraries.io/npm/@nexus-ioc%2Ftesting)
|
|
11
|
+
[](https://github.com/Isqanderm/ioc)
|
|
12
|
+
[](https://github.com/Isqanderm/ioc/issues)
|
|
13
|
+
[](https://www.typescriptlang.org/)
|
|
14
|
+
[](https://github.com/Isqanderm/ioc/blob/main/CONTRIBUTING.md)
|
|
15
|
+
|
|
16
|
+
> Test library for Nexus IoC
|
|
6
17
|
|
|
7
18
|
## Table of Contents
|
|
8
19
|
|
|
9
20
|
- [Installation](#installation)
|
|
10
21
|
- [Quick Start](#quick-start)
|
|
22
|
+
- [inject() with fakes](#inject-with-fakes)
|
|
11
23
|
- [License](#license)
|
|
12
24
|
- [Author](#author)
|
|
13
25
|
- [Contributing](#contributing)
|
|
@@ -35,12 +47,47 @@ describe('AppModule', () => {
|
|
|
35
47
|
providers: [AppService],
|
|
36
48
|
}).compile();
|
|
37
49
|
|
|
38
|
-
const appService =
|
|
50
|
+
const appService = appModule.get<AppService>(AppService);
|
|
39
51
|
expect(appService).toBeInstanceOf(AppService);
|
|
40
52
|
});
|
|
41
53
|
});
|
|
42
54
|
```
|
|
43
55
|
|
|
56
|
+
### inject() with fakes
|
|
57
|
+
|
|
58
|
+
`inject()` works in providers created by `Test.createModule(...).compile()`. A
|
|
59
|
+
`{ provide: X, useValue: fake }` replacement is what `inject(X)` receives:
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { Injectable, inject } from '@nexus-ioc/core';
|
|
63
|
+
import { Test } from '@nexus-ioc/testing';
|
|
64
|
+
|
|
65
|
+
@Injectable()
|
|
66
|
+
class Mailer {
|
|
67
|
+
send(to: string) {}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@Injectable()
|
|
71
|
+
class Notifier {
|
|
72
|
+
private readonly mailer = inject(Mailer);
|
|
73
|
+
|
|
74
|
+
notify(to: string) {
|
|
75
|
+
this.mailer.send(to);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
it('uses the fake', async () => {
|
|
80
|
+
const fake = { send: vi.fn() };
|
|
81
|
+
|
|
82
|
+
const moduleRef = await Test.createModule({
|
|
83
|
+
providers: [Notifier, { provide: Mailer, useValue: fake }],
|
|
84
|
+
}).compile();
|
|
85
|
+
|
|
86
|
+
moduleRef.get<Notifier>(Notifier).notify('a@b.c');
|
|
87
|
+
expect(fake.send).toHaveBeenCalledWith('a@b.c');
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
44
91
|
## License
|
|
45
92
|
|
|
46
93
|
This project is licensed under the MIT License. See the LICENSE file for details.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash-testing-util.js","sourceRoot":"","sources":["../../../src/core/hash-testing-util.ts"],"names":[],"mappings":";;;AAEA,MAAa,eAAe;IAA5B;QACS,cAAS,GAAG,CAAC,CAAC;IAwBvB,CAAC;IAvBA,KAAK,CAAC,UAAU,CAAC,KAAa;QAC7B,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,OAAO,IAAI,KAAK,CAAC,EAAE,CAAC;aAClB,IAAI,CAAC,IAAI,CAAC;aACV,GAAG,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,CAAC;YAER,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;gBAC3B,KAAK,GAAG,CAAC,CAAC;YACX,CAAC;YAED,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC5B,CAAC,CAAC;aACD,IAAI,CAAC,EAAE,CAAC,CAAC;IACZ,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,MAAc;QAC9B,OAAO,EAAE,CAAC;IACX,CAAC;IAED,eAAe;QACd,OAAO,GAAG,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;IAC9B,CAAC;CACD;AAzBD,0CAyBC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Test = void 0;
|
|
4
|
+
const core_1 = require("@nexus-ioc/core");
|
|
5
|
+
const internal_1 = require("@nexus-ioc/core/internal");
|
|
6
|
+
const shared_1 = require("@nexus-ioc/shared");
|
|
7
|
+
const hash_testing_util_1 = require("./hash-testing-util");
|
|
8
|
+
const testing_creator_1 = require("./testing-creator");
|
|
9
|
+
class Test {
|
|
10
|
+
constructor(metatype) {
|
|
11
|
+
this.metatype = metatype;
|
|
12
|
+
this.scannerPlugins = [];
|
|
13
|
+
this.hashTestingUtil = new hash_testing_util_1.HashTestingUtil();
|
|
14
|
+
this.container = new internal_1.Container(this.hashTestingUtil);
|
|
15
|
+
this.moduleTestingCreator = new testing_creator_1.TestingCreator();
|
|
16
|
+
this._moduleContainer = null;
|
|
17
|
+
this._moduleDecorator = core_1.Module;
|
|
18
|
+
this._module = null;
|
|
19
|
+
this.containerCompiled = false;
|
|
20
|
+
this.lazyModuleLoader = new internal_1.LazyModuleLoader((lazyModule) => this.load(lazyModule), (ref) => this.unload(ref));
|
|
21
|
+
}
|
|
22
|
+
static createModule(metatype) {
|
|
23
|
+
return new Test(metatype);
|
|
24
|
+
}
|
|
25
|
+
async addModule(metatype) {
|
|
26
|
+
return this.container.addModule(metatype);
|
|
27
|
+
}
|
|
28
|
+
async getModule(metatype) {
|
|
29
|
+
return this.container.getModule(metatype);
|
|
30
|
+
}
|
|
31
|
+
async replaceModule(metatypeToReplace, newMetatype) {
|
|
32
|
+
if (this.containerCompiled || this._moduleContainer) {
|
|
33
|
+
throw new Error("replaceModule must be called before compile()");
|
|
34
|
+
}
|
|
35
|
+
return this.container.replaceModule(metatypeToReplace, newMetatype);
|
|
36
|
+
}
|
|
37
|
+
get(token, options = {}) {
|
|
38
|
+
if (!this.containerCompiled) {
|
|
39
|
+
throw new shared_1.ContainerNotCompiledError();
|
|
40
|
+
}
|
|
41
|
+
if (!this.container.hasProvider(token)) {
|
|
42
|
+
if (options.optional) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
throw new core_1.ProviderNotFoundError(token);
|
|
46
|
+
}
|
|
47
|
+
return this.container.get(token);
|
|
48
|
+
}
|
|
49
|
+
async resolve(token, options = {}) {
|
|
50
|
+
if (!this.containerCompiled) {
|
|
51
|
+
throw new shared_1.ContainerNotCompiledError();
|
|
52
|
+
}
|
|
53
|
+
if (!this.container.hasProvider(token)) {
|
|
54
|
+
if (options.optional) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
throw new core_1.ProviderNotFoundError(token);
|
|
58
|
+
}
|
|
59
|
+
return this.container.resolve(token);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Loads a lazy module into the testing container, like
|
|
63
|
+
* `NexusApplication.load()`. Also backs the injectable `LazyModuleLoader`.
|
|
64
|
+
*/
|
|
65
|
+
async load(lazyModule) {
|
|
66
|
+
if (!this.containerCompiled) {
|
|
67
|
+
throw new shared_1.ContainerNotCompiledError();
|
|
68
|
+
}
|
|
69
|
+
const segment = await this.container.load(lazyModule);
|
|
70
|
+
await this.container.instantiateSingletons(segment.providerTokens);
|
|
71
|
+
return new core_1.ModuleRef(this.container, segment);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Unloads a lazy module previously loaded through `load()`, like
|
|
75
|
+
* `NexusApplication.unload()`. Also backs the injectable
|
|
76
|
+
* `LazyModuleLoader`.
|
|
77
|
+
*/
|
|
78
|
+
async unload(ref) {
|
|
79
|
+
if (!this.containerCompiled) {
|
|
80
|
+
throw new shared_1.ContainerNotCompiledError();
|
|
81
|
+
}
|
|
82
|
+
return ref.unload();
|
|
83
|
+
}
|
|
84
|
+
async compile() {
|
|
85
|
+
this._module = this.moduleTestingCreator.create(this.metatype, this._moduleDecorator);
|
|
86
|
+
this._moduleContainer = await this.container.addModule(this._module);
|
|
87
|
+
await this.container.run(this._moduleContainer.metatype, [
|
|
88
|
+
(0, internal_1.createInternalModule)(this.lazyModuleLoader),
|
|
89
|
+
]);
|
|
90
|
+
this.containerCompiled = true;
|
|
91
|
+
for (const scannerPlugin of this.scannerPlugins) {
|
|
92
|
+
await scannerPlugin.scan(this.container.graph);
|
|
93
|
+
}
|
|
94
|
+
await this.container.instantiateSingletons(this.container.graph.nodes.keys());
|
|
95
|
+
return this._moduleContainer;
|
|
96
|
+
}
|
|
97
|
+
get module() {
|
|
98
|
+
if (!this.containerCompiled) {
|
|
99
|
+
throw new shared_1.ContainerNotCompiledError();
|
|
100
|
+
}
|
|
101
|
+
return this._module;
|
|
102
|
+
}
|
|
103
|
+
get moduleContainer() {
|
|
104
|
+
if (!this.containerCompiled) {
|
|
105
|
+
throw new shared_1.ContainerNotCompiledError();
|
|
106
|
+
}
|
|
107
|
+
return this._moduleContainer;
|
|
108
|
+
}
|
|
109
|
+
addScannerPlugin(scanner) {
|
|
110
|
+
const plugins = Array.isArray(scanner) ? scanner : [scanner];
|
|
111
|
+
this.scannerPlugins.push(...plugins);
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
setModuleDecorator(decorator) {
|
|
115
|
+
this._moduleDecorator = decorator;
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
get errors() {
|
|
119
|
+
if (!this.containerCompiled) {
|
|
120
|
+
throw new shared_1.ContainerNotCompiledError();
|
|
121
|
+
}
|
|
122
|
+
return this._moduleContainer?.errors;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.Test = Test;
|
|
126
|
+
//# sourceMappingURL=testing-container.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing-container.js","sourceRoot":"","sources":["../../../src/core/testing-container.ts"],"names":[],"mappings":";;;AAAA,0CAcyB;AACzB,uDAIkC;AAClC,8CAA8D;AAE9D,2DAAsD;AACtD,uDAAmD;AAEnD,MAAa,IAAI;IAiBhB,YAAqC,QAAW;QAAX,aAAQ,GAAR,QAAQ,CAAG;QAd/B,mBAAc,GAA6B,EAAE,CAAC;QAC9C,oBAAe,GAAG,IAAI,mCAAe,EAAE,CAAC;QACxC,cAAS,GAAG,IAAI,oBAAS,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAChD,yBAAoB,GAAG,IAAI,gCAAc,EAAK,CAAC;QACxD,qBAAgB,GAAoC,IAAI,CAAC;QACzD,qBAAgB,GACvB,aAAe,CAAC;QACT,YAAO,GAAgB,IAAI,CAAC;QAC5B,sBAAiB,GAAG,KAAK,CAAC;QACjB,qBAAgB,GAAG,IAAI,2BAAgB,CACvD,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,EACrC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CACzB,CAAC;IAEiD,CAAC;IAE7C,MAAM,CAAC,YAAY,CACzB,QAAW;QAEX,OAAO,IAAI,IAAI,CAAI,QAAQ,CAAC,CAAC;IAC9B,CAAC;IAEM,KAAK,CAAC,SAAS,CACrB,QAA8B;QAE9B,OAAO,IAAI,CAAC,SAAS,CAAC,SAAS,C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src/core/testing-creator.ts"],"names":[],"mappings":";;;AAEA,MAAa,cAAc;IAC1B,MAAM,CACL,QAAW,EACX,eAAgD;QAEhD,MAAM,MAAM,GAAG;SAAQ,CAAC;QAExB,eAAe,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;QAElC,OAAO,MAAM,CAAC;IACf,CAAC;CACD;AAXD,wCAWC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,8DAAgD;AAAvC,yGAAA,IAAI,OAAA;AACb,uDAA6B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interfaces/index.ts"],"names":[],"mappings":";;;AAAA,+EAAqD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-testing-container.interface.js","sourceRoot":"","sources":["../../../src/interfaces/module-testing-container.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export class HashTestingUtil {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.increment = 1;
|
|
4
|
+
}
|
|
5
|
+
async hashString(value) {
|
|
6
|
+
let index = 0;
|
|
7
|
+
return new Array(64)
|
|
8
|
+
.fill(null)
|
|
9
|
+
.map(() => {
|
|
10
|
+
index++;
|
|
11
|
+
if (index >= value.length) {
|
|
12
|
+
index = 0;
|
|
13
|
+
}
|
|
14
|
+
return value.charAt(index);
|
|
15
|
+
})
|
|
16
|
+
.join("");
|
|
17
|
+
}
|
|
18
|
+
async hashObject(_value) {
|
|
19
|
+
return "";
|
|
20
|
+
}
|
|
21
|
+
incrementString() {
|
|
22
|
+
return `${this.increment++}`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=hash-testing-util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash-testing-util.js","sourceRoot":"","sources":["../../../src/core/hash-testing-util.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,eAAe;IAA5B;QACS,cAAS,GAAG,CAAC,CAAC;IAwBvB,CAAC;IAvBA,KAAK,CAAC,UAAU,CAAC,KAAa;QAC7B,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,OAAO,IAAI,KAAK,CAAC,EAAE,CAAC;aAClB,IAAI,CAAC,IAAI,CAAC;aACV,GAAG,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,CAAC;YAER,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;gBAC3B,KAAK,GAAG,CAAC,CAAC;YACX,CAAC;YAED,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC5B,CAAC,CAAC;aACD,IAAI,CAAC,EAAE,CAAC,CAAC;IACZ,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,MAAc;QAC9B,OAAO,EAAE,CAAC;IACX,CAAC;IAED,eAAe;QACd,OAAO,GAAG,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;IAC9B,CAAC;CACD"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { Module as ModuleDecorator, ModuleRef, ProviderNotFoundError, } from "@nexus-ioc/core";
|
|
2
|
+
import { Container, createInternalModule, LazyModuleLoader, } from "@nexus-ioc/core/internal";
|
|
3
|
+
import { ContainerNotCompiledError } from "@nexus-ioc/shared";
|
|
4
|
+
import { HashTestingUtil } from "./hash-testing-util.js";
|
|
5
|
+
import { TestingCreator } from "./testing-creator.js";
|
|
6
|
+
export class Test {
|
|
7
|
+
constructor(metatype) {
|
|
8
|
+
this.metatype = metatype;
|
|
9
|
+
this.scannerPlugins = [];
|
|
10
|
+
this.hashTestingUtil = new HashTestingUtil();
|
|
11
|
+
this.container = new Container(this.hashTestingUtil);
|
|
12
|
+
this.moduleTestingCreator = new TestingCreator();
|
|
13
|
+
this._moduleContainer = null;
|
|
14
|
+
this._moduleDecorator = ModuleDecorator;
|
|
15
|
+
this._module = null;
|
|
16
|
+
this.containerCompiled = false;
|
|
17
|
+
this.lazyModuleLoader = new LazyModuleLoader((lazyModule) => this.load(lazyModule), (ref) => this.unload(ref));
|
|
18
|
+
}
|
|
19
|
+
static createModule(metatype) {
|
|
20
|
+
return new Test(metatype);
|
|
21
|
+
}
|
|
22
|
+
async addModule(metatype) {
|
|
23
|
+
return this.container.addModule(metatype);
|
|
24
|
+
}
|
|
25
|
+
async getModule(metatype) {
|
|
26
|
+
return this.container.getModule(metatype);
|
|
27
|
+
}
|
|
28
|
+
async replaceModule(metatypeToReplace, newMetatype) {
|
|
29
|
+
if (this.containerCompiled || this._moduleContainer) {
|
|
30
|
+
throw new Error("replaceModule must be called before compile()");
|
|
31
|
+
}
|
|
32
|
+
return this.container.replaceModule(metatypeToReplace, newMetatype);
|
|
33
|
+
}
|
|
34
|
+
get(token, options = {}) {
|
|
35
|
+
if (!this.containerCompiled) {
|
|
36
|
+
throw new ContainerNotCompiledError();
|
|
37
|
+
}
|
|
38
|
+
if (!this.container.hasProvider(token)) {
|
|
39
|
+
if (options.optional) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
throw new ProviderNotFoundError(token);
|
|
43
|
+
}
|
|
44
|
+
return this.container.get(token);
|
|
45
|
+
}
|
|
46
|
+
async resolve(token, options = {}) {
|
|
47
|
+
if (!this.containerCompiled) {
|
|
48
|
+
throw new ContainerNotCompiledError();
|
|
49
|
+
}
|
|
50
|
+
if (!this.container.hasProvider(token)) {
|
|
51
|
+
if (options.optional) {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
throw new ProviderNotFoundError(token);
|
|
55
|
+
}
|
|
56
|
+
return this.container.resolve(token);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Loads a lazy module into the testing container, like
|
|
60
|
+
* `NexusApplication.load()`. Also backs the injectable `LazyModuleLoader`.
|
|
61
|
+
*/
|
|
62
|
+
async load(lazyModule) {
|
|
63
|
+
if (!this.containerCompiled) {
|
|
64
|
+
throw new ContainerNotCompiledError();
|
|
65
|
+
}
|
|
66
|
+
const segment = await this.container.load(lazyModule);
|
|
67
|
+
await this.container.instantiateSingletons(segment.providerTokens);
|
|
68
|
+
return new ModuleRef(this.container, segment);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Unloads a lazy module previously loaded through `load()`, like
|
|
72
|
+
* `NexusApplication.unload()`. Also backs the injectable
|
|
73
|
+
* `LazyModuleLoader`.
|
|
74
|
+
*/
|
|
75
|
+
async unload(ref) {
|
|
76
|
+
if (!this.containerCompiled) {
|
|
77
|
+
throw new ContainerNotCompiledError();
|
|
78
|
+
}
|
|
79
|
+
return ref.unload();
|
|
80
|
+
}
|
|
81
|
+
async compile() {
|
|
82
|
+
this._module = this.moduleTestingCreator.create(this.metatype, this._moduleDecorator);
|
|
83
|
+
this._moduleContainer = await this.container.addModule(this._module);
|
|
84
|
+
await this.container.run(this._moduleContainer.metatype, [
|
|
85
|
+
createInternalModule(this.lazyModuleLoader),
|
|
86
|
+
]);
|
|
87
|
+
this.containerCompiled = true;
|
|
88
|
+
for (const scannerPlugin of this.scannerPlugins) {
|
|
89
|
+
await scannerPlugin.scan(this.container.graph);
|
|
90
|
+
}
|
|
91
|
+
await this.container.instantiateSingletons(this.container.graph.nodes.keys());
|
|
92
|
+
return this._moduleContainer;
|
|
93
|
+
}
|
|
94
|
+
get module() {
|
|
95
|
+
if (!this.containerCompiled) {
|
|
96
|
+
throw new ContainerNotCompiledError();
|
|
97
|
+
}
|
|
98
|
+
return this._module;
|
|
99
|
+
}
|
|
100
|
+
get moduleContainer() {
|
|
101
|
+
if (!this.containerCompiled) {
|
|
102
|
+
throw new ContainerNotCompiledError();
|
|
103
|
+
}
|
|
104
|
+
return this._moduleContainer;
|
|
105
|
+
}
|
|
106
|
+
addScannerPlugin(scanner) {
|
|
107
|
+
const plugins = Array.isArray(scanner) ? scanner : [scanner];
|
|
108
|
+
this.scannerPlugins.push(...plugins);
|
|
109
|
+
return this;
|
|
110
|
+
}
|
|
111
|
+
setModuleDecorator(decorator) {
|
|
112
|
+
this._moduleDecorator = decorator;
|
|
113
|
+
return this;
|
|
114
|
+
}
|
|
115
|
+
get errors() {
|
|
116
|
+
if (!this.containerCompiled) {
|
|
117
|
+
throw new ContainerNotCompiledError();
|
|
118
|
+
}
|
|
119
|
+
return this._moduleContainer?.errors;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=testing-container.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing-container.js","sourceRoot":"","sources":["../../../src/core/testing-container.ts"],"names":[],"mappings":"AAAA,OAAO,EAMN,MAAM,IAAI,eAAe,EAEzB,SAAS,EACT,qBAAqB,GAKrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACN,SAAS,EACT,oBAAoB,EACpB,gBAAgB,GAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAE9D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,MAAM,OAAO,IAAI;IAiBhB,YAAqC,QAAW;QAAX,aAAQ,GAAR,QAAQ,CAAG;QAd/B,mBAAc,GAA6B,EAAE,CAAC;QAC9C,oBAAe,GAAG,IAAI,eAAe,EAAE,CAAC;QACxC,cAAS,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAChD,yBAAoB,GAAG,IAAI,cAAc,EAAK,CAAC;QACxD,qBAAgB,GAAoC,IAAI,CAAC;QACzD,qBAAgB,GACvB,eAAe,CAAC;QACT,YAAO,GAAgB,IAAI,CAAC;QAC5B,sBAAiB,GAAG,KAAK,CAAC;QACjB,qBAAgB,GAAG,IAAI,gBAAgB,CACvD,CAAC,UAAU,EAAE,EAAE,CAAC,I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O,IAAI,CAAC;IACb,CAAC;IAED,IAAW,MAAM;QAChB,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC7B,MAAM,IAAI,yBAAyB,EAAE,CAAC;QACvC,CAAC;QAED,OAAO,IAAI,CAAC,gBAAgB,EAAE,MAAsB,CAAC;IACtD,CAAC;CACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing-creator.js","sourceRoot":"","sources":["../../../src/core/testing-creator.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,cAAc;IAC1B,MAAM,CACL,QAAW,EACX,eAAgD;QAEhD,MAAM,MAAM,GAAG;SAAQ,CAAC;QAExB,eAAe,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;QAElC,OAAO,MAAM,CAAC;IACf,CAAC;CACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAChD,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,sCAAsC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-testing-container.interface.js","sourceRoot":"","sources":["../../../src/interfaces/module-testing-container.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { HashUtilInterface } from "@nexus-ioc/
|
|
1
|
+
import type { HashUtilInterface } from "@nexus-ioc/shared";
|
|
2
2
|
export declare class HashTestingUtil implements HashUtilInterface {
|
|
3
3
|
private increment;
|
|
4
4
|
hashString(value: string): Promise<string>;
|
|
5
|
-
hashObject(
|
|
5
|
+
hashObject(_value: object): Promise<string>;
|
|
6
6
|
incrementString(): string;
|
|
7
7
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type DynamicModule, type GetOptions, type GraphError, type LazyModule, type ModuleContainerInterface, type ModuleMetadata, ModuleRef, type ProviderToken, type ScannerPluginInterface, type Type, type UnloadResult } from "@nexus-ioc/core";
|
|
2
|
+
import type { ModuleTestingContainerInterface } from "../interfaces";
|
|
3
|
+
export declare class Test<T extends ModuleMetadata = ModuleMetadata> implements ModuleTestingContainerInterface<T> {
|
|
4
|
+
private readonly metatype;
|
|
5
|
+
private readonly scannerPlugins;
|
|
6
|
+
private readonly hashTestingUtil;
|
|
7
|
+
private readonly container;
|
|
8
|
+
private readonly moduleTestingCreator;
|
|
9
|
+
private _moduleContainer;
|
|
10
|
+
private _moduleDecorator;
|
|
11
|
+
private _module;
|
|
12
|
+
private containerCompiled;
|
|
13
|
+
private readonly lazyModuleLoader;
|
|
14
|
+
private constructor();
|
|
15
|
+
static createModule<M extends ModuleMetadata = ModuleMetadata>(metatype: M): Test<M>;
|
|
16
|
+
addModule(metatype: Type | DynamicModule): Promise<ModuleContainerInterface>;
|
|
17
|
+
getModule(metatype: Type): Promise<ModuleContainerInterface | undefined>;
|
|
18
|
+
replaceModule(metatypeToReplace: Type, newMetatype: Type): Promise<ModuleContainerInterface>;
|
|
19
|
+
get<T>(token: ProviderToken<T>): T;
|
|
20
|
+
get<T>(token: ProviderToken<T>, options: {
|
|
21
|
+
optional: true;
|
|
22
|
+
}): T | undefined;
|
|
23
|
+
get<T>(token: ProviderToken<T>, options: {
|
|
24
|
+
optional?: false;
|
|
25
|
+
}): T;
|
|
26
|
+
get<T>(token: ProviderToken<T>, options: GetOptions): T | undefined;
|
|
27
|
+
resolve<T>(token: ProviderToken<T>): Promise<T>;
|
|
28
|
+
resolve<T>(token: ProviderToken<T>, options: {
|
|
29
|
+
optional: true;
|
|
30
|
+
}): Promise<T | undefined>;
|
|
31
|
+
resolve<T>(token: ProviderToken<T>, options: {
|
|
32
|
+
optional?: false;
|
|
33
|
+
}): Promise<T>;
|
|
34
|
+
resolve<T>(token: ProviderToken<T>, options: GetOptions): Promise<T | undefined>;
|
|
35
|
+
/**
|
|
36
|
+
* Loads a lazy module into the testing container, like
|
|
37
|
+
* `NexusApplication.load()`. Also backs the injectable `LazyModuleLoader`.
|
|
38
|
+
*/
|
|
39
|
+
load(lazyModule: LazyModule): Promise<ModuleRef>;
|
|
40
|
+
/**
|
|
41
|
+
* Unloads a lazy module previously loaded through `load()`, like
|
|
42
|
+
* `NexusApplication.unload()`. Also backs the injectable
|
|
43
|
+
* `LazyModuleLoader`.
|
|
44
|
+
*/
|
|
45
|
+
unload(ref: ModuleRef): Promise<UnloadResult>;
|
|
46
|
+
compile(): Promise<ModuleContainerInterface>;
|
|
47
|
+
get module(): Type<any> | null;
|
|
48
|
+
get moduleContainer(): ModuleContainerInterface | null;
|
|
49
|
+
addScannerPlugin(scanner: ScannerPluginInterface | ScannerPluginInterface[]): this;
|
|
50
|
+
setModuleDecorator(decorator: (metadata: T) => ClassDecorator): this;
|
|
51
|
+
get errors(): GraphError[];
|
|
52
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ContainerBaseInterface, GetOptions, LazyModule, ModuleContainerInterface, ModuleMetadata, ModulePluginInterface, ModuleRef, ProviderToken, UnloadResult } from "@nexus-ioc/core";
|
|
2
|
+
export interface ModuleTestingContainerInterface<_T extends ModuleMetadata> extends Omit<ContainerBaseInterface, "get" | "resolve" | "hasProvider">, ModulePluginInterface {
|
|
3
|
+
setModuleDecorator(decorator: <M extends ModuleMetadata = ModuleMetadata>(metadata: M) => ClassDecorator): this;
|
|
4
|
+
get<T>(token: ProviderToken<T>): T;
|
|
5
|
+
get<T>(token: ProviderToken<T>, options: {
|
|
6
|
+
optional: true;
|
|
7
|
+
}): T | undefined;
|
|
8
|
+
get<T>(token: ProviderToken<T>, options: {
|
|
9
|
+
optional?: false;
|
|
10
|
+
}): T;
|
|
11
|
+
get<T>(token: ProviderToken<T>, options: GetOptions): T | undefined;
|
|
12
|
+
resolve<T>(token: ProviderToken<T>): Promise<T>;
|
|
13
|
+
resolve<T>(token: ProviderToken<T>, options: {
|
|
14
|
+
optional: true;
|
|
15
|
+
}): Promise<T | undefined>;
|
|
16
|
+
resolve<T>(token: ProviderToken<T>, options: {
|
|
17
|
+
optional?: false;
|
|
18
|
+
}): Promise<T>;
|
|
19
|
+
resolve<T>(token: ProviderToken<T>, options: GetOptions): Promise<T | undefined>;
|
|
20
|
+
compile(): Promise<ModuleContainerInterface>;
|
|
21
|
+
load(lazyModule: LazyModule): Promise<ModuleRef>;
|
|
22
|
+
unload(ref: ModuleRef): Promise<UnloadResult>;
|
|
23
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexus-ioc/testing",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Testing helpers for Nexus IoC library",
|
|
5
5
|
"author": "IsqanderM <aleksandr.melnik.personal@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/Isqanderm/ioc#readme",
|
|
@@ -15,43 +15,66 @@
|
|
|
15
15
|
"lib": "src",
|
|
16
16
|
"test": "__test__"
|
|
17
17
|
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
18
21
|
"files": [
|
|
19
22
|
"dist",
|
|
23
|
+
"!dist/**/*.tsbuildinfo",
|
|
20
24
|
"package.json",
|
|
21
25
|
"LICENSE",
|
|
22
26
|
"README.md"
|
|
23
27
|
],
|
|
24
|
-
"main": "./dist/index.js",
|
|
25
|
-
"module": "./dist/index.js",
|
|
26
|
-
"types": "./dist/index.d.ts",
|
|
28
|
+
"main": "./dist/cjs/index.js",
|
|
29
|
+
"module": "./dist/esm/index.js",
|
|
30
|
+
"types": "./dist/types/index.d.ts",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"import": {
|
|
34
|
+
"types": "./dist/types/index.d.ts",
|
|
35
|
+
"default": "./dist/esm/index.js"
|
|
36
|
+
},
|
|
37
|
+
"require": {
|
|
38
|
+
"types": "./dist/types/index.d.ts",
|
|
39
|
+
"default": "./dist/cjs/index.js"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"sideEffects": false,
|
|
27
44
|
"license": "MIT",
|
|
28
45
|
"peerDependencies": {
|
|
29
|
-
"
|
|
30
|
-
"
|
|
46
|
+
"@nexus-ioc/core": "^0.7.0",
|
|
47
|
+
"reflect-metadata": "^0.1.12 || ^0.2.0"
|
|
31
48
|
},
|
|
32
49
|
"devDependencies": {
|
|
33
|
-
"@
|
|
34
|
-
"@types/node": "^
|
|
35
|
-
"
|
|
50
|
+
"@nexus-ioc/core": "^0.7.0",
|
|
51
|
+
"@types/node": "^24.8.1",
|
|
52
|
+
"@vitest/coverage-v8": "^3.0.0",
|
|
36
53
|
"reflect-metadata": "^0.1.12 || ^0.2.0",
|
|
37
|
-
"sinon": "^
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
54
|
+
"sinon": "^21.0.0",
|
|
55
|
+
"typescript": "^5.9.3",
|
|
56
|
+
"vite": "^7.0.0",
|
|
57
|
+
"vitest": "^3.0.0"
|
|
41
58
|
},
|
|
42
59
|
"dependencies": {
|
|
60
|
+
"@nexus-ioc/shared": "^0.7.0",
|
|
43
61
|
"tslib": "^2.7.0"
|
|
44
62
|
},
|
|
45
63
|
"scripts": {
|
|
46
|
-
"build": "
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"test
|
|
64
|
+
"build": "npm run build:cjs && npm run build:esm",
|
|
65
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
66
|
+
"build:esm": "tsc -p tsconfig.esm.json && node ../../scripts/fix-esm-imports.js dist/esm && echo '{\"type\":\"module\"}' > dist/esm/package.json",
|
|
67
|
+
"test": "vitest run",
|
|
68
|
+
"clean": "rm -rf ./dist && rm -f tsconfig*.tsbuildinfo",
|
|
69
|
+
"test:watch": "vitest",
|
|
70
|
+
"test:ui": "vitest --ui",
|
|
71
|
+
"test:coverage": "vitest run --coverage",
|
|
50
72
|
"code:format": "npx @biomejs/biome format --write",
|
|
51
73
|
"code:lint": "npx @biomejs/biome lint --write",
|
|
52
74
|
"code:check": "npx @biomejs/biome check",
|
|
53
75
|
"code:check:ci": "npx @biomejs/biome ci",
|
|
54
76
|
"code:check:apply": "npx @biomejs/biome check --write",
|
|
55
|
-
"test:ready": "
|
|
56
|
-
}
|
|
77
|
+
"test:ready": "npm run build"
|
|
78
|
+
},
|
|
79
|
+
"gitHead": "1246f1b9b3ba543f6618a6165adc68630ce26928"
|
|
57
80
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hash-testing-util.js","sourceRoot":"","sources":["../../src/core/hash-testing-util.ts"],"names":[],"mappings":";;;AAEA,MAAa,eAAe;IAA5B;QACS,cAAS,GAAG,CAAC,CAAC;IAwBvB,CAAC;IAvBA,KAAK,CAAC,UAAU,CAAC,KAAa;QAC7B,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,OAAO,IAAI,KAAK,CAAC,EAAE,CAAC;aAClB,IAAI,CAAC,IAAI,CAAC;aACV,GAAG,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,CAAC;YAER,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;gBAC3B,KAAK,GAAG,CAAC,CAAC;YACX,CAAC;YAED,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC5B,CAAC,CAAC;aACD,IAAI,CAAC,EAAE,CAAC,CAAC;IACZ,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,KAAa;QAC7B,OAAO,EAAE,CAAC;IACX,CAAC;IAED,eAAe;QACd,OAAO,GAAG,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;IAC9B,CAAC;CACD;AAzBD,0CAyBC"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { type DynamicModule, type GraphError, type InjectionToken, type Module, type ModuleContainerInterface, type ModuleMetadata, type ScannerPluginInterface } from "@nexus-ioc/core";
|
|
2
|
-
import type { ModuleTestingContainerInterface } from "../interfaces";
|
|
3
|
-
export declare class Test<T extends ModuleMetadata = ModuleMetadata> implements ModuleTestingContainerInterface<T> {
|
|
4
|
-
private readonly metatype;
|
|
5
|
-
private readonly scannerPlugins;
|
|
6
|
-
private readonly hashTestingUtil;
|
|
7
|
-
private readonly container;
|
|
8
|
-
private readonly moduleTestingCreator;
|
|
9
|
-
private _moduleContainer;
|
|
10
|
-
private _moduleDecorator;
|
|
11
|
-
private _module;
|
|
12
|
-
private containerCompiled;
|
|
13
|
-
private constructor();
|
|
14
|
-
static createModule<M extends ModuleMetadata = ModuleMetadata>(metatype: M): Test<M>;
|
|
15
|
-
addModule(metatype: Module | DynamicModule): Promise<ModuleContainerInterface>;
|
|
16
|
-
getModule(metatype: Module): Promise<ModuleContainerInterface | undefined>;
|
|
17
|
-
replaceModule(metatypeToReplace: Module, newMetatype: Module): Promise<ModuleContainerInterface>;
|
|
18
|
-
get<T>(token: InjectionToken): Promise<T | undefined>;
|
|
19
|
-
compile(): Promise<ModuleContainerInterface>;
|
|
20
|
-
get module(): Module | null;
|
|
21
|
-
get moduleContainer(): ModuleContainerInterface | null;
|
|
22
|
-
addScannerPlugin(scanner: ScannerPluginInterface | ScannerPluginInterface[]): this;
|
|
23
|
-
setModuleDecorator(decorator: (metadata: T) => ClassDecorator): this;
|
|
24
|
-
get errors(): GraphError[];
|
|
25
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Test = void 0;
|
|
4
|
-
const core_1 = require("@nexus-ioc/core");
|
|
5
|
-
const container_1 = require("@nexus-ioc/core/dist/core/modules/container");
|
|
6
|
-
const container_not_compiled_error_1 = require("@nexus-ioc/core/dist/errors/container-not-compiled.error");
|
|
7
|
-
const hash_testing_util_1 = require("./hash-testing-util");
|
|
8
|
-
const testing_creator_1 = require("./testing-creator");
|
|
9
|
-
class Test {
|
|
10
|
-
constructor(metatype) {
|
|
11
|
-
this.metatype = metatype;
|
|
12
|
-
this.scannerPlugins = [];
|
|
13
|
-
this.hashTestingUtil = new hash_testing_util_1.HashTestingUtil();
|
|
14
|
-
this.container = new container_1.Container(this.hashTestingUtil);
|
|
15
|
-
this.moduleTestingCreator = new testing_creator_1.TestingCreator();
|
|
16
|
-
this._moduleContainer = null;
|
|
17
|
-
this._moduleDecorator = core_1.NsModule;
|
|
18
|
-
this._module = null;
|
|
19
|
-
this.containerCompiled = false;
|
|
20
|
-
}
|
|
21
|
-
static createModule(metatype) {
|
|
22
|
-
return new Test(metatype);
|
|
23
|
-
}
|
|
24
|
-
async addModule(metatype) {
|
|
25
|
-
return this.container.addModule(metatype);
|
|
26
|
-
}
|
|
27
|
-
async getModule(metatype) {
|
|
28
|
-
return this.container.getModule(metatype);
|
|
29
|
-
}
|
|
30
|
-
async replaceModule(metatypeToReplace, newMetatype) {
|
|
31
|
-
return this.container.replaceModule(metatypeToReplace, newMetatype);
|
|
32
|
-
}
|
|
33
|
-
get(token) {
|
|
34
|
-
if (!this.containerCompiled) {
|
|
35
|
-
throw new container_not_compiled_error_1.ContainerNotCompiledError();
|
|
36
|
-
}
|
|
37
|
-
return this.container.get(token);
|
|
38
|
-
}
|
|
39
|
-
async compile() {
|
|
40
|
-
this._module = this.moduleTestingCreator.create(this.metatype, this._moduleDecorator);
|
|
41
|
-
this._moduleContainer = await this.container.addModule(this._module);
|
|
42
|
-
await this.container.run(this._moduleContainer.metatype);
|
|
43
|
-
this.containerCompiled = true;
|
|
44
|
-
for (const scannerPlugin of this.scannerPlugins) {
|
|
45
|
-
await scannerPlugin.scan(this.container.graph);
|
|
46
|
-
}
|
|
47
|
-
return this._moduleContainer;
|
|
48
|
-
}
|
|
49
|
-
get module() {
|
|
50
|
-
if (!this.containerCompiled) {
|
|
51
|
-
throw new container_not_compiled_error_1.ContainerNotCompiledError();
|
|
52
|
-
}
|
|
53
|
-
return this._module;
|
|
54
|
-
}
|
|
55
|
-
get moduleContainer() {
|
|
56
|
-
if (!this.containerCompiled) {
|
|
57
|
-
throw new container_not_compiled_error_1.ContainerNotCompiledError();
|
|
58
|
-
}
|
|
59
|
-
return this._moduleContainer;
|
|
60
|
-
}
|
|
61
|
-
addScannerPlugin(scanner) {
|
|
62
|
-
const plugins = Array.isArray(scanner) ? scanner : [scanner];
|
|
63
|
-
this.scannerPlugins.push(...plugins);
|
|
64
|
-
return this;
|
|
65
|
-
}
|
|
66
|
-
setModuleDecorator(decorator) {
|
|
67
|
-
this._moduleDecorator = decorator;
|
|
68
|
-
return this;
|
|
69
|
-
}
|
|
70
|
-
get errors() {
|
|
71
|
-
if (!this.containerCompiled) {
|
|
72
|
-
throw new container_not_compiled_error_1.ContainerNotCompiledError();
|
|
73
|
-
}
|
|
74
|
-
return this._moduleContainer?.errors;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
exports.Test = Test;
|
|
78
|
-
//# sourceMappingURL=testing-container.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"testing-container.js","sourceRoot":"","sources":["../../src/core/testing-container.ts"],"names":[],"mappings":";;;AAAA,0CASyB;AACzB,2EAAwE;AACxE,2GAAqG;AAErG,2DAAsD;AACtD,uDAAmD;AAEnD,MAAa,IAAI;IAahB,YAAqC,QAAW;QAAX,aAAQ,GAAR,QAAQ,CAAG;QAV/B,mBAAc,GAA6B,EAAE,CAAC;QAC9C,oBAAe,GAAG,IAAI,mCAAe,EAAE,CAAC;QACxC,cAAS,GAAG,IAAI,qBAAS,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAChD,yBAAoB,GAAG,IAAI,gCAAc,EAAK,CAAC;QACxD,qBAAgB,GA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ACX,eAAgD;QAEhD,MAAM,MAAM,GAAG;SAAQ,CAAC;QAExB,eAAe,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;QAElC,OAAO,MAAM,CAAC;IACf,CAAC;CACD;AAXD,wCAWC"}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,8DAAgD;AAAvC,yGAAA,IAAI,OAAA;AACb,uDAA6B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":";;;AAAA,+EAAqD"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { ContainerBaseInterface, ModuleContainerInterface, ModuleMetadata, ModulePluginInterface } from "@nexus-ioc/core";
|
|
2
|
-
export interface ModuleTestingContainerInterface<T extends ModuleMetadata> extends ContainerBaseInterface, ModulePluginInterface {
|
|
3
|
-
setModuleDecorator(decorator: <M extends ModuleMetadata = ModuleMetadata>(metadata: M) => ClassDecorator): this;
|
|
4
|
-
compile(): Promise<ModuleContainerInterface>;
|
|
5
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"module-testing-container.interface.js","sourceRoot":"","sources":["../../src/interfaces/module-testing-container.interface.ts"],"names":[],"mappings":""}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|