@omnitron-dev/testing 0.4.1 → 0.4.3

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 (154) hide show
  1. package/dist/async/deferred.d.ts +15 -0
  2. package/dist/async/deferred.js +35 -0
  3. package/dist/async/deferred.js.map +1 -0
  4. package/dist/async/events.d.ts +32 -0
  5. package/dist/async/events.js +176 -0
  6. package/dist/async/events.js.map +1 -0
  7. package/dist/async/index.d.ts +5 -0
  8. package/dist/async/index.js +6 -0
  9. package/dist/async/index.js.map +1 -0
  10. package/dist/async/mock-timer.d.ts +19 -0
  11. package/dist/async/mock-timer.js +87 -0
  12. package/dist/async/mock-timer.js.map +1 -0
  13. package/dist/async/retry.d.ts +8 -0
  14. package/dist/async/retry.js +36 -0
  15. package/dist/async/retry.js.map +1 -0
  16. package/dist/async/wait.d.ts +10 -0
  17. package/dist/async/wait.js +35 -0
  18. package/dist/async/wait.js.map +1 -0
  19. package/dist/docker/database-manager.d.ts +22 -0
  20. package/dist/docker/database-manager.js +97 -0
  21. package/dist/docker/database-manager.js.map +1 -0
  22. package/dist/docker/docker-test-manager.d.ts +44 -0
  23. package/dist/docker/docker-test-manager.js +805 -0
  24. package/dist/docker/docker-test-manager.js.map +1 -0
  25. package/dist/docker/index.d.ts +4 -0
  26. package/dist/docker/index.js +4 -0
  27. package/dist/docker/index.js.map +1 -0
  28. package/dist/docker/redis-manager.d.ts +12 -0
  29. package/dist/docker/redis-manager.js +453 -0
  30. package/dist/docker/redis-manager.js.map +1 -0
  31. package/dist/docker/types.d.ts +103 -0
  32. package/dist/docker/types.js +2 -0
  33. package/dist/docker/types.js.map +1 -0
  34. package/dist/errors.d.ts +15 -0
  35. package/dist/errors.js +28 -0
  36. package/dist/errors.js.map +1 -0
  37. package/dist/helpers/assertions.d.ts +6 -0
  38. package/dist/helpers/assertions.js +37 -0
  39. package/dist/helpers/assertions.js.map +1 -0
  40. package/dist/helpers/console.d.ts +1 -0
  41. package/dist/helpers/console.js +23 -0
  42. package/dist/helpers/console.js.map +1 -0
  43. package/dist/helpers/index.d.ts +3 -0
  44. package/dist/helpers/index.js +4 -0
  45. package/dist/helpers/index.js.map +1 -0
  46. package/dist/helpers/temp-dir.d.ts +2 -0
  47. package/dist/helpers/temp-dir.js +13 -0
  48. package/dist/helpers/temp-dir.js.map +1 -0
  49. package/dist/index.d.ts +2 -0
  50. package/dist/index.js +2 -0
  51. package/dist/index.js.map +1 -1
  52. package/dist/performance/index.d.ts +2 -0
  53. package/dist/performance/index.js +3 -0
  54. package/dist/performance/index.js.map +1 -0
  55. package/dist/performance/memory-detector.d.ts +9 -0
  56. package/dist/performance/memory-detector.js +61 -0
  57. package/dist/performance/memory-detector.js.map +1 -0
  58. package/dist/performance/perf-timer.d.ts +9 -0
  59. package/dist/performance/perf-timer.js +49 -0
  60. package/dist/performance/perf-timer.js.map +1 -0
  61. package/dist/titan/container-utils.d.ts +20 -0
  62. package/dist/titan/container-utils.js +78 -0
  63. package/dist/titan/container-utils.js.map +1 -0
  64. package/dist/titan/database/database-testing.module.d.ts +81 -0
  65. package/dist/titan/database/database-testing.module.js +419 -0
  66. package/dist/titan/database/database-testing.module.js.map +1 -0
  67. package/dist/titan/database/index.d.ts +3 -0
  68. package/dist/titan/database/index.js +4 -0
  69. package/dist/titan/database/index.js.map +1 -0
  70. package/dist/titan/database/test-utilities.d.ts +31 -0
  71. package/dist/titan/database/test-utilities.js +145 -0
  72. package/dist/titan/database/test-utilities.js.map +1 -0
  73. package/dist/titan/index.d.ts +14 -0
  74. package/dist/titan/index.js +10 -0
  75. package/dist/titan/index.js.map +1 -0
  76. package/dist/titan/nexus/index.d.ts +3 -0
  77. package/dist/titan/nexus/index.js +4 -0
  78. package/dist/titan/nexus/index.js.map +1 -0
  79. package/dist/titan/nexus/mock-provider.d.ts +41 -0
  80. package/dist/titan/nexus/mock-provider.js +127 -0
  81. package/dist/titan/nexus/mock-provider.js.map +1 -0
  82. package/dist/titan/nexus/test-container.d.ts +120 -0
  83. package/dist/titan/nexus/test-container.js +559 -0
  84. package/dist/titan/nexus/test-container.js.map +1 -0
  85. package/dist/titan/nexus/test-utilities.d.ts +135 -0
  86. package/dist/titan/nexus/test-utilities.js +484 -0
  87. package/dist/titan/nexus/test-utilities.js.map +1 -0
  88. package/dist/titan/pm/index.d.ts +4 -0
  89. package/dist/titan/pm/index.js +4 -0
  90. package/dist/titan/pm/index.js.map +1 -0
  91. package/dist/titan/pm/mock-process-spawner.d.ts +60 -0
  92. package/dist/titan/pm/mock-process-spawner.js +321 -0
  93. package/dist/titan/pm/mock-process-spawner.js.map +1 -0
  94. package/dist/titan/pm/mock-spawner.d.ts +27 -0
  95. package/dist/titan/pm/mock-spawner.js +99 -0
  96. package/dist/titan/pm/mock-spawner.js.map +1 -0
  97. package/dist/titan/pm/test-process-manager.d.ts +49 -0
  98. package/dist/titan/pm/test-process-manager.js +188 -0
  99. package/dist/titan/pm/test-process-manager.js.map +1 -0
  100. package/dist/titan/redis-test-utils.d.ts +33 -0
  101. package/dist/titan/redis-test-utils.js +414 -0
  102. package/dist/titan/redis-test-utils.js.map +1 -0
  103. package/dist/titan/test-application.d.ts +21 -0
  104. package/dist/titan/test-application.js +90 -0
  105. package/dist/titan/test-application.js.map +1 -0
  106. package/dist/titan/test-fixtures.d.ts +97 -0
  107. package/dist/titan/test-fixtures.js +223 -0
  108. package/dist/titan/test-fixtures.js.map +1 -0
  109. package/dist/titan/test-mocks.d.ts +29 -0
  110. package/dist/titan/test-mocks.js +262 -0
  111. package/dist/titan/test-mocks.js.map +1 -0
  112. package/dist/titan/test-module.d.ts +46 -0
  113. package/dist/titan/test-module.js +120 -0
  114. package/dist/titan/test-module.js.map +1 -0
  115. package/package.json +41 -4
  116. package/src/async/README.md +336 -0
  117. package/src/async/deferred.ts +98 -0
  118. package/src/async/events.ts +386 -0
  119. package/src/async/index.ts +48 -0
  120. package/src/async/mock-timer.ts +220 -0
  121. package/src/async/retry.ts +118 -0
  122. package/src/async/wait.ts +151 -0
  123. package/src/docker/database-manager.ts +242 -0
  124. package/src/docker/docker-test-manager.ts +1186 -0
  125. package/src/docker/index.ts +48 -0
  126. package/src/docker/redis-manager.ts +738 -0
  127. package/src/docker/types.ts +216 -0
  128. package/src/errors.ts +31 -0
  129. package/src/helpers/assertions.ts +171 -0
  130. package/src/helpers/console.ts +74 -0
  131. package/src/helpers/index.ts +15 -0
  132. package/src/helpers/temp-dir.ts +50 -0
  133. package/src/index.ts +2 -0
  134. package/src/performance/index.ts +11 -0
  135. package/src/performance/memory-detector.ts +166 -0
  136. package/src/performance/perf-timer.ts +146 -0
  137. package/src/titan/container-utils.ts +128 -0
  138. package/src/titan/database/database-testing.module.ts +831 -0
  139. package/src/titan/database/index.ts +30 -0
  140. package/src/titan/database/test-utilities.ts +337 -0
  141. package/src/titan/index.ts +147 -0
  142. package/src/titan/nexus/index.ts +3 -0
  143. package/src/titan/nexus/mock-provider.ts +189 -0
  144. package/src/titan/nexus/test-container.ts +887 -0
  145. package/src/titan/nexus/test-utilities.ts +796 -0
  146. package/src/titan/pm/index.ts +22 -0
  147. package/src/titan/pm/mock-process-spawner.ts +481 -0
  148. package/src/titan/pm/mock-spawner.ts +156 -0
  149. package/src/titan/pm/test-process-manager.ts +345 -0
  150. package/src/titan/redis-test-utils.ts +566 -0
  151. package/src/titan/test-application.ts +154 -0
  152. package/src/titan/test-fixtures.ts +304 -0
  153. package/src/titan/test-mocks.ts +336 -0
  154. package/src/titan/test-module.ts +232 -0
@@ -0,0 +1,232 @@
1
+ import { IModule, ProviderDefinition, InjectionToken } from '@omnitron-dev/titan/nexus';
2
+ import { Application, IApplicationConfig } from '@omnitron-dev/titan';
3
+
4
+ // Import TestContainer from local nexus testing utilities (now in this package)
5
+ import { TestContainer, createTestContainer } from './nexus/test-container.js';
6
+
7
+ /**
8
+ * Options for creating a test module
9
+ */
10
+ export interface TestModuleOptions {
11
+ modules?: IModule[];
12
+ providers?: Array<[InjectionToken<any>, ProviderDefinition<any>]>;
13
+ mocks?: Array<{
14
+ token: InjectionToken<any>;
15
+ mock: any;
16
+ spy?: boolean;
17
+ }>;
18
+ config?: Partial<IApplicationConfig>;
19
+ autoMock?: boolean;
20
+ }
21
+
22
+ /**
23
+ * Test module for Titan applications
24
+ */
25
+ export class TestModule {
26
+ private container: TestContainer;
27
+ private app?: Application;
28
+
29
+ constructor(private options: TestModuleOptions = {}) {
30
+ this.container = createTestContainer({
31
+ modules: options.modules || [],
32
+ providers: options.providers || [],
33
+ mocks: options.mocks || [],
34
+ autoMock: options.autoMock || false,
35
+ });
36
+ }
37
+
38
+ /**
39
+ * Get the test container
40
+ */
41
+ getContainer(): TestContainer {
42
+ return this.container;
43
+ }
44
+
45
+ /**
46
+ * Create an application instance for testing
47
+ */
48
+ async createApplication(): Promise<Application> {
49
+ if (this.app) {
50
+ return this.app;
51
+ }
52
+
53
+ const config: IApplicationConfig = {
54
+ name: 'test-app',
55
+ version: '0.0.0-test',
56
+ ...this.options.config,
57
+ };
58
+
59
+ this.app = new Application(config);
60
+
61
+ // Use the test container for dependency injection
62
+ (this.app as any).container = this.container;
63
+
64
+ // Load modules if provided
65
+ if (this.options.modules) {
66
+ for (const module of this.options.modules) {
67
+ this.container.loadModule(module);
68
+ }
69
+ }
70
+
71
+ return this.app;
72
+ }
73
+
74
+ /**
75
+ * Mock a dependency
76
+ */
77
+ mock<T>(token: InjectionToken<T>, mock: T, spy = false): this {
78
+ this.container.mock(token, mock, spy);
79
+ return this;
80
+ }
81
+
82
+ /**
83
+ * Stub a dependency with partial implementation
84
+ */
85
+ stub<T>(token: InjectionToken<T>, stub: Partial<T>): this {
86
+ this.container.stub(token, stub);
87
+ return this;
88
+ }
89
+
90
+ /**
91
+ * Override a dependency
92
+ */
93
+ override<T>(token: InjectionToken<T>): {
94
+ useValue: (value: T) => TestModule;
95
+ useClass: (cls: new (...args: any[]) => T) => TestModule;
96
+ useFactory: (factory: (...args: any[]) => T) => TestModule;
97
+ } {
98
+ return {
99
+ useValue: (value: T) => {
100
+ this.container.override(token).useValue(value);
101
+ return this;
102
+ },
103
+ useClass: (cls: new (...args: any[]) => T) => {
104
+ this.container.override(token).useClass(cls);
105
+ return this;
106
+ },
107
+ useFactory: (factory: (...args: any[]) => T) => {
108
+ this.container.override(token).useFactory(factory);
109
+ return this;
110
+ },
111
+ };
112
+ }
113
+
114
+ /**
115
+ * Spy on a method
116
+ */
117
+ spy<T>(token: InjectionToken<T>, method: keyof T): any {
118
+ return this.container.spy(token, method);
119
+ }
120
+
121
+ /**
122
+ * Get a service from the container
123
+ */
124
+ get<T>(token: InjectionToken<T>): T {
125
+ return this.container.resolve(token);
126
+ }
127
+
128
+ /**
129
+ * Reset all mocks
130
+ */
131
+ resetMocks(): void {
132
+ this.container.resetMocks();
133
+ }
134
+
135
+ /**
136
+ * Clear all mocks
137
+ */
138
+ clearMocks(): void {
139
+ this.container.clearMocks();
140
+ }
141
+
142
+ /**
143
+ * Restore to original state
144
+ */
145
+ restore(): void {
146
+ this.container.restore();
147
+ }
148
+
149
+ /**
150
+ * Clean up resources
151
+ */
152
+ async cleanup(): Promise<void> {
153
+ if (this.app) {
154
+ await this.app.stop();
155
+ this.app = undefined;
156
+ }
157
+ this.container.restore();
158
+ }
159
+ }
160
+
161
+ /**
162
+ * Create a test module
163
+ */
164
+ export function createTestModule(options: TestModuleOptions = {}): TestModule {
165
+ return new TestModule(options);
166
+ }
167
+
168
+ /**
169
+ * Test module builder for fluent API
170
+ */
171
+ export class TestModuleBuilder {
172
+ private options: TestModuleOptions = {
173
+ modules: [],
174
+ providers: [],
175
+ mocks: [],
176
+ config: {},
177
+ };
178
+
179
+ /**
180
+ * Add a module to test
181
+ */
182
+ withModule(module: IModule): this {
183
+ this.options.modules!.push(module);
184
+ return this;
185
+ }
186
+
187
+ /**
188
+ * Add a provider
189
+ */
190
+ withProvider<T>(token: InjectionToken<T>, provider: ProviderDefinition<T>): this {
191
+ this.options.providers!.push([token, provider]);
192
+ return this;
193
+ }
194
+
195
+ /**
196
+ * Add a mock
197
+ */
198
+ withMock<T>(token: InjectionToken<T>, mock: T, spy = false): this {
199
+ this.options.mocks!.push({ token, mock, spy });
200
+ return this;
201
+ }
202
+
203
+ /**
204
+ * Set application config
205
+ */
206
+ withConfig(config: Partial<IApplicationConfig>): this {
207
+ this.options.config = { ...this.options.config, ...config };
208
+ return this;
209
+ }
210
+
211
+ /**
212
+ * Enable auto-mocking
213
+ */
214
+ withAutoMock(): this {
215
+ this.options.autoMock = true;
216
+ return this;
217
+ }
218
+
219
+ /**
220
+ * Build the test module
221
+ */
222
+ build(): TestModule {
223
+ return new TestModule(this.options);
224
+ }
225
+ }
226
+
227
+ /**
228
+ * Create a test module builder
229
+ */
230
+ export function testModule(): TestModuleBuilder {
231
+ return new TestModuleBuilder();
232
+ }