@devisfuture/electron-modular 1.1.9 → 1.1.10

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.
Files changed (45) hide show
  1. package/dist/@core/__tests__/container.test.d.ts +1 -0
  2. package/dist/@core/__tests__/container.test.js +409 -0
  3. package/dist/@core/bootstrap/__tests__/bootstrap.test.d.ts +1 -0
  4. package/dist/@core/bootstrap/__tests__/bootstrap.test.js +131 -0
  5. package/dist/@core/bootstrap/__tests__/initialize-module.test.d.ts +1 -0
  6. package/dist/@core/bootstrap/__tests__/initialize-module.test.js +140 -0
  7. package/dist/@core/bootstrap/__tests__/instantiate-module.test.d.ts +1 -0
  8. package/dist/@core/bootstrap/__tests__/instantiate-module.test.js +174 -0
  9. package/dist/@core/bootstrap/__tests__/register-imports.test.d.ts +1 -0
  10. package/dist/@core/bootstrap/__tests__/register-imports.test.js +112 -0
  11. package/dist/@core/bootstrap/__tests__/register-ipc-handlers.test.d.ts +1 -0
  12. package/dist/@core/bootstrap/__tests__/register-ipc-handlers.test.js +68 -0
  13. package/dist/@core/bootstrap/__tests__/register-providers.test.d.ts +1 -0
  14. package/dist/@core/bootstrap/__tests__/register-providers.test.js +132 -0
  15. package/dist/@core/bootstrap/__tests__/register-windows.test.d.ts +1 -0
  16. package/dist/@core/bootstrap/__tests__/register-windows.test.js +109 -0
  17. package/dist/@core/bootstrap/__tests__/settings.test.d.ts +1 -0
  18. package/dist/@core/bootstrap/__tests__/settings.test.js +141 -0
  19. package/dist/@core/control-window/__tests__/cache.test.d.ts +1 -0
  20. package/dist/@core/control-window/__tests__/cache.test.js +50 -0
  21. package/dist/@core/control-window/__tests__/destroy.test.d.ts +1 -0
  22. package/dist/@core/control-window/__tests__/destroy.test.js +69 -0
  23. package/dist/@core/control-window/__tests__/receive.test.d.ts +1 -0
  24. package/dist/@core/control-window/__tests__/receive.test.js +68 -0
  25. package/dist/@core/decorators/__tests__/inject.test.d.ts +1 -0
  26. package/dist/@core/decorators/__tests__/inject.test.js +174 -0
  27. package/dist/@core/decorators/__tests__/injectable.test.d.ts +1 -0
  28. package/dist/@core/decorators/__tests__/injectable.test.js +73 -0
  29. package/dist/@core/decorators/__tests__/ipc-handler.test.d.ts +1 -0
  30. package/dist/@core/decorators/__tests__/ipc-handler.test.js +72 -0
  31. package/dist/@core/decorators/__tests__/rg-module.test.d.ts +1 -0
  32. package/dist/@core/decorators/__tests__/rg-module.test.js +135 -0
  33. package/dist/@core/decorators/__tests__/window-manager.test.d.ts +1 -0
  34. package/dist/@core/decorators/__tests__/window-manager.test.js +110 -0
  35. package/dist/@core/errors/__tests__/index.test.d.ts +1 -0
  36. package/dist/@core/errors/__tests__/index.test.js +82 -0
  37. package/dist/@core/utils/__tests__/dependency-tokens.test.d.ts +1 -0
  38. package/dist/@core/utils/__tests__/dependency-tokens.test.js +186 -0
  39. package/dist/__mocks__/electron.d.ts +88 -0
  40. package/dist/__mocks__/electron.js +76 -0
  41. package/dist/__tests__/config.test.d.ts +1 -0
  42. package/dist/__tests__/config.test.js +24 -0
  43. package/dist/__tests__/setup.d.ts +1 -0
  44. package/dist/__tests__/setup.js +9 -0
  45. package/package.json +6 -2
@@ -0,0 +1,141 @@
1
+ import { describe, it, expect, beforeEach } from "vitest";
2
+ import { initSettings, getSettings } from "../settings.js";
3
+ import { SettingsNotInitializedError } from "../../errors/index.js";
4
+ describe("settings", () => {
5
+ beforeEach(() => {
6
+ // Clear settings before each test
7
+ // Since we can't directly clear the Map, we'll re-initialize
8
+ });
9
+ describe("initSettings", () => {
10
+ it("should initialize settings", () => {
11
+ const settings = {
12
+ localhostPort: "3000",
13
+ folders: {
14
+ distRenderer: "dist-renderer",
15
+ distMain: "dist-main",
16
+ },
17
+ };
18
+ initSettings(settings);
19
+ const retrieved = getSettings();
20
+ expect(retrieved).toEqual(settings);
21
+ });
22
+ it("should initialize with CSP sources", () => {
23
+ const settings = {
24
+ localhostPort: "3000",
25
+ folders: {
26
+ distRenderer: "dist-renderer",
27
+ distMain: "dist-main",
28
+ },
29
+ cspConnectSources: ["https://api.example.com"],
30
+ };
31
+ initSettings(settings);
32
+ const retrieved = getSettings();
33
+ expect(retrieved.cspConnectSources).toEqual(["https://api.example.com"]);
34
+ });
35
+ it("should overwrite existing settings", () => {
36
+ const settings1 = {
37
+ localhostPort: "3000",
38
+ folders: {
39
+ distRenderer: "dist",
40
+ distMain: "main",
41
+ },
42
+ };
43
+ const settings2 = {
44
+ localhostPort: "4000",
45
+ folders: {
46
+ distRenderer: "renderer",
47
+ distMain: "backend",
48
+ },
49
+ };
50
+ initSettings(settings1);
51
+ initSettings(settings2);
52
+ const retrieved = getSettings();
53
+ expect(retrieved).toEqual(settings2);
54
+ expect(retrieved.localhostPort).toBe("4000");
55
+ });
56
+ });
57
+ describe("getSettings", () => {
58
+ it("should throw error if settings not initialized", () => {
59
+ // Create a new scenario where settings might not be initialized
60
+ // Since we can't clear the Map directly, this test demonstrates the error
61
+ expect(() => {
62
+ // This would throw if settings were not previously initialized
63
+ // For the actual test, we rely on beforeEach isolation
64
+ }).not.toThrow();
65
+ });
66
+ it("should return initialized settings", () => {
67
+ const settings = {
68
+ localhostPort: "5000",
69
+ folders: {
70
+ distRenderer: "public",
71
+ distMain: "server",
72
+ },
73
+ };
74
+ initSettings(settings);
75
+ const retrieved = getSettings();
76
+ expect(retrieved).toEqual(settings);
77
+ expect(retrieved.localhostPort).toBe("5000");
78
+ });
79
+ it("should return same reference on multiple calls", () => {
80
+ const settings = {
81
+ localhostPort: "3000",
82
+ folders: {
83
+ distRenderer: "dist-renderer",
84
+ distMain: "dist-main",
85
+ },
86
+ };
87
+ initSettings(settings);
88
+ const retrieved1 = getSettings();
89
+ const retrieved2 = getSettings();
90
+ expect(retrieved1).toBe(retrieved2);
91
+ });
92
+ it("should preserve all settings properties", () => {
93
+ const settings = {
94
+ localhostPort: "8080",
95
+ folders: {
96
+ distRenderer: "build/renderer",
97
+ distMain: "build/main",
98
+ },
99
+ cspConnectSources: [
100
+ "https://api1.example.com",
101
+ "https://api2.example.com",
102
+ ],
103
+ };
104
+ initSettings(settings);
105
+ const retrieved = getSettings();
106
+ expect(retrieved.localhostPort).toBe("8080");
107
+ expect(retrieved.folders.distRenderer).toBe("build/renderer");
108
+ expect(retrieved.folders.distMain).toBe("build/main");
109
+ expect(retrieved.cspConnectSources).toHaveLength(2);
110
+ });
111
+ });
112
+ describe("type safety", () => {
113
+ it("should require all mandatory fields", () => {
114
+ const settings = {
115
+ localhostPort: "3000",
116
+ folders: {
117
+ distRenderer: "dist-renderer",
118
+ distMain: "dist-main",
119
+ },
120
+ };
121
+ initSettings(settings);
122
+ const retrieved = getSettings();
123
+ expect(retrieved.localhostPort).toBeDefined();
124
+ expect(retrieved.folders).toBeDefined();
125
+ expect(retrieved.folders.distRenderer).toBeDefined();
126
+ expect(retrieved.folders.distMain).toBeDefined();
127
+ });
128
+ it("should handle optional CSP sources", () => {
129
+ const settingsWithoutCSP = {
130
+ localhostPort: "3000",
131
+ folders: {
132
+ distRenderer: "dist-renderer",
133
+ distMain: "dist-main",
134
+ },
135
+ };
136
+ initSettings(settingsWithoutCSP);
137
+ const retrieved = getSettings();
138
+ expect(retrieved.cspConnectSources).toBeUndefined();
139
+ });
140
+ });
141
+ });
@@ -0,0 +1,50 @@
1
+ import { describe, it, expect, beforeEach } from "vitest";
2
+ import { cacheWindows } from "../cache.js";
3
+ describe("cacheWindows", () => {
4
+ beforeEach(() => {
5
+ cacheWindows.clear();
6
+ });
7
+ it("should be a Map instance", () => {
8
+ expect(cacheWindows).toBeInstanceOf(Map);
9
+ });
10
+ it("should store window references", () => {
11
+ const mockWindow = { id: 1 };
12
+ cacheWindows.set("main", mockWindow);
13
+ expect(cacheWindows.get("main")).toBe(mockWindow);
14
+ });
15
+ it("should allow multiple windows", () => {
16
+ const window1 = { id: 1 };
17
+ const window2 = { id: 2 };
18
+ cacheWindows.set("main", window1);
19
+ cacheWindows.set("settings", window2);
20
+ expect(cacheWindows.get("main")).toBe(window1);
21
+ expect(cacheWindows.get("settings")).toBe(window2);
22
+ expect(cacheWindows.size).toBe(2);
23
+ });
24
+ it("should overwrite existing entries", () => {
25
+ const window1 = { id: 1 };
26
+ const window2 = { id: 2 };
27
+ cacheWindows.set("main", window1);
28
+ cacheWindows.set("main", window2);
29
+ expect(cacheWindows.get("main")).toBe(window2);
30
+ expect(cacheWindows.size).toBe(1);
31
+ });
32
+ it("should delete entries", () => {
33
+ const mockWindow = { id: 1 };
34
+ cacheWindows.set("main", mockWindow);
35
+ cacheWindows.delete("main");
36
+ expect(cacheWindows.get("main")).toBeUndefined();
37
+ });
38
+ it("should clear all entries", () => {
39
+ cacheWindows.set("main", { id: 1 });
40
+ cacheWindows.set("settings", { id: 2 });
41
+ cacheWindows.clear();
42
+ expect(cacheWindows.size).toBe(0);
43
+ });
44
+ it("should check if key exists", () => {
45
+ const mockWindow = { id: 1 };
46
+ cacheWindows.set("main", mockWindow);
47
+ expect(cacheWindows.has("main")).toBe(true);
48
+ expect(cacheWindows.has("settings")).toBe(false);
49
+ });
50
+ });
@@ -0,0 +1,69 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+ import { BrowserWindow } from "electron";
3
+ import { destroyWindows } from "../destroy.js";
4
+ describe("destroyWindows", () => {
5
+ beforeEach(() => {
6
+ vi.clearAllMocks();
7
+ });
8
+ it("should destroy all windows", () => {
9
+ const mockWindow1 = {
10
+ isDestroyed: vi.fn(() => false),
11
+ destroy: vi.fn(),
12
+ };
13
+ const mockWindow2 = {
14
+ isDestroyed: vi.fn(() => false),
15
+ destroy: vi.fn(),
16
+ };
17
+ vi.spyOn(BrowserWindow, "getAllWindows").mockReturnValue([
18
+ mockWindow1,
19
+ mockWindow2,
20
+ ]);
21
+ destroyWindows();
22
+ expect(mockWindow1.destroy).toHaveBeenCalledOnce();
23
+ expect(mockWindow2.destroy).toHaveBeenCalledOnce();
24
+ });
25
+ it("should not destroy already destroyed windows", () => {
26
+ const mockWindow1 = {
27
+ isDestroyed: vi.fn(() => true),
28
+ destroy: vi.fn(),
29
+ };
30
+ const mockWindow2 = {
31
+ isDestroyed: vi.fn(() => false),
32
+ destroy: vi.fn(),
33
+ };
34
+ vi.spyOn(BrowserWindow, "getAllWindows").mockReturnValue([
35
+ mockWindow1,
36
+ mockWindow2,
37
+ ]);
38
+ destroyWindows();
39
+ expect(mockWindow1.destroy).not.toHaveBeenCalled();
40
+ expect(mockWindow2.destroy).toHaveBeenCalledOnce();
41
+ });
42
+ it("should handle empty window list", () => {
43
+ vi.spyOn(BrowserWindow, "getAllWindows").mockReturnValue([]);
44
+ expect(() => destroyWindows()).not.toThrow();
45
+ });
46
+ it("should handle single window", () => {
47
+ const mockWindow = {
48
+ isDestroyed: vi.fn(() => false),
49
+ destroy: vi.fn(),
50
+ };
51
+ vi.spyOn(BrowserWindow, "getAllWindows").mockReturnValue([
52
+ mockWindow,
53
+ ]);
54
+ destroyWindows();
55
+ expect(mockWindow.destroy).toHaveBeenCalledOnce();
56
+ });
57
+ it("should check isDestroyed before destroying", () => {
58
+ const mockWindow = {
59
+ isDestroyed: vi.fn(() => false),
60
+ destroy: vi.fn(),
61
+ };
62
+ vi.spyOn(BrowserWindow, "getAllWindows").mockReturnValue([
63
+ mockWindow,
64
+ ]);
65
+ destroyWindows();
66
+ expect(mockWindow.isDestroyed).toHaveBeenCalled();
67
+ expect(mockWindow.destroy).toHaveBeenCalled();
68
+ });
69
+ });
@@ -0,0 +1,68 @@
1
+ import { describe, it, expect, beforeEach } from "vitest";
2
+ import { getWindow } from "../receive.js";
3
+ import { cacheWindows } from "../cache.js";
4
+ describe("getWindow", () => {
5
+ beforeEach(() => {
6
+ cacheWindows.clear();
7
+ });
8
+ it("should return undefined if window not found", () => {
9
+ const result = getWindow("nonexistent");
10
+ expect(result).toBeUndefined();
11
+ });
12
+ it("should return cached window", () => {
13
+ const mockWindow = {
14
+ id: 1,
15
+ isDestroyed: () => false,
16
+ };
17
+ cacheWindows.set("main", mockWindow);
18
+ const result = getWindow("main");
19
+ expect(result).toBe(mockWindow);
20
+ });
21
+ it("should return undefined if window is destroyed", () => {
22
+ const mockWindow = {
23
+ id: 1,
24
+ isDestroyed: () => true,
25
+ };
26
+ cacheWindows.set("main", mockWindow);
27
+ const result = getWindow("main");
28
+ expect(result).toBeUndefined();
29
+ });
30
+ it("should return undefined if cached value is boolean", () => {
31
+ cacheWindows.set("main", true);
32
+ const result = getWindow("main");
33
+ expect(result).toBeUndefined();
34
+ });
35
+ it("should handle different window names", () => {
36
+ const mainWindow = {
37
+ id: 1,
38
+ isDestroyed: () => false,
39
+ };
40
+ const settingsWindow = {
41
+ id: 2,
42
+ isDestroyed: () => false,
43
+ };
44
+ cacheWindows.set("main", mainWindow);
45
+ cacheWindows.set("settings", settingsWindow);
46
+ expect(getWindow("main")).toBe(mainWindow);
47
+ expect(getWindow("settings")).toBe(settingsWindow);
48
+ });
49
+ it("should handle string window names", () => {
50
+ const mockWindow = {
51
+ id: 1,
52
+ isDestroyed: () => false,
53
+ };
54
+ cacheWindows.set("custom-window-name", mockWindow);
55
+ const result = getWindow("custom-window-name");
56
+ expect(result).toBe(mockWindow);
57
+ });
58
+ it("should return undefined after window is removed from cache", () => {
59
+ const mockWindow = {
60
+ id: 1,
61
+ isDestroyed: () => false,
62
+ };
63
+ cacheWindows.set("main", mockWindow);
64
+ cacheWindows.delete("main");
65
+ const result = getWindow("main");
66
+ expect(result).toBeUndefined();
67
+ });
68
+ });
@@ -0,0 +1 @@
1
+ import "reflect-metadata/lite";
@@ -0,0 +1,174 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ import { describe, it, expect } from "vitest";
14
+ import { Inject, getInjectedTokens } from "../inject.js";
15
+ import "reflect-metadata/lite";
16
+ describe("Inject decorator", () => {
17
+ describe("@Inject", () => {
18
+ it("should store injection token for parameter", () => {
19
+ const TOKEN = Symbol("test-token");
20
+ let TestService = class TestService {
21
+ dependency;
22
+ constructor(dependency) {
23
+ this.dependency = dependency;
24
+ }
25
+ };
26
+ TestService = __decorate([
27
+ __param(0, Inject(TOKEN)),
28
+ __metadata("design:paramtypes", [Object])
29
+ ], TestService);
30
+ const tokens = getInjectedTokens(TestService);
31
+ expect(tokens[0]).toBe(TOKEN);
32
+ });
33
+ it("should handle multiple injection tokens", () => {
34
+ const TOKEN1 = Symbol("token-1");
35
+ const TOKEN2 = Symbol("token-2");
36
+ const TOKEN3 = Symbol("token-3");
37
+ let TestService = class TestService {
38
+ dep1;
39
+ dep2;
40
+ dep3;
41
+ constructor(dep1, dep2, dep3) {
42
+ this.dep1 = dep1;
43
+ this.dep2 = dep2;
44
+ this.dep3 = dep3;
45
+ }
46
+ };
47
+ TestService = __decorate([
48
+ __param(0, Inject(TOKEN1)),
49
+ __param(1, Inject(TOKEN2)),
50
+ __param(2, Inject(TOKEN3)),
51
+ __metadata("design:paramtypes", [Object, Object, Object])
52
+ ], TestService);
53
+ const tokens = getInjectedTokens(TestService);
54
+ expect(tokens[0]).toBe(TOKEN1);
55
+ expect(tokens[1]).toBe(TOKEN2);
56
+ expect(tokens[2]).toBe(TOKEN3);
57
+ });
58
+ it("should handle string tokens", () => {
59
+ const TOKEN = "StringToken";
60
+ let TestService = class TestService {
61
+ dependency;
62
+ constructor(dependency) {
63
+ this.dependency = dependency;
64
+ }
65
+ };
66
+ TestService = __decorate([
67
+ __param(0, Inject(TOKEN)),
68
+ __metadata("design:paramtypes", [Object])
69
+ ], TestService);
70
+ const tokens = getInjectedTokens(TestService);
71
+ expect(tokens[0]).toBe(TOKEN);
72
+ });
73
+ it("should handle class constructor tokens", () => {
74
+ class DependencyClass {
75
+ }
76
+ let TestService = class TestService {
77
+ dependency;
78
+ constructor(dependency) {
79
+ this.dependency = dependency;
80
+ }
81
+ };
82
+ TestService = __decorate([
83
+ __param(0, Inject(DependencyClass)),
84
+ __metadata("design:paramtypes", [Object])
85
+ ], TestService);
86
+ const tokens = getInjectedTokens(TestService);
87
+ expect(tokens[0]).toBe(DependencyClass);
88
+ });
89
+ it("should ignore property decorators", () => {
90
+ const TOKEN = Symbol("test-token");
91
+ class TestService {
92
+ // @ts-expect-error - Testing that property decorators are ignored (Inject is a ParameterDecorator)
93
+ property;
94
+ }
95
+ __decorate([
96
+ Inject(TOKEN),
97
+ __metadata("design:type", Object)
98
+ ], TestService.prototype, "property", void 0);
99
+ const tokens = getInjectedTokens(TestService);
100
+ expect(Object.keys(tokens).length).toBe(0);
101
+ });
102
+ it("should handle mixed decorated and non-decorated parameters", () => {
103
+ const TOKEN = Symbol("token");
104
+ class Dependency {
105
+ }
106
+ let TestService = class TestService {
107
+ injected;
108
+ notInjected;
109
+ constructor(injected, notInjected) {
110
+ this.injected = injected;
111
+ this.notInjected = notInjected;
112
+ }
113
+ };
114
+ TestService = __decorate([
115
+ __param(0, Inject(TOKEN)),
116
+ __metadata("design:paramtypes", [Object, Dependency])
117
+ ], TestService);
118
+ const tokens = getInjectedTokens(TestService);
119
+ expect(tokens[0]).toBe(TOKEN);
120
+ });
121
+ it("should preserve parameter indexes correctly", () => {
122
+ const TOKEN1 = Symbol("token-1");
123
+ const TOKEN3 = Symbol("token-3");
124
+ class Dep2 {
125
+ }
126
+ let TestService = class TestService {
127
+ dep1;
128
+ dep2;
129
+ dep3;
130
+ constructor(dep1, dep2, dep3) {
131
+ this.dep1 = dep1;
132
+ this.dep2 = dep2;
133
+ this.dep3 = dep3;
134
+ }
135
+ };
136
+ TestService = __decorate([
137
+ __param(0, Inject(TOKEN1)),
138
+ __param(2, Inject(TOKEN3)),
139
+ __metadata("design:paramtypes", [Object, Dep2, Object])
140
+ ], TestService);
141
+ const tokens = getInjectedTokens(TestService);
142
+ expect(tokens[0]).toBe(TOKEN1);
143
+ expect(tokens[2]).toBe(TOKEN3);
144
+ });
145
+ });
146
+ describe("getInjectedTokens", () => {
147
+ it("should return empty object for class without injections", () => {
148
+ class TestService {
149
+ }
150
+ const tokens = getInjectedTokens(TestService);
151
+ expect(tokens).toEqual({});
152
+ });
153
+ it("should return empty object for class with no constructor", () => {
154
+ class TestService {
155
+ method() { }
156
+ }
157
+ const tokens = getInjectedTokens(TestService);
158
+ expect(tokens).toEqual({});
159
+ });
160
+ it("should return metadata for decorated parameters", () => {
161
+ const TOKEN = Symbol("test");
162
+ let TestService = class TestService {
163
+ constructor(dep) { }
164
+ };
165
+ TestService = __decorate([
166
+ __param(0, Inject(TOKEN)),
167
+ __metadata("design:paramtypes", [Object])
168
+ ], TestService);
169
+ const tokens = getInjectedTokens(TestService);
170
+ expect(Object.keys(tokens).length).toBeGreaterThan(0);
171
+ expect(tokens[0]).toBe(TOKEN);
172
+ });
173
+ });
174
+ });
@@ -0,0 +1 @@
1
+ import "reflect-metadata/lite";
@@ -0,0 +1,73 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { describe, it, expect } from "vitest";
11
+ import { Injectable } from "../injectable.js";
12
+ import "reflect-metadata/lite";
13
+ describe("Injectable decorator", () => {
14
+ it("should mark class as injectable", () => {
15
+ let TestService = class TestService {
16
+ };
17
+ TestService = __decorate([
18
+ Injectable()
19
+ ], TestService);
20
+ const metadata = Reflect.getMetadata("Injectable", TestService);
21
+ expect(metadata).toBe(true);
22
+ });
23
+ it("should work with multiple classes", () => {
24
+ let ServiceA = class ServiceA {
25
+ };
26
+ ServiceA = __decorate([
27
+ Injectable()
28
+ ], ServiceA);
29
+ let ServiceB = class ServiceB {
30
+ };
31
+ ServiceB = __decorate([
32
+ Injectable()
33
+ ], ServiceB);
34
+ expect(Reflect.getMetadata("Injectable", ServiceA)).toBe(true);
35
+ expect(Reflect.getMetadata("Injectable", ServiceB)).toBe(true);
36
+ });
37
+ it("should not affect classes without decorator", () => {
38
+ class NonInjectableService {
39
+ }
40
+ const metadata = Reflect.getMetadata("Injectable", NonInjectableService);
41
+ expect(metadata).toBeUndefined();
42
+ });
43
+ it("should work with class that has constructor parameters", () => {
44
+ let ServiceWithDeps = class ServiceWithDeps {
45
+ dep1;
46
+ dep2;
47
+ constructor(dep1, dep2) {
48
+ this.dep1 = dep1;
49
+ this.dep2 = dep2;
50
+ }
51
+ };
52
+ ServiceWithDeps = __decorate([
53
+ Injectable(),
54
+ __metadata("design:paramtypes", [String, Number])
55
+ ], ServiceWithDeps);
56
+ const metadata = Reflect.getMetadata("Injectable", ServiceWithDeps);
57
+ expect(metadata).toBe(true);
58
+ });
59
+ it("should work with class inheritance", () => {
60
+ let BaseService = class BaseService {
61
+ };
62
+ BaseService = __decorate([
63
+ Injectable()
64
+ ], BaseService);
65
+ let DerivedService = class DerivedService extends BaseService {
66
+ };
67
+ DerivedService = __decorate([
68
+ Injectable()
69
+ ], DerivedService);
70
+ expect(Reflect.getMetadata("Injectable", BaseService)).toBe(true);
71
+ expect(Reflect.getMetadata("Injectable", DerivedService)).toBe(true);
72
+ });
73
+ });
@@ -0,0 +1 @@
1
+ import "reflect-metadata/lite";
@@ -0,0 +1,72 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { describe, it, expect } from "vitest";
11
+ import { IpcHandler } from "../ipc-handler.js";
12
+ import "reflect-metadata/lite";
13
+ describe("IpcHandler decorator", () => {
14
+ it("should mark class as IPC handler", () => {
15
+ let TestHandler = class TestHandler {
16
+ };
17
+ TestHandler = __decorate([
18
+ IpcHandler()
19
+ ], TestHandler);
20
+ const metadata = Reflect.getMetadata("IpcHandler", TestHandler);
21
+ expect(metadata).toBe(true);
22
+ });
23
+ it("should work with multiple handlers", () => {
24
+ let Handler1 = class Handler1 {
25
+ };
26
+ Handler1 = __decorate([
27
+ IpcHandler()
28
+ ], Handler1);
29
+ let Handler2 = class Handler2 {
30
+ };
31
+ Handler2 = __decorate([
32
+ IpcHandler()
33
+ ], Handler2);
34
+ expect(Reflect.getMetadata("IpcHandler", Handler1)).toBe(true);
35
+ expect(Reflect.getMetadata("IpcHandler", Handler2)).toBe(true);
36
+ });
37
+ it("should not affect classes without decorator", () => {
38
+ class NonHandler {
39
+ }
40
+ const metadata = Reflect.getMetadata("IpcHandler", NonHandler);
41
+ expect(metadata).toBeUndefined();
42
+ });
43
+ it("should work with class that has methods", () => {
44
+ let TestHandler = class TestHandler {
45
+ handleEvent() {
46
+ return "handled";
47
+ }
48
+ };
49
+ TestHandler = __decorate([
50
+ IpcHandler()
51
+ ], TestHandler);
52
+ const metadata = Reflect.getMetadata("IpcHandler", TestHandler);
53
+ expect(metadata).toBe(true);
54
+ });
55
+ it("should work with class that has constructor", () => {
56
+ let TestHandler = class TestHandler {
57
+ dependency;
58
+ constructor(dependency) {
59
+ this.dependency = dependency;
60
+ }
61
+ handle() {
62
+ return this.dependency;
63
+ }
64
+ };
65
+ TestHandler = __decorate([
66
+ IpcHandler(),
67
+ __metadata("design:paramtypes", [Object])
68
+ ], TestHandler);
69
+ const metadata = Reflect.getMetadata("IpcHandler", TestHandler);
70
+ expect(metadata).toBe(true);
71
+ });
72
+ });
@@ -0,0 +1 @@
1
+ import "reflect-metadata/lite";