@zeltjs/testing 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 9wick / Kohei Kido
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,15 @@
1
+ import { Container, Token } from "@needle-di/core";
2
+
3
+ //#region src/test-container.d.ts
4
+ type PickedProvider<T> = {
5
+ provide: Token<T>;
6
+ useValue: Partial<T>;
7
+ };
8
+ type CreateContainerParams = <T, A extends unknown[]>(token: Token<T>, providers?: { [K in keyof A]: PickedProvider<A[K]> }) => {
9
+ target: T;
10
+ container: Container;
11
+ };
12
+ declare const createTestContainer: CreateContainerParams;
13
+ //#endregion
14
+ export { createTestContainer };
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/test-container.ts"],"mappings":";;;KAKK,cAAA;EACH,OAAA,EAAS,KAAA,CAAM,CAAA;EACf,QAAA,EAAU,OAAA,CAAQ,CAAA;AAAA;AAAA,KAGf,qBAAA,4BACH,KAAA,EAAO,KAAA,CAAM,CAAA,GACb,SAAA,iBAA0B,CAAA,GAAI,cAAA,CAAe,CAAA,CAAE,CAAA;EAC1C,MAAA,EAAQ,CAAA;EAAG,SAAA,EAAW,SAAA;AAAA;AAAA,cAEhB,mBAAA,EAAqB,qBAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ import { Container } from "@needle-di/core";
2
+ //#region src/test-container.ts
3
+ let baseContainer = null;
4
+ const createTestContainer = (targetClass, providers) => {
5
+ const childContainer = getBaseContainer().createChild();
6
+ providers?.map((p) => childContainer.bind(p));
7
+ return {
8
+ target: childContainer.get(targetClass),
9
+ container: childContainer
10
+ };
11
+ };
12
+ const getBaseContainer = () => {
13
+ if (baseContainer) return baseContainer;
14
+ baseContainer = new Container();
15
+ return baseContainer;
16
+ };
17
+ //#endregion
18
+ export { createTestContainer };
19
+
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/test-container.ts"],"sourcesContent":["import { Container } from '@needle-di/core';\nimport type { Token } from '@needle-di/core';\n\nlet baseContainer: Container | null = null;\n\ntype PickedProvider<T> = {\n provide: Token<T>;\n useValue: Partial<T>;\n};\n\ntype CreateContainerParams = <T, A extends unknown[]>(\n token: Token<T>,\n providers?: { [K in keyof A]: PickedProvider<A[K]> },\n) => { target: T; container: Container };\n\nexport const createTestContainer: CreateContainerParams = (targetClass, providers) => {\n const baseContainer = getBaseContainer();\n const childContainer = baseContainer.createChild();\n providers?.map((p) => childContainer.bind(p));\n const target = childContainer.get(targetClass); // 依存関係を解決してインスタンスを生成\n return { target, container: childContainer };\n};\n\nconst getBaseContainer = () => {\n if (baseContainer) {\n return baseContainer;\n }\n baseContainer = new Container();\n\n // 本来は利用側で必要なものをdummy inject する\n // (zelt framework 自体は default 持たない)\n\n return baseContainer;\n};\n"],"mappings":";;AAGA,IAAI,gBAAkC;AAYtC,MAAa,uBAA8C,aAAa,cAAc;CAEpF,MAAM,iBADgB,kBACc,CAAC,aAAa;AAClD,YAAW,KAAK,MAAM,eAAe,KAAK,EAAE,CAAC;AAE7C,QAAO;EAAE,QADM,eAAe,IAAI,YACnB;EAAE,WAAW;EAAgB;;AAG9C,MAAM,yBAAyB;AAC7B,KAAI,cACF,QAAO;AAET,iBAAgB,IAAI,WAAW;AAK/B,QAAO"}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@zeltjs/testing",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/zeltjs/zelt.git",
9
+ "directory": "packages/testing"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "peerDependencies": {
24
+ "@needle-di/core": "1.1.2",
25
+ "vitest": ">=4 <5",
26
+ "@zeltjs/core": "0.0.1"
27
+ },
28
+ "devDependencies": {
29
+ "@needle-di/core": "1.1.2"
30
+ },
31
+ "scripts": {
32
+ "build": "tsdown",
33
+ "test": "vitest run",
34
+ "typecheck": "tsc -b"
35
+ }
36
+ }