@omnitron-dev/testing 0.1.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.
Files changed (182) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +19 -0
  3. package/dist/async/deferred.d.ts +15 -0
  4. package/dist/async/deferred.js +35 -0
  5. package/dist/async/deferred.js.map +1 -0
  6. package/dist/async/events.d.ts +32 -0
  7. package/dist/async/events.js +176 -0
  8. package/dist/async/events.js.map +1 -0
  9. package/dist/async/index.d.ts +5 -0
  10. package/dist/async/index.js +6 -0
  11. package/dist/async/index.js.map +1 -0
  12. package/dist/async/mock-timer.d.ts +19 -0
  13. package/dist/async/mock-timer.js +87 -0
  14. package/dist/async/mock-timer.js.map +1 -0
  15. package/dist/async/retry.d.ts +8 -0
  16. package/dist/async/retry.js +36 -0
  17. package/dist/async/retry.js.map +1 -0
  18. package/dist/async/wait.d.ts +10 -0
  19. package/dist/async/wait.js +35 -0
  20. package/dist/async/wait.js.map +1 -0
  21. package/dist/docker/database-manager.d.ts +22 -0
  22. package/dist/docker/database-manager.js +97 -0
  23. package/dist/docker/database-manager.js.map +1 -0
  24. package/dist/docker/docker-test-manager.d.ts +44 -0
  25. package/dist/docker/docker-test-manager.js +812 -0
  26. package/dist/docker/docker-test-manager.js.map +1 -0
  27. package/dist/docker/index.d.ts +4 -0
  28. package/dist/docker/index.js +4 -0
  29. package/dist/docker/index.js.map +1 -0
  30. package/dist/docker/redis-manager.d.ts +12 -0
  31. package/dist/docker/redis-manager.js +452 -0
  32. package/dist/docker/redis-manager.js.map +1 -0
  33. package/dist/docker/types.d.ts +103 -0
  34. package/dist/docker/types.js +2 -0
  35. package/dist/docker/types.js.map +1 -0
  36. package/dist/errors.d.ts +15 -0
  37. package/dist/errors.js +28 -0
  38. package/dist/errors.js.map +1 -0
  39. package/dist/helpers/assertions.d.ts +6 -0
  40. package/dist/helpers/assertions.js +37 -0
  41. package/dist/helpers/assertions.js.map +1 -0
  42. package/dist/helpers/console.d.ts +1 -0
  43. package/dist/helpers/console.js +23 -0
  44. package/dist/helpers/console.js.map +1 -0
  45. package/dist/helpers/index.d.ts +3 -0
  46. package/dist/helpers/index.js +4 -0
  47. package/dist/helpers/index.js.map +1 -0
  48. package/dist/helpers/temp-dir.d.ts +2 -0
  49. package/dist/helpers/temp-dir.js +13 -0
  50. package/dist/helpers/temp-dir.js.map +1 -0
  51. package/dist/index.d.ts +18 -0
  52. package/dist/index.js +22 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/performance/index.d.ts +2 -0
  55. package/dist/performance/index.js +3 -0
  56. package/dist/performance/index.js.map +1 -0
  57. package/dist/performance/memory-detector.d.ts +9 -0
  58. package/dist/performance/memory-detector.js +61 -0
  59. package/dist/performance/memory-detector.js.map +1 -0
  60. package/dist/performance/perf-timer.d.ts +9 -0
  61. package/dist/performance/perf-timer.js +49 -0
  62. package/dist/performance/perf-timer.js.map +1 -0
  63. package/dist/runtime/bun-adapter.d.ts +1 -0
  64. package/dist/runtime/bun-adapter.js +100 -0
  65. package/dist/runtime/bun-adapter.js.map +1 -0
  66. package/dist/runtime/deno-adapter.d.ts +27 -0
  67. package/dist/runtime/deno-adapter.js +221 -0
  68. package/dist/runtime/deno-adapter.js.map +1 -0
  69. package/dist/runtime/node-adapter.d.ts +16 -0
  70. package/dist/runtime/node-adapter.js +30 -0
  71. package/dist/runtime/node-adapter.js.map +1 -0
  72. package/dist/runtime/test-adapter.d.ts +22 -0
  73. package/dist/runtime/test-adapter.js +93 -0
  74. package/dist/runtime/test-adapter.js.map +1 -0
  75. package/dist/titan/container-utils.d.ts +20 -0
  76. package/dist/titan/container-utils.js +78 -0
  77. package/dist/titan/container-utils.js.map +1 -0
  78. package/dist/titan/database/database-testing.module.d.ts +82 -0
  79. package/dist/titan/database/database-testing.module.js +433 -0
  80. package/dist/titan/database/database-testing.module.js.map +1 -0
  81. package/dist/titan/database/index.d.ts +3 -0
  82. package/dist/titan/database/index.js +4 -0
  83. package/dist/titan/database/index.js.map +1 -0
  84. package/dist/titan/database/test-utilities.d.ts +31 -0
  85. package/dist/titan/database/test-utilities.js +146 -0
  86. package/dist/titan/database/test-utilities.js.map +1 -0
  87. package/dist/titan/index.d.ts +14 -0
  88. package/dist/titan/index.js +10 -0
  89. package/dist/titan/index.js.map +1 -0
  90. package/dist/titan/nexus/index.d.ts +3 -0
  91. package/dist/titan/nexus/index.js +4 -0
  92. package/dist/titan/nexus/index.js.map +1 -0
  93. package/dist/titan/nexus/mock-provider.d.ts +41 -0
  94. package/dist/titan/nexus/mock-provider.js +127 -0
  95. package/dist/titan/nexus/mock-provider.js.map +1 -0
  96. package/dist/titan/nexus/test-container.d.ts +120 -0
  97. package/dist/titan/nexus/test-container.js +559 -0
  98. package/dist/titan/nexus/test-container.js.map +1 -0
  99. package/dist/titan/nexus/test-utilities.d.ts +135 -0
  100. package/dist/titan/nexus/test-utilities.js +484 -0
  101. package/dist/titan/nexus/test-utilities.js.map +1 -0
  102. package/dist/titan/pm/index.d.ts +4 -0
  103. package/dist/titan/pm/index.js +4 -0
  104. package/dist/titan/pm/index.js.map +1 -0
  105. package/dist/titan/pm/mock-process-spawner.d.ts +61 -0
  106. package/dist/titan/pm/mock-process-spawner.js +343 -0
  107. package/dist/titan/pm/mock-process-spawner.js.map +1 -0
  108. package/dist/titan/pm/mock-spawner.d.ts +28 -0
  109. package/dist/titan/pm/mock-spawner.js +101 -0
  110. package/dist/titan/pm/mock-spawner.js.map +1 -0
  111. package/dist/titan/pm/test-process-manager.d.ts +49 -0
  112. package/dist/titan/pm/test-process-manager.js +192 -0
  113. package/dist/titan/pm/test-process-manager.js.map +1 -0
  114. package/dist/titan/redis-test-utils.d.ts +33 -0
  115. package/dist/titan/redis-test-utils.js +415 -0
  116. package/dist/titan/redis-test-utils.js.map +1 -0
  117. package/dist/titan/test-application.d.ts +21 -0
  118. package/dist/titan/test-application.js +90 -0
  119. package/dist/titan/test-application.js.map +1 -0
  120. package/dist/titan/test-fixtures.d.ts +97 -0
  121. package/dist/titan/test-fixtures.js +223 -0
  122. package/dist/titan/test-fixtures.js.map +1 -0
  123. package/dist/titan/test-mocks.d.ts +30 -0
  124. package/dist/titan/test-mocks.js +262 -0
  125. package/dist/titan/test-mocks.js.map +1 -0
  126. package/dist/titan/test-module.d.ts +47 -0
  127. package/dist/titan/test-module.js +120 -0
  128. package/dist/titan/test-module.js.map +1 -0
  129. package/package.json +146 -0
  130. package/runtime/bun.d.ts +2 -0
  131. package/runtime/bun.js +5 -0
  132. package/runtime/bun.ts +7 -0
  133. package/runtime/deno.d.ts +2 -0
  134. package/runtime/deno.js +4 -0
  135. package/runtime/vitest.d.ts +2 -0
  136. package/runtime/vitest.js +16 -0
  137. package/runtime/vitest.ts +7 -0
  138. package/src/async/README.md +336 -0
  139. package/src/async/deferred.ts +98 -0
  140. package/src/async/events.ts +386 -0
  141. package/src/async/index.ts +23 -0
  142. package/src/async/mock-timer.ts +220 -0
  143. package/src/async/retry.ts +115 -0
  144. package/src/async/wait.ts +148 -0
  145. package/src/docker/database-manager.ts +242 -0
  146. package/src/docker/docker-test-manager.ts +1198 -0
  147. package/src/docker/index.ts +48 -0
  148. package/src/docker/redis-manager.ts +741 -0
  149. package/src/docker/types.ts +216 -0
  150. package/src/errors.ts +38 -0
  151. package/src/globals.d.ts +24 -0
  152. package/src/helpers/assertions.ts +168 -0
  153. package/src/helpers/console.ts +74 -0
  154. package/src/helpers/index.ts +15 -0
  155. package/src/helpers/temp-dir.ts +50 -0
  156. package/src/index.ts +43 -0
  157. package/src/performance/index.ts +11 -0
  158. package/src/performance/memory-detector.ts +166 -0
  159. package/src/performance/perf-timer.ts +146 -0
  160. package/src/runtime/bun-adapter.ts +127 -0
  161. package/src/runtime/deno-adapter.ts +286 -0
  162. package/src/runtime/node-adapter.ts +40 -0
  163. package/src/runtime/test-adapter.test.ts +98 -0
  164. package/src/runtime/test-adapter.ts +122 -0
  165. package/src/titan/container-utils.ts +128 -0
  166. package/src/titan/database/database-testing.module.ts +851 -0
  167. package/src/titan/database/index.ts +30 -0
  168. package/src/titan/database/test-utilities.ts +340 -0
  169. package/src/titan/index.ts +128 -0
  170. package/src/titan/nexus/index.ts +3 -0
  171. package/src/titan/nexus/mock-provider.ts +189 -0
  172. package/src/titan/nexus/test-container.ts +895 -0
  173. package/src/titan/nexus/test-utilities.ts +797 -0
  174. package/src/titan/pm/index.ts +22 -0
  175. package/src/titan/pm/mock-process-spawner.ts +534 -0
  176. package/src/titan/pm/mock-spawner.ts +162 -0
  177. package/src/titan/pm/test-process-manager.ts +352 -0
  178. package/src/titan/redis-test-utils.ts +567 -0
  179. package/src/titan/test-application.ts +154 -0
  180. package/src/titan/test-fixtures.ts +304 -0
  181. package/src/titan/test-mocks.ts +336 -0
  182. package/src/titan/test-module.ts +233 -0
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Database Testing Utilities
3
+ *
4
+ * Comprehensive utilities for testing database operations with support for:
5
+ * - Automatic transaction rollback
6
+ * - Test data seeding
7
+ * - Database cleanup strategies
8
+ * - Docker-based real database testing
9
+ * - SQLite in-memory fallback
10
+ */
11
+
12
+ export {
13
+ DatabaseTestingModule,
14
+ DatabaseTestingService,
15
+ type DatabaseTestingOptions,
16
+ } from './database-testing.module.js';
17
+
18
+ export {
19
+ createTestDatabase,
20
+ withTestDatabase,
21
+ createTestDatabaseConfigs,
22
+ cleanupTestDatabaseConfigs,
23
+ getRecommendedTestDatabase,
24
+ isDockerAvailable,
25
+ type DatabaseTestOptions,
26
+ type DatabaseTestContext,
27
+ } from './test-utilities.js';
28
+
29
+ // Re-export DATABASE_TESTING_SERVICE from the testing module
30
+ export { DATABASE_TESTING_SERVICE } from './database-testing.module.js';
@@ -0,0 +1,340 @@
1
+ /**
2
+ * Database Testing Utilities
3
+ *
4
+ * Provides utilities for testing database operations with real databases in Docker containers
5
+ * Falls back to SQLite when Docker is not available
6
+ */
7
+
8
+ import { DockerTestManager, DatabaseTestManager, type DockerContainer } from '@omnitron-dev/testing/docker';
9
+ import type { DatabaseModuleOptions } from '@omnitron-dev/titan-database';
10
+
11
+ export interface DatabaseTestOptions {
12
+ /**
13
+ * Preferred database dialect to use for testing
14
+ * If Docker is available, will start a container with this database
15
+ * If Docker is not available, falls back to SQLite in-memory
16
+ */
17
+ dialect?: 'postgres' | 'mysql' | 'mariadb' | 'sqlite';
18
+
19
+ /**
20
+ * Database name
21
+ */
22
+ database?: string;
23
+
24
+ /**
25
+ * Database user
26
+ */
27
+ user?: string;
28
+
29
+ /**
30
+ * Database password
31
+ */
32
+ password?: string;
33
+
34
+ /**
35
+ * Custom Docker path
36
+ */
37
+ dockerPath?: string;
38
+
39
+ /**
40
+ * Force SQLite even if Docker is available
41
+ */
42
+ forceSqlite?: boolean;
43
+
44
+ /**
45
+ * Verbose logging
46
+ */
47
+ verbose?: boolean;
48
+
49
+ /**
50
+ * Custom port (or 'auto' for automatic port allocation)
51
+ */
52
+ port?: number | 'auto';
53
+ }
54
+
55
+ export interface DatabaseTestContext {
56
+ /**
57
+ * Database connection configuration
58
+ */
59
+ connection: DatabaseModuleOptions['connection'];
60
+
61
+ /**
62
+ * Dialect being used
63
+ */
64
+ dialect: 'postgres' | 'mysql' | 'mariadb' | 'sqlite';
65
+
66
+ /**
67
+ * Docker container (if using Docker)
68
+ */
69
+ container?: DockerContainer;
70
+
71
+ /**
72
+ * Cleanup function to stop container and release resources
73
+ */
74
+ cleanup: () => Promise<void>;
75
+
76
+ /**
77
+ * Whether Docker is being used
78
+ */
79
+ isDocker: boolean;
80
+ }
81
+
82
+ /**
83
+ * Check if Docker is available
84
+ */
85
+ export function isDockerAvailable(dockerPath?: string): boolean {
86
+ try {
87
+ DockerTestManager.getInstance({ dockerPath });
88
+ return true;
89
+ } catch {
90
+ return false;
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Create a test database context with automatic Docker detection
96
+ *
97
+ * This function will:
98
+ * 1. Check if Docker is available
99
+ * 2. If Docker is available and not forceSqlite, start a database container
100
+ * 3. If Docker is not available or forceSqlite is true, use in-memory SQLite
101
+ * 4. Return a context object with connection config and cleanup function
102
+ */
103
+ export async function createTestDatabase(options: DatabaseTestOptions = {}): Promise<DatabaseTestContext> {
104
+ const {
105
+ dialect = 'postgres',
106
+ database = 'testdb',
107
+ user = 'testuser',
108
+ password = 'testpass',
109
+ dockerPath,
110
+ forceSqlite = false,
111
+ verbose = false,
112
+ port = 'auto',
113
+ } = options;
114
+
115
+ // Check if Docker is available
116
+ const dockerAvailable = !forceSqlite && isDockerAvailable(dockerPath);
117
+
118
+ if (dockerAvailable) {
119
+ try {
120
+ if (verbose) {
121
+ console.log(`Starting ${dialect} container for testing...`);
122
+ }
123
+
124
+ let container: DockerContainer;
125
+ let connectionConfig: DatabaseModuleOptions['connection'];
126
+
127
+ switch (dialect) {
128
+ case 'postgres':
129
+ container = await DatabaseTestManager.createPostgresContainer({
130
+ port,
131
+ database,
132
+ user,
133
+ password,
134
+ });
135
+ connectionConfig = {
136
+ dialect: 'postgres',
137
+ connection: {
138
+ host: container.host,
139
+ port: container.ports.get(5432)!,
140
+ database,
141
+ user,
142
+ password,
143
+ },
144
+ pool: {
145
+ acquireTimeoutMillis: 5000,
146
+ idleTimeoutMillis: 10000,
147
+ max: 10,
148
+ },
149
+ };
150
+ break;
151
+
152
+ case 'mysql':
153
+ case 'mariadb':
154
+ container = await DatabaseTestManager.createMySQLContainer({
155
+ port,
156
+ database,
157
+ user,
158
+ password,
159
+ });
160
+ connectionConfig = {
161
+ dialect: 'mysql',
162
+ connection: {
163
+ host: container.host,
164
+ port: container.ports.get(3306)!,
165
+ database,
166
+ user,
167
+ password,
168
+ },
169
+ pool: {
170
+ max: 10,
171
+ acquireTimeoutMillis: 5000,
172
+ },
173
+ };
174
+ break;
175
+
176
+ default:
177
+ throw new Error(`Unsupported dialect for Docker: ${dialect}`);
178
+ }
179
+
180
+ if (verbose) {
181
+ console.log(`${dialect} container started on port ${container.port}`);
182
+ }
183
+
184
+ return {
185
+ connection: connectionConfig,
186
+ dialect,
187
+ container,
188
+ isDocker: true,
189
+ cleanup: async () => {
190
+ if (verbose) {
191
+ console.log(`Stopping ${dialect} container...`);
192
+ }
193
+ await container.cleanup();
194
+ },
195
+ };
196
+ } catch (error) {
197
+ console.warn(`Failed to start Docker container, falling back to SQLite: ${error}`);
198
+ // Fall through to SQLite fallback
199
+ }
200
+ }
201
+
202
+ // Fallback to SQLite
203
+ if (verbose && !forceSqlite) {
204
+ console.log('Docker not available, using in-memory SQLite for testing');
205
+ } else if (verbose) {
206
+ console.log('Using in-memory SQLite for testing (forced)');
207
+ }
208
+
209
+ // Create unique in-memory database for each test to avoid conflicts
210
+ const uniqueId = `test_${Date.now()}_${Math.random().toString(36).substring(7)}`;
211
+
212
+ return {
213
+ connection: {
214
+ dialect: 'sqlite',
215
+ connection: `file:${uniqueId}?mode=memory&cache=shared`,
216
+ },
217
+ dialect: 'sqlite',
218
+ isDocker: false,
219
+ cleanup: async () => {
220
+ // No cleanup needed for in-memory SQLite
221
+ },
222
+ };
223
+ }
224
+
225
+ /**
226
+ * Helper function to run tests with a specific database
227
+ *
228
+ * @example
229
+ * ```typescript
230
+ * await withTestDatabase({ dialect: 'postgres' }, async (context) => {
231
+ * const app = await Application.create(MyModule, {
232
+ * config: {
233
+ * database: context.connection,
234
+ * },
235
+ * });
236
+ *
237
+ * // Run tests...
238
+ *
239
+ * await app.stop();
240
+ * });
241
+ * ```
242
+ */
243
+ export async function withTestDatabase<T>(
244
+ options: DatabaseTestOptions,
245
+ testFn: (context: DatabaseTestContext) => Promise<T>
246
+ ): Promise<T> {
247
+ const context = await createTestDatabase(options);
248
+
249
+ try {
250
+ return await testFn(context);
251
+ } finally {
252
+ await context.cleanup();
253
+ }
254
+ }
255
+
256
+ /**
257
+ * Create test database configuration for multiple dialects
258
+ *
259
+ * This is useful for parameterized tests that run against multiple database types
260
+ *
261
+ * @example
262
+ * ```typescript
263
+ * const configs = await createTestDatabaseConfigs(['postgres', 'mysql', 'sqlite']);
264
+ *
265
+ * describe.each(configs)('Database Tests - $dialect', ({ dialect, context, cleanup }) => {
266
+ * afterAll(async () => {
267
+ * await cleanup();
268
+ * });
269
+ *
270
+ * it('should work with ' + dialect, async () => {
271
+ * // Test code using context.connection
272
+ * });
273
+ * });
274
+ * ```
275
+ */
276
+ export async function createTestDatabaseConfigs(
277
+ dialects: Array<'postgres' | 'mysql' | 'mariadb' | 'sqlite'>,
278
+ options: Omit<DatabaseTestOptions, 'dialect'> = {}
279
+ ): Promise<
280
+ Array<{
281
+ dialect: string;
282
+ context: DatabaseTestContext;
283
+ cleanup: () => Promise<void>;
284
+ }>
285
+ > {
286
+ const configs: Array<{
287
+ dialect: string;
288
+ context: DatabaseTestContext;
289
+ cleanup: () => Promise<void>;
290
+ }> = [];
291
+
292
+ for (const dialect of dialects) {
293
+ const context = await createTestDatabase({
294
+ ...options,
295
+ dialect,
296
+ });
297
+
298
+ configs.push({
299
+ dialect,
300
+ context,
301
+ cleanup: context.cleanup,
302
+ });
303
+ }
304
+
305
+ return configs;
306
+ }
307
+
308
+ /**
309
+ * Cleanup all test database contexts
310
+ */
311
+ export async function cleanupTestDatabaseConfigs(
312
+ configs: Array<{
313
+ cleanup: () => Promise<void>;
314
+ }>
315
+ ): Promise<void> {
316
+ await Promise.all(configs.map((config) => config.cleanup()));
317
+ }
318
+
319
+ /**
320
+ * Get recommended database for CI/CD environment
321
+ *
322
+ * Returns the best database to use based on the environment:
323
+ * - CI environments: SQLite (fast, no dependencies)
324
+ * - Local development with Docker: PostgreSQL
325
+ * - Local development without Docker: SQLite
326
+ */
327
+ export async function getRecommendedTestDatabase(options: DatabaseTestOptions = {}): Promise<DatabaseTestContext> {
328
+ const isCI = process.env['CI'] === 'true' || process.env['GITHUB_ACTIONS'] === 'true';
329
+
330
+ if (isCI) {
331
+ // Use SQLite in CI for speed and simplicity
332
+ return createTestDatabase({
333
+ ...options,
334
+ forceSqlite: true,
335
+ });
336
+ }
337
+
338
+ // Use preferred dialect with automatic fallback
339
+ return createTestDatabase(options);
340
+ }
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Titan Testing Utilities
3
+ *
4
+ * Re-exports all Titan-specific testing utilities
5
+ */
6
+
7
+ // Test Module
8
+ export { TestModule, TestModuleBuilder, createTestModule, testModule } from './test-module.js';
9
+ export type { TestModuleOptions } from './test-module.js';
10
+
11
+ // Test Application
12
+ export { TestApplication } from './test-application.js';
13
+
14
+ // Test Fixtures
15
+ export { TestSchemas, TestConfigs, TestRedisConfigs, TestModules, TestData, TestTiming } from './test-fixtures.js';
16
+
17
+ // Test Mocks
18
+ export {
19
+ createMockLogger,
20
+ createMockConfigService,
21
+ createMockRedisManager,
22
+ createMockRedisClient,
23
+ createMockSchedulerService,
24
+ createMockEventBus,
25
+ } from './test-mocks.js';
26
+
27
+ // Redis Test Utils
28
+ export {
29
+ createRedisTestFixture,
30
+ cleanupRedisTestFixture,
31
+ waitForRedis,
32
+ createMockRedis,
33
+ RedisPerformanceTester,
34
+ } from './redis-test-utils.js';
35
+ export type { RedisTestFixtureOptions, RedisTestFixture } from './redis-test-utils.js';
36
+
37
+ // Container Utils
38
+ export {
39
+ registerModuleProviders,
40
+ registerProvider,
41
+ createTestContainer as createSimpleTestContainer,
42
+ resolveFromModule,
43
+ hasProvider,
44
+ getModuleTokens,
45
+ MockContainer,
46
+ } from './container-utils.js';
47
+
48
+ // Process Manager Testing
49
+ export {
50
+ TestProcessManager,
51
+ createTestProcessManager,
52
+ MockProcessSpawner,
53
+ AdvancedMockProcessSpawner,
54
+ SimpleMockProcessSpawner,
55
+ MockWorker,
56
+ MockNetronClient,
57
+ MockWorkerHandle,
58
+ } from './pm/index.js';
59
+ export type { ITestProcessManagerConfig, IOperationRecord } from './pm/index.js';
60
+
61
+ // Nexus DI Testing
62
+ export {
63
+ MockProviderDI,
64
+ createMockProvider,
65
+ createAutoMockProvider,
66
+ MockProvider,
67
+ SpyProvider,
68
+ StubProvider,
69
+ TestContainer,
70
+ createTestContainer,
71
+ createTestContainer as createNexusTestContainer,
72
+ createIsolatedTestContainer,
73
+ TestModuleBuilder as NexusTestModuleBuilder,
74
+ CallCountExpectation,
75
+ CallArgumentsExpectation,
76
+ NeverCalledExpectation,
77
+ SnapshotContainer,
78
+ IsolatedContainer,
79
+ TestModule as NexusTestModule,
80
+ TestHarness,
81
+ waitFor,
82
+ createDeferred,
83
+ createTestProvider,
84
+ createTestFactoryProvider,
85
+ createTestClassProvider,
86
+ assertThrows,
87
+ createTestToken,
88
+ verifyContainerState,
89
+ cleanupTest,
90
+ createTestSuite,
91
+ createTestModule as createNexusTestModule,
92
+ createTestHarness,
93
+ expectResolution,
94
+ expectRejection,
95
+ expectDependency,
96
+ expectLifecycle,
97
+ } from './nexus/index.js';
98
+ export type {
99
+ MockProviderConfig,
100
+ MockConfig,
101
+ TestContainerOptions,
102
+ Interaction,
103
+ SpyExpectation,
104
+ TestMockConfig,
105
+ TestProvider,
106
+ TestModuleConfig,
107
+ TestHarnessConfig,
108
+ TestContainerOptionsExtended,
109
+ MemoryUsage,
110
+ ResolutionExpectation,
111
+ RejectionExpectation,
112
+ DependencyExpectation,
113
+ LifecycleExpectation,
114
+ } from './nexus/index.js';
115
+
116
+ // Database Testing
117
+ export {
118
+ DatabaseTestingModule,
119
+ DATABASE_TESTING_SERVICE,
120
+ DatabaseTestingService,
121
+ createTestDatabase,
122
+ withTestDatabase,
123
+ createTestDatabaseConfigs,
124
+ cleanupTestDatabaseConfigs,
125
+ getRecommendedTestDatabase,
126
+ isDockerAvailable,
127
+ } from './database/index.js';
128
+ export type { DatabaseTestingOptions, DatabaseTestOptions, DatabaseTestContext } from './database/index.js';
@@ -0,0 +1,3 @@
1
+ export * from './mock-provider.js';
2
+ export * from './test-container.js';
3
+ export * from './test-utilities.js';
@@ -0,0 +1,189 @@
1
+ import { ProviderDefinition, InjectionToken as Token } from '@omnitron-dev/titan/nexus';
2
+
3
+ // Vitest type declaration (for build compatibility)
4
+ declare const vi: any;
5
+
6
+ /**
7
+ * Mock provider configuration
8
+ */
9
+ export interface MockProviderConfig<T = any> {
10
+ token: Token<T>;
11
+ value?: T;
12
+ factory?: (...args: any[]) => T;
13
+ spy?: boolean;
14
+ autoMock?: boolean;
15
+ }
16
+
17
+ /**
18
+ * Mock provider for testing (original implementation for DI)
19
+ */
20
+ export class MockProviderDI<T> {
21
+ private provider: ProviderDefinition<T>;
22
+
23
+ constructor(private config: MockProviderConfig<T>) {
24
+ if (config.value !== undefined) {
25
+ this.provider = { useValue: config.value };
26
+ } else if (config.factory) {
27
+ this.provider = { useFactory: config.factory };
28
+ } else if (config.autoMock) {
29
+ this.provider = { useFactory: () => this.createAutoMock() };
30
+ } else {
31
+ this.provider = { useValue: {} as T };
32
+ }
33
+ }
34
+
35
+ getProvider(): ProviderDefinition<T> {
36
+ return this.provider;
37
+ }
38
+
39
+ /**
40
+ * Create an automatic mock
41
+ */
42
+ private createAutoMock(): T {
43
+ // Create a proxy that returns vi mocks for all properties
44
+ return new Proxy({} as any, {
45
+ get(target, prop) {
46
+ if (typeof prop === 'string') {
47
+ if (!(prop in target)) {
48
+ (target as any)[prop] = vi.fn();
49
+ }
50
+ return (target as any)[prop];
51
+ }
52
+ return undefined;
53
+ },
54
+ });
55
+ }
56
+
57
+ /**
58
+ * Create a spy wrapper around the mock
59
+ */
60
+ createSpy(): T {
61
+ const provider = this.provider;
62
+ let mock: T | undefined;
63
+
64
+ if ('useValue' in provider) {
65
+ mock = provider.useValue;
66
+ } else {
67
+ // For factories and other cases, use automock
68
+ mock = this.createAutoMock();
69
+ }
70
+
71
+ if (!mock) {
72
+ mock = this.createAutoMock();
73
+ }
74
+
75
+ if (typeof mock === 'object' && mock !== null) {
76
+ // Wrap all functions with vi spies
77
+ const spy = { ...mock } as any;
78
+
79
+ for (const key in spy) {
80
+ if (typeof spy[key] === 'function') {
81
+ spy[key] = vi.fn(spy[key]);
82
+ }
83
+ }
84
+
85
+ return spy;
86
+ }
87
+
88
+ return mock as T;
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Create a mock provider
94
+ */
95
+ export function createMockProvider<T>(config: MockProviderConfig<T>): MockProviderDI<T> {
96
+ return new MockProviderDI(config);
97
+ }
98
+
99
+ /**
100
+ * Create an auto-mock provider
101
+ */
102
+ export function createAutoMockProvider<T>(token: Token<T>): MockProviderDI<T> {
103
+ return new MockProviderDI({
104
+ token,
105
+ autoMock: true,
106
+ });
107
+ }
108
+
109
+ /**
110
+ * Mock provider that wraps vi mocks (for test utilities)
111
+ */
112
+ export class MockProvider {
113
+ constructor(private mockImplementation: Record<string, any>) {
114
+ // Copy all mock methods to the provider instance
115
+ for (const [key, value] of Object.entries(mockImplementation)) {
116
+ if (typeof value === 'function' && vi.isMockFunction && vi.isMockFunction(value)) {
117
+ (this as any)[key] = value;
118
+ } else {
119
+ // Wrap non-mock functions with vi.fn()
120
+ (this as any)[key] = typeof value === 'function' ? vi.fn(value) : value;
121
+ }
122
+ }
123
+ }
124
+
125
+ [key: string]: any;
126
+ }
127
+
128
+ /**
129
+ * Spy provider that wraps original implementation with spies
130
+ */
131
+ export class SpyProvider {
132
+ private calls = new Map<string, Array<{ args: any[]; result?: any; error?: Error }>>();
133
+ private spies = new Map<string, any>();
134
+
135
+ constructor(
136
+ private original: any,
137
+ methods: string[]
138
+ ) {
139
+ for (const method of methods) {
140
+ if (typeof this.original[method] === 'function') {
141
+ const spy = vi.spyOn(this.original, method);
142
+ this.spies.set(method, spy);
143
+
144
+ // Wrap to track calls manually too
145
+ (this as any)[method] = (...args: any[]) => {
146
+ try {
147
+ const result = this.original[method](...args);
148
+ this.recordCall(method, args, result);
149
+ return result;
150
+ } catch (error) {
151
+ this.recordCall(method, args, undefined, error as Error);
152
+ throw error;
153
+ }
154
+ };
155
+ }
156
+ }
157
+ }
158
+
159
+ private recordCall(method: string, args: any[], result?: any, error?: Error): void {
160
+ if (!this.calls.has(method)) {
161
+ this.calls.set(method, []);
162
+ }
163
+ this.calls.get(method)!.push({ args, result, error });
164
+ }
165
+
166
+ getCallCount(method: string): number {
167
+ return this.calls.get(method)?.length || 0;
168
+ }
169
+
170
+ getLastCall(method: string): { args: any[]; result?: any; error?: Error } | undefined {
171
+ const calls = this.calls.get(method);
172
+ return calls?.[calls.length - 1];
173
+ }
174
+
175
+ getSpy(method: string): any {
176
+ return this.spies.get(method);
177
+ }
178
+ }
179
+
180
+ /**
181
+ * Stub provider that returns fixed values
182
+ */
183
+ export class StubProvider {
184
+ constructor(private stubs: Record<string, any>) {
185
+ for (const [key, value] of Object.entries(stubs)) {
186
+ (this as any)[key] = vi.fn().mockReturnValue(value);
187
+ }
188
+ }
189
+ }