@nexus-ioc/testing 0.6.1 → 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 +37 -1
- package/dist/cjs/core/testing-container.js +53 -4
- package/dist/cjs/core/testing-container.js.map +1 -1
- package/dist/esm/core/testing-container.js +52 -3
- package/dist/esm/core/testing-container.js.map +1 -1
- package/dist/types/core/testing-container.d.ts +33 -6
- package/dist/types/interfaces/module-testing-container.interface.d.ts +20 -2
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
- [Installation](#installation)
|
|
21
21
|
- [Quick Start](#quick-start)
|
|
22
|
+
- [inject() with fakes](#inject-with-fakes)
|
|
22
23
|
- [License](#license)
|
|
23
24
|
- [Author](#author)
|
|
24
25
|
- [Contributing](#contributing)
|
|
@@ -46,12 +47,47 @@ describe('AppModule', () => {
|
|
|
46
47
|
providers: [AppService],
|
|
47
48
|
}).compile();
|
|
48
49
|
|
|
49
|
-
const appService =
|
|
50
|
+
const appService = appModule.get<AppService>(AppService);
|
|
50
51
|
expect(appService).toBeInstanceOf(AppService);
|
|
51
52
|
});
|
|
52
53
|
});
|
|
53
54
|
```
|
|
54
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
|
+
|
|
55
91
|
## License
|
|
56
92
|
|
|
57
93
|
This project is licensed under the MIT License. See the LICENSE file for details.
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Test = void 0;
|
|
4
4
|
const core_1 = require("@nexus-ioc/core");
|
|
5
|
+
const internal_1 = require("@nexus-ioc/core/internal");
|
|
5
6
|
const shared_1 = require("@nexus-ioc/shared");
|
|
6
7
|
const hash_testing_util_1 = require("./hash-testing-util");
|
|
7
8
|
const testing_creator_1 = require("./testing-creator");
|
|
@@ -10,12 +11,13 @@ class Test {
|
|
|
10
11
|
this.metatype = metatype;
|
|
11
12
|
this.scannerPlugins = [];
|
|
12
13
|
this.hashTestingUtil = new hash_testing_util_1.HashTestingUtil();
|
|
13
|
-
this.container = new
|
|
14
|
+
this.container = new internal_1.Container(this.hashTestingUtil);
|
|
14
15
|
this.moduleTestingCreator = new testing_creator_1.TestingCreator();
|
|
15
16
|
this._moduleContainer = null;
|
|
16
|
-
this._moduleDecorator = core_1.
|
|
17
|
+
this._moduleDecorator = core_1.Module;
|
|
17
18
|
this._module = null;
|
|
18
19
|
this.containerCompiled = false;
|
|
20
|
+
this.lazyModuleLoader = new internal_1.LazyModuleLoader((lazyModule) => this.load(lazyModule), (ref) => this.unload(ref));
|
|
19
21
|
}
|
|
20
22
|
static createModule(metatype) {
|
|
21
23
|
return new Test(metatype);
|
|
@@ -27,22 +29,69 @@ class Test {
|
|
|
27
29
|
return this.container.getModule(metatype);
|
|
28
30
|
}
|
|
29
31
|
async replaceModule(metatypeToReplace, newMetatype) {
|
|
32
|
+
if (this.containerCompiled || this._moduleContainer) {
|
|
33
|
+
throw new Error("replaceModule must be called before compile()");
|
|
34
|
+
}
|
|
30
35
|
return this.container.replaceModule(metatypeToReplace, newMetatype);
|
|
31
36
|
}
|
|
32
|
-
get(token) {
|
|
37
|
+
get(token, options = {}) {
|
|
33
38
|
if (!this.containerCompiled) {
|
|
34
39
|
throw new shared_1.ContainerNotCompiledError();
|
|
35
40
|
}
|
|
41
|
+
if (!this.container.hasProvider(token)) {
|
|
42
|
+
if (options.optional) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
throw new core_1.ProviderNotFoundError(token);
|
|
46
|
+
}
|
|
36
47
|
return this.container.get(token);
|
|
37
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
|
+
}
|
|
38
84
|
async compile() {
|
|
39
85
|
this._module = this.moduleTestingCreator.create(this.metatype, this._moduleDecorator);
|
|
40
86
|
this._moduleContainer = await this.container.addModule(this._module);
|
|
41
|
-
await this.container.run(this._moduleContainer.metatype
|
|
87
|
+
await this.container.run(this._moduleContainer.metatype, [
|
|
88
|
+
(0, internal_1.createInternalModule)(this.lazyModuleLoader),
|
|
89
|
+
]);
|
|
42
90
|
this.containerCompiled = true;
|
|
43
91
|
for (const scannerPlugin of this.scannerPlugins) {
|
|
44
92
|
await scannerPlugin.scan(this.container.graph);
|
|
45
93
|
}
|
|
94
|
+
await this.container.instantiateSingletons(this.container.graph.nodes.keys());
|
|
46
95
|
return this._moduleContainer;
|
|
47
96
|
}
|
|
48
97
|
get module() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing-container.js","sourceRoot":"","sources":["../../../src/core/testing-container.ts"],"names":[],"mappings":";;;AAAA,
|
|
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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OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAC7D,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC;QACrC,OAAO,IAAI,CAAC;IACb,CAAC;IAEM,kBAAkB,CAAC,SAA0C;QACnE,IAAI,CAAC,gBAAgB,GAAG,SAAS,CAAC;QAClC,OAAO,IAAI,CAAC;IACb,CAAC;IAED,IAAW,MAAM;QAChB,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC7B,MAAM,IAAI,kCAAyB,EAAE,CAAC;QACvC,CAAC;QAED,OAAO,IAAI,CAAC,gBAAgB,EAAE,MAAsB,CAAC;IACtD,CAAC;CACD;AA1LD,oBA0LC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Module as ModuleDecorator, ModuleRef, ProviderNotFoundError, } from "@nexus-ioc/core";
|
|
2
|
+
import { Container, createInternalModule, LazyModuleLoader, } from "@nexus-ioc/core/internal";
|
|
2
3
|
import { ContainerNotCompiledError } from "@nexus-ioc/shared";
|
|
3
4
|
import { HashTestingUtil } from "./hash-testing-util.js";
|
|
4
5
|
import { TestingCreator } from "./testing-creator.js";
|
|
@@ -13,6 +14,7 @@ export class Test {
|
|
|
13
14
|
this._moduleDecorator = ModuleDecorator;
|
|
14
15
|
this._module = null;
|
|
15
16
|
this.containerCompiled = false;
|
|
17
|
+
this.lazyModuleLoader = new LazyModuleLoader((lazyModule) => this.load(lazyModule), (ref) => this.unload(ref));
|
|
16
18
|
}
|
|
17
19
|
static createModule(metatype) {
|
|
18
20
|
return new Test(metatype);
|
|
@@ -24,22 +26,69 @@ export class Test {
|
|
|
24
26
|
return this.container.getModule(metatype);
|
|
25
27
|
}
|
|
26
28
|
async replaceModule(metatypeToReplace, newMetatype) {
|
|
29
|
+
if (this.containerCompiled || this._moduleContainer) {
|
|
30
|
+
throw new Error("replaceModule must be called before compile()");
|
|
31
|
+
}
|
|
27
32
|
return this.container.replaceModule(metatypeToReplace, newMetatype);
|
|
28
33
|
}
|
|
29
|
-
get(token) {
|
|
34
|
+
get(token, options = {}) {
|
|
30
35
|
if (!this.containerCompiled) {
|
|
31
36
|
throw new ContainerNotCompiledError();
|
|
32
37
|
}
|
|
38
|
+
if (!this.container.hasProvider(token)) {
|
|
39
|
+
if (options.optional) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
throw new ProviderNotFoundError(token);
|
|
43
|
+
}
|
|
33
44
|
return this.container.get(token);
|
|
34
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
|
+
}
|
|
35
81
|
async compile() {
|
|
36
82
|
this._module = this.moduleTestingCreator.create(this.metatype, this._moduleDecorator);
|
|
37
83
|
this._moduleContainer = await this.container.addModule(this._module);
|
|
38
|
-
await this.container.run(this._moduleContainer.metatype
|
|
84
|
+
await this.container.run(this._moduleContainer.metatype, [
|
|
85
|
+
createInternalModule(this.lazyModuleLoader),
|
|
86
|
+
]);
|
|
39
87
|
this.containerCompiled = true;
|
|
40
88
|
for (const scannerPlugin of this.scannerPlugins) {
|
|
41
89
|
await scannerPlugin.scan(this.container.graph);
|
|
42
90
|
}
|
|
91
|
+
await this.container.instantiateSingletons(this.container.graph.nodes.keys());
|
|
43
92
|
return this._moduleContainer;
|
|
44
93
|
}
|
|
45
94
|
get module() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing-container.js","sourceRoot":"","sources":["../../../src/core/testing-container.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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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AC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAC7D,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC;QACrC,OAAO,IAAI,CAAC;IACb,CAAC;IAEM,kBAAkB,CAAC,SAA0C;QACnE,IAAI,CAAC,gBAAgB,GAAG,SAAS,CAAC;QAClC,OAAO,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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type DynamicModule, type
|
|
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
2
|
import type { ModuleTestingContainerInterface } from "../interfaces";
|
|
3
3
|
export declare class Test<T extends ModuleMetadata = ModuleMetadata> implements ModuleTestingContainerInterface<T> {
|
|
4
4
|
private readonly metatype;
|
|
@@ -10,14 +10,41 @@ export declare class Test<T extends ModuleMetadata = ModuleMetadata> implements
|
|
|
10
10
|
private _moduleDecorator;
|
|
11
11
|
private _module;
|
|
12
12
|
private containerCompiled;
|
|
13
|
+
private readonly lazyModuleLoader;
|
|
13
14
|
private constructor();
|
|
14
15
|
static createModule<M extends ModuleMetadata = ModuleMetadata>(metatype: M): Test<M>;
|
|
15
|
-
addModule(metatype:
|
|
16
|
-
getModule(metatype:
|
|
17
|
-
replaceModule(metatypeToReplace:
|
|
18
|
-
get<T>(token:
|
|
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>;
|
|
19
46
|
compile(): Promise<ModuleContainerInterface>;
|
|
20
|
-
get module():
|
|
47
|
+
get module(): Type<any> | null;
|
|
21
48
|
get moduleContainer(): ModuleContainerInterface | null;
|
|
22
49
|
addScannerPlugin(scanner: ScannerPluginInterface | ScannerPluginInterface[]): this;
|
|
23
50
|
setModuleDecorator(decorator: (metadata: T) => ClassDecorator): this;
|
|
@@ -1,5 +1,23 @@
|
|
|
1
|
-
import type { ContainerBaseInterface, ModuleContainerInterface, ModuleMetadata, ModulePluginInterface } from "@nexus-ioc/core";
|
|
2
|
-
export interface ModuleTestingContainerInterface<_T extends ModuleMetadata> extends ContainerBaseInterface, ModulePluginInterface {
|
|
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
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>;
|
|
4
20
|
compile(): Promise<ModuleContainerInterface>;
|
|
21
|
+
load(lazyModule: LazyModule): Promise<ModuleRef>;
|
|
22
|
+
unload(ref: ModuleRef): Promise<UnloadResult>;
|
|
5
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",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
22
|
"dist",
|
|
23
|
+
"!dist/**/*.tsbuildinfo",
|
|
23
24
|
"package.json",
|
|
24
25
|
"LICENSE",
|
|
25
26
|
"README.md"
|
|
@@ -42,11 +43,11 @@
|
|
|
42
43
|
"sideEffects": false,
|
|
43
44
|
"license": "MIT",
|
|
44
45
|
"peerDependencies": {
|
|
45
|
-
"@nexus-ioc/core": "^0.
|
|
46
|
+
"@nexus-ioc/core": "^0.7.0",
|
|
46
47
|
"reflect-metadata": "^0.1.12 || ^0.2.0"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
49
|
-
"@nexus-ioc/core": "^0.
|
|
50
|
+
"@nexus-ioc/core": "^0.7.0",
|
|
50
51
|
"@types/node": "^24.8.1",
|
|
51
52
|
"@vitest/coverage-v8": "^3.0.0",
|
|
52
53
|
"reflect-metadata": "^0.1.12 || ^0.2.0",
|
|
@@ -56,7 +57,7 @@
|
|
|
56
57
|
"vitest": "^3.0.0"
|
|
57
58
|
},
|
|
58
59
|
"dependencies": {
|
|
59
|
-
"@nexus-ioc/shared": "^0.
|
|
60
|
+
"@nexus-ioc/shared": "^0.7.0",
|
|
60
61
|
"tslib": "^2.7.0"
|
|
61
62
|
},
|
|
62
63
|
"scripts": {
|