@omnitron-dev/testing 0.4.4 → 0.4.6

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 (122) hide show
  1. package/README.md +43 -0
  2. package/dist/async/events.js.map +1 -1
  3. package/dist/async/index.d.ts +5 -5
  4. package/dist/async/index.js +5 -5
  5. package/dist/async/index.js.map +1 -1
  6. package/dist/async/retry.js.map +1 -1
  7. package/dist/async/wait.js.map +1 -1
  8. package/dist/docker/database-manager.js +13 -15
  9. package/dist/docker/database-manager.js.map +1 -1
  10. package/dist/docker/docker-test-manager.d.ts +12 -3
  11. package/dist/docker/docker-test-manager.js +286 -255
  12. package/dist/docker/docker-test-manager.js.map +1 -1
  13. package/dist/docker/redis-manager.js +70 -95
  14. package/dist/docker/redis-manager.js.map +1 -1
  15. package/dist/docker/types.d.ts +7 -2
  16. package/dist/env.d.ts +11 -0
  17. package/dist/env.js +21 -0
  18. package/dist/env.js.map +1 -0
  19. package/dist/errors.js.map +1 -1
  20. package/dist/helpers/assertions.js +3 -3
  21. package/dist/helpers/assertions.js.map +1 -1
  22. package/dist/index.d.ts +1 -1
  23. package/dist/runtime/bun-adapter.d.ts +23 -1
  24. package/dist/runtime/bun-adapter.js +14 -1
  25. package/dist/runtime/bun-adapter.js.map +1 -1
  26. package/dist/runtime/deno-adapter.d.ts +72 -15
  27. package/dist/runtime/deno-adapter.js +93 -78
  28. package/dist/runtime/deno-adapter.js.map +1 -1
  29. package/dist/runtime/node-adapter.d.ts +15 -3
  30. package/dist/runtime/node-adapter.js +1 -1
  31. package/dist/runtime/node-adapter.js.map +1 -1
  32. package/dist/runtime/test-adapter.d.ts +1 -1
  33. package/dist/runtime/test-adapter.js +12 -14
  34. package/dist/runtime/test-adapter.js.map +1 -1
  35. package/dist/titan/database/database-testing.module.d.ts +7 -6
  36. package/dist/titan/database/database-testing.module.js +40 -26
  37. package/dist/titan/database/database-testing.module.js.map +1 -1
  38. package/dist/titan/database/index.d.ts +1 -1
  39. package/dist/titan/database/index.js +1 -1
  40. package/dist/titan/database/index.js.map +1 -1
  41. package/dist/titan/database/test-utilities.d.ts +2 -2
  42. package/dist/titan/database/test-utilities.js +3 -2
  43. package/dist/titan/database/test-utilities.js.map +1 -1
  44. package/dist/titan/index.d.ts +9 -9
  45. package/dist/titan/index.js +6 -6
  46. package/dist/titan/index.js.map +1 -1
  47. package/dist/titan/nexus/mock-provider.js +6 -6
  48. package/dist/titan/nexus/mock-provider.js.map +1 -1
  49. package/dist/titan/nexus/test-container.js +10 -10
  50. package/dist/titan/nexus/test-container.js.map +1 -1
  51. package/dist/titan/nexus/test-utilities.js +9 -9
  52. package/dist/titan/nexus/test-utilities.js.map +1 -1
  53. package/dist/titan/pm/mock-process-spawner.d.ts +4 -3
  54. package/dist/titan/pm/mock-process-spawner.js +37 -15
  55. package/dist/titan/pm/mock-process-spawner.js.map +1 -1
  56. package/dist/titan/pm/mock-spawner.d.ts +2 -1
  57. package/dist/titan/pm/mock-spawner.js +3 -1
  58. package/dist/titan/pm/mock-spawner.js.map +1 -1
  59. package/dist/titan/pm/test-process-manager.d.ts +4 -4
  60. package/dist/titan/pm/test-process-manager.js +7 -3
  61. package/dist/titan/pm/test-process-manager.js.map +1 -1
  62. package/dist/titan/redis-test-utils.d.ts +8 -2
  63. package/dist/titan/redis-test-utils.js +147 -92
  64. package/dist/titan/redis-test-utils.js.map +1 -1
  65. package/dist/titan/test-application.d.ts +1 -1
  66. package/dist/titan/test-application.js +1 -1
  67. package/dist/titan/test-application.js.map +1 -1
  68. package/dist/titan/test-fixtures.js.map +1 -1
  69. package/dist/titan/test-mocks.d.ts +12 -11
  70. package/dist/titan/test-mocks.js +49 -49
  71. package/dist/titan/test-mocks.js.map +1 -1
  72. package/dist/titan/test-module.js.map +1 -1
  73. package/package.json +66 -40
  74. package/src/async/events.ts +1 -1
  75. package/src/async/index.ts +5 -30
  76. package/src/async/retry.ts +1 -4
  77. package/src/async/wait.ts +1 -4
  78. package/src/docker/a-port-the-network-could-reach.spec.ts +66 -0
  79. package/src/docker/database-manager.ts +13 -15
  80. package/src/docker/docker-orphan-reaper.spec.ts +175 -0
  81. package/src/docker/docker-port-collision.spec.ts +97 -0
  82. package/src/docker/docker-test-manager.spec.ts +122 -0
  83. package/src/docker/docker-test-manager.ts +421 -327
  84. package/src/docker/docker-volume-cleanup.spec.ts +113 -0
  85. package/src/docker/redis-cluster-creation.spec.ts +52 -0
  86. package/src/docker/redis-manager.ts +87 -117
  87. package/src/docker/types.ts +11 -4
  88. package/src/env.spec.ts +20 -0
  89. package/src/env.ts +33 -0
  90. package/src/errors.ts +9 -2
  91. package/src/globals.d.ts +2 -2
  92. package/src/helpers/assertions.ts +4 -7
  93. package/src/index.ts +1 -1
  94. package/src/runtime/adapter-surface.spec.ts +83 -0
  95. package/src/runtime/bun-adapter.ts +36 -5
  96. package/src/runtime/deno-adapter.ts +167 -108
  97. package/src/runtime/node-adapter.ts +5 -5
  98. package/src/runtime/test-adapter.test.ts +1 -1
  99. package/src/runtime/test-adapter.ts +15 -17
  100. package/src/titan/database/database-testing.module.ts +73 -53
  101. package/src/titan/database/index.ts +2 -2
  102. package/src/titan/database/test-utilities.ts +6 -3
  103. package/src/titan/index.ts +13 -27
  104. package/src/titan/nexus/mock-provider.ts +12 -12
  105. package/src/titan/nexus/test-container.ts +25 -17
  106. package/src/titan/nexus/test-utilities.ts +13 -11
  107. package/src/titan/pm/mock-process-spawner.ts +80 -27
  108. package/src/titan/pm/mock-spawner.ts +10 -4
  109. package/src/titan/pm/test-process-manager.ts +26 -9
  110. package/src/titan/redis-test-utils.test.ts +102 -0
  111. package/src/titan/redis-test-utils.ts +191 -109
  112. package/src/titan/test-application.ts +2 -2
  113. package/src/titan/test-fixtures.ts +0 -1
  114. package/src/titan/test-mocks.ts +50 -50
  115. package/runtime/bun.d.ts +0 -2
  116. package/runtime/bun.js +0 -5
  117. package/runtime/bun.ts +0 -7
  118. package/runtime/deno.d.ts +0 -2
  119. package/runtime/deno.js +0 -4
  120. package/runtime/jest.d.ts +0 -2
  121. package/runtime/jest.js +0 -16
  122. package/runtime/jest.ts +0 -7
@@ -8,10 +8,9 @@
8
8
  import { DynamicModule, IModule } from '@omnitron-dev/titan/nexus';
9
9
  import { Module, Injectable, Inject } from '@omnitron-dev/titan/decorators';
10
10
  import { Kysely, Transaction, sql } from 'kysely';
11
- import { TitanDatabaseModule } from '@omnitron-dev/titan/module/database';
12
- import { DatabaseManager } from '@omnitron-dev/titan/module/database';
13
- import { MigrationRunner } from '@omnitron-dev/titan/module/database';
14
- import { TransactionManager } from '@omnitron-dev/titan/module/database';
11
+ import { TitanDatabaseModule } from '@omnitron-dev/titan-database';
12
+ import { DatabaseManager } from '@omnitron-dev/titan-database';
13
+ import { MigrationRunner } from '@omnitron-dev/titan-database';
15
14
  import { Errors } from '@omnitron-dev/titan/errors';
16
15
  // @kysera/testing utilities (moved from @kysera/core in 0.7.0)
17
16
  import {
@@ -29,11 +28,15 @@ import {
29
28
  } from '@kysera/testing';
30
29
  import {
31
30
  DATABASE_MANAGER,
32
- DATABASE_MIGRATION_SERVICE,
33
- DATABASE_TRANSACTION_MANAGER,
34
- DATABASE_TESTING_SERVICE,
35
- } from '@omnitron-dev/titan/module/database';
36
- import type { DatabaseModuleOptions } from '@omnitron-dev/titan/module/database';
31
+ } from '@omnitron-dev/titan-database';
32
+
33
+ // These tokens were removed from titan's public exports but are still needed
34
+ // for optional DI injection in the testing module. Using Symbol.for() ensures
35
+ // they match any other code that creates the same symbol.
36
+ const DATABASE_MIGRATION_SERVICE = Symbol.for('titan:DATABASE_MIGRATION_SERVICE');
37
+ const DATABASE_TRANSACTION_MANAGER = Symbol.for('titan:DATABASE_TRANSACTION_MANAGER');
38
+ export const DATABASE_TESTING_SERVICE = Symbol.for('titan:DATABASE_TESTING_SERVICE');
39
+ import type { DatabaseModuleOptions } from '@omnitron-dev/titan-database';
37
40
 
38
41
  export interface DatabaseTestingOptions extends Partial<DatabaseModuleOptions> {
39
42
  /**
@@ -97,7 +100,7 @@ export class DatabaseTestingService {
97
100
  @Inject(DATABASE_MANAGER) private manager: DatabaseManager,
98
101
  @Inject('DATABASE_TESTING_OPTIONS') private options: DatabaseTestingOptions,
99
102
  @Inject(DATABASE_MIGRATION_SERVICE) private migrationRunner?: MigrationRunner,
100
- @Inject(DATABASE_TRANSACTION_MANAGER) private transactionManager?: TransactionManager
103
+ @Inject(DATABASE_TRANSACTION_MANAGER) private transactionManager?: unknown
101
104
  ) {}
102
105
 
103
106
  /**
@@ -115,7 +118,7 @@ export class DatabaseTestingService {
115
118
 
116
119
  // Run migrations if enabled
117
120
  if (this.options.autoMigrate && this.migrationRunner) {
118
- await this.migrationRunner.migrate();
121
+ await this.migrationRunner.up();
119
122
  }
120
123
 
121
124
  // Seed database if enabled
@@ -130,7 +133,7 @@ export class DatabaseTestingService {
130
133
  * Setup before each test
131
134
  */
132
135
  async beforeEach(): Promise<void> {
133
- const db = await this.manager.getConnection();
136
+ const _db = await this.manager.getConnection();
134
137
 
135
138
  // Clean database if enabled
136
139
  if (this.options.autoClean) {
@@ -225,6 +228,25 @@ export class DatabaseTestingService {
225
228
  }
226
229
  }
227
230
 
231
+ /**
232
+ * Convert booleans to integers for SQLite compatibility
233
+ */
234
+ private convertBooleansForSqlite(
235
+ db: Kysely<Record<string, unknown>> | Transaction<unknown>,
236
+ data: Record<string, unknown>
237
+ ): Record<string, unknown> {
238
+ const dialect = this.getDialect(db as Kysely<Record<string, unknown>>);
239
+ if (dialect !== 'sqlite') {
240
+ return data;
241
+ }
242
+
243
+ const result: Record<string, unknown> = {};
244
+ for (const [key, value] of Object.entries(data)) {
245
+ result[key] = typeof value === 'boolean' ? (value ? 1 : 0) : value;
246
+ }
247
+ return result;
248
+ }
249
+
228
250
  /**
229
251
  * Insert seed data
230
252
  */
@@ -238,10 +260,11 @@ export class DatabaseTestingService {
238
260
  const records = Array.isArray(seed.data) ? seed.data : [seed.data];
239
261
 
240
262
  for (const record of records) {
241
- await (db as Kysely<Record<string, unknown>>)
242
- .insertInto(seed.table)
243
- .values(record)
244
- .execute();
263
+ const convertedRecord = this.convertBooleansForSqlite(
264
+ db as Kysely<Record<string, unknown>>,
265
+ record as Record<string, unknown>
266
+ );
267
+ await (db as Kysely<Record<string, unknown>>).insertInto(seed.table).values(convertedRecord).execute();
245
268
  }
246
269
  } catch (error) {
247
270
  if (this.options.verbose) {
@@ -285,10 +308,7 @@ export class DatabaseTestingService {
285
308
  /**
286
309
  * Get all tables in database
287
310
  */
288
- private async getAllTables(
289
- db: Kysely<Record<string, unknown>>,
290
- dialect: string
291
- ): Promise<string[]> {
311
+ private async getAllTables(db: Kysely<Record<string, unknown>>, dialect: string): Promise<string[]> {
292
312
  interface TableRow {
293
313
  table_name: string;
294
314
  }
@@ -327,7 +347,13 @@ export class DatabaseTestingService {
327
347
  * Get database dialect
328
348
  */
329
349
  private getDialect(db: Kysely<Record<string, unknown>>): string {
330
- // Try to determine dialect from the connection
350
+ // First, try to get dialect from the DatabaseManager (most reliable)
351
+ const managerDialect = this.manager.getDialect();
352
+ if (managerDialect) {
353
+ return managerDialect;
354
+ }
355
+
356
+ // Fallback: Try to determine dialect from the Kysely instance structure
331
357
  const dbWithDialect = db as unknown as {
332
358
  dialect?: { name?: string };
333
359
  _dialect?: { name?: string };
@@ -342,7 +368,8 @@ export class DatabaseTestingService {
342
368
  if (dbWithDialect.driver?.postgres) return 'postgres';
343
369
  if (dbWithDialect.driver?.mysql) return 'mysql';
344
370
 
345
- return 'sqlite';
371
+ // If we can't determine the dialect, throw an error instead of defaulting to sqlite
372
+ throw Errors.conflict('Unable to determine database dialect. Ensure DatabaseManager is properly configured.');
346
373
  }
347
374
 
348
375
  /**
@@ -378,8 +405,8 @@ export class DatabaseTestingService {
378
405
  /**
379
406
  * Get test database connection
380
407
  */
381
- getTestConnection(): Kysely<Record<string, unknown>> | Transaction<unknown> {
382
- return (this.currentTransaction || this.manager.getConnection()) as
408
+ async getTestConnection(): Promise<Kysely<Record<string, unknown>> | Transaction<unknown>> {
409
+ return (this.currentTransaction || (await this.manager.getConnection())) as
383
410
  | Kysely<Record<string, unknown>>
384
411
  | Transaction<unknown>;
385
412
  }
@@ -392,14 +419,18 @@ export class DatabaseTestingService {
392
419
  generator: () => Partial<T> | Promise<Partial<T>>,
393
420
  count: number = 1
394
421
  ): Promise<T[]> {
395
- const db = this.getTestConnection();
422
+ const db = await this.getTestConnection();
396
423
  const results: T[] = [];
397
424
 
398
425
  for (let i = 0; i < count; i++) {
399
426
  const data = await generator();
427
+ const convertedData = this.convertBooleansForSqlite(
428
+ db as Kysely<Record<string, unknown>>,
429
+ data as Record<string, unknown>
430
+ );
400
431
  const result = await (db as Kysely<Record<string, unknown>>)
401
432
  .insertInto(table)
402
- .values(data)
433
+ .values(convertedData)
403
434
  .returningAll()
404
435
  .executeTakeFirst();
405
436
 
@@ -415,7 +446,7 @@ export class DatabaseTestingService {
415
446
  * Assert database state
416
447
  */
417
448
  async assertDatabaseHas(table: string, data: Record<string, unknown>): Promise<boolean> {
418
- const db = this.getTestConnection() as Kysely<Record<string, unknown>>;
449
+ const db = (await this.getTestConnection()) as Kysely<Record<string, unknown>>;
419
450
 
420
451
  let query = db.selectFrom(table).selectAll();
421
452
 
@@ -440,7 +471,7 @@ export class DatabaseTestingService {
440
471
  * Count records in table
441
472
  */
442
473
  async assertDatabaseCount(table: string, count: number): Promise<boolean> {
443
- const db = this.getTestConnection();
474
+ const db = await this.getTestConnection();
444
475
 
445
476
  const result = await (db as Kysely<Record<string, unknown>>)
446
477
  .selectFrom(table)
@@ -466,9 +497,7 @@ export class DatabaseTestingService {
466
497
  * });
467
498
  * ```
468
499
  */
469
- async runInTransaction<T>(
470
- fn: (trx: Transaction<unknown>) => Promise<T>
471
- ): Promise<void> {
500
+ async runInTransaction<T>(fn: (trx: Transaction<unknown>) => Promise<T>): Promise<void> {
472
501
  const db = await this.manager.getConnection();
473
502
  await testInTransaction(db, fn);
474
503
  }
@@ -485,9 +514,7 @@ export class DatabaseTestingService {
485
514
  * });
486
515
  * ```
487
516
  */
488
- async runWithSavepoints<T>(
489
- fn: (trx: Transaction<unknown>) => Promise<T>
490
- ): Promise<void> {
517
+ async runWithSavepoints<T>(fn: (trx: Transaction<unknown>) => Promise<T>): Promise<void> {
491
518
  const db = await this.manager.getConnection();
492
519
  await testWithSavepoints(db, fn);
493
520
  }
@@ -524,10 +551,7 @@ export class DatabaseTestingService {
524
551
  * await testingService.cleanWithKysera('truncate', ['users', 'posts']);
525
552
  * ```
526
553
  */
527
- async cleanWithKysera(
528
- strategy: CleanupStrategy = 'delete',
529
- tables?: string[]
530
- ): Promise<void> {
554
+ async cleanWithKysera(strategy: CleanupStrategy = 'delete', tables?: string[]): Promise<void> {
531
555
  const db = await this.manager.getConnection();
532
556
  await kyseraCleanDatabase(db, strategy, tables);
533
557
  }
@@ -542,9 +566,7 @@ export class DatabaseTestingService {
542
566
  * });
543
567
  * ```
544
568
  */
545
- async seedWithKysera(
546
- fn: (trx: Transaction<unknown>) => Promise<void>
547
- ): Promise<void> {
569
+ async seedWithKysera(fn: (trx: Transaction<unknown>) => Promise<void>): Promise<void> {
548
570
  const db = await this.manager.getConnection();
549
571
  await kyseraSeedDatabase(db, fn);
550
572
  }
@@ -614,9 +636,9 @@ export class DatabaseTestingService {
614
636
  * const user2 = createUser({ name: 'Custom Name' }); // Override name
615
637
  * ```
616
638
  */
617
- createDataFactory<T extends Record<string, unknown>>(
618
- defaults: { [K in keyof T]: T[K] | (() => T[K]) }
619
- ): (overrides?: Partial<T>) => T {
639
+ createDataFactory<T extends Record<string, unknown>>(defaults: { [K in keyof T]: T[K] | (() => T[K]) }): (
640
+ overrides?: Partial<T>
641
+ ) => T {
620
642
  return kyseraCreateFactory(defaults);
621
643
  }
622
644
 
@@ -635,16 +657,12 @@ export class DatabaseTestingService {
635
657
  count: number,
636
658
  overrides?: Partial<T>
637
659
  ): Promise<T[]> {
638
- const db = this.getTestConnection() as Kysely<Record<string, unknown>>;
660
+ const db = (await this.getTestConnection()) as Kysely<Record<string, unknown>>;
639
661
  const results: T[] = [];
640
662
 
641
663
  for (let i = 0; i < count; i++) {
642
664
  const data = factory(overrides);
643
- const result = await db
644
- .insertInto(table)
645
- .values(data)
646
- .returningAll()
647
- .executeTakeFirst();
665
+ const result = await db.insertInto(table).values(data).returningAll().executeTakeFirst();
648
666
 
649
667
  if (result) {
650
668
  results.push(result as T);
@@ -730,9 +748,7 @@ export class DatabaseTestingModule {
730
748
  * running tests in parallel. Each isolated module gets its own schema (if supported)
731
749
  * and independent service instances.
732
750
  */
733
- static async createIsolatedModule(
734
- options: DatabaseTestingOptions = {}
735
- ): Promise<{
751
+ static async createIsolatedModule(options: DatabaseTestingOptions = {}): Promise<{
736
752
  module: DynamicModule;
737
753
  service?: DatabaseTestingService;
738
754
  cleanup: () => Promise<void>;
@@ -765,6 +781,7 @@ export class DatabaseTestingModule {
765
781
  const module = DatabaseTestingModule.forTest(isolatedOptions);
766
782
 
767
783
  // Store service reference for cleanup
784
+
768
785
  let serviceInstance: DatabaseTestingService | undefined;
769
786
 
770
787
  // Return module with enhanced cleanup that properly disposes the service
@@ -773,6 +790,9 @@ export class DatabaseTestingModule {
773
790
  get service() {
774
791
  return serviceInstance;
775
792
  },
793
+ set service(instance: DatabaseTestingService | undefined) {
794
+ serviceInstance = instance;
795
+ },
776
796
  cleanup: async () => {
777
797
  try {
778
798
  // If service was injected, clean it up
@@ -26,5 +26,5 @@ export {
26
26
  type DatabaseTestContext,
27
27
  } from './test-utilities.js';
28
28
 
29
- // Re-export DATABASE_TESTING_SERVICE constant from titan for convenience
30
- export { DATABASE_TESTING_SERVICE } from '@omnitron-dev/titan/module/database';
29
+ // Re-export DATABASE_TESTING_SERVICE from the testing module
30
+ export { DATABASE_TESTING_SERVICE } from './database-testing.module.js';
@@ -5,8 +5,8 @@
5
5
  * Falls back to SQLite when Docker is not available
6
6
  */
7
7
 
8
- import { DockerTestManager, DatabaseTestManager, type DockerContainer } from '@omnitron-dev/testing/docker';
9
- import type { DatabaseModuleOptions } from '@omnitron-dev/titan/module/database';
8
+ import { DockerTestManager, DatabaseTestManager, type DockerContainer } from '../../docker/index.js';
9
+ import type { DatabaseModuleOptions } from '@omnitron-dev/titan-database';
10
10
 
11
11
  export interface DatabaseTestOptions {
12
12
  /**
@@ -206,10 +206,13 @@ export async function createTestDatabase(options: DatabaseTestOptions = {}): Pro
206
206
  console.log('Using in-memory SQLite for testing (forced)');
207
207
  }
208
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
+
209
212
  return {
210
213
  connection: {
211
214
  dialect: 'sqlite',
212
- connection: 'file::memory:?cache=shared',
215
+ connection: `file:${uniqueId}?mode=memory&cache=shared`,
213
216
  },
214
217
  dialect: 'sqlite',
215
218
  isDocker: false,
@@ -5,34 +5,21 @@
5
5
  */
6
6
 
7
7
  // Test Module
8
- export {
9
- TestModule,
10
- TestModuleBuilder,
11
- createTestModule,
12
- testModule,
13
- } from './test-module.js';
8
+ export { TestModule, TestModuleBuilder, createTestModule, testModule } from './test-module.js';
14
9
  export type { TestModuleOptions } from './test-module.js';
15
10
 
16
11
  // Test Application
17
- export {
18
- TestApplication,
19
- } from './test-application.js';
12
+ export { TestApplication } from './test-application.js';
20
13
 
21
14
  // Test Fixtures
22
- export {
23
- TestSchemas,
24
- TestConfigs,
25
- TestRedisConfigs,
26
- TestModules,
27
- TestData,
28
- TestTiming,
29
- } from './test-fixtures.js';
15
+ export { TestSchemas, TestConfigs, TestRedisConfigs, TestModules, TestData, TestTiming } from './test-fixtures.js';
30
16
 
31
17
  // Test Mocks
32
18
  export {
33
19
  createMockLogger,
34
20
  createMockConfigService,
35
21
  createMockRedisManager,
22
+ createMockRedisClient,
36
23
  createMockSchedulerService,
37
24
  createMockEventBus,
38
25
  } from './test-mocks.js';
@@ -43,9 +30,14 @@ export {
43
30
  cleanupRedisTestFixture,
44
31
  waitForRedis,
45
32
  createMockRedis,
33
+ resolveTestRedisEndpoint,
46
34
  RedisPerformanceTester,
47
35
  } from './redis-test-utils.js';
48
- export type { RedisTestFixtureOptions, RedisTestFixture } from './redis-test-utils.js';
36
+ export type {
37
+ RedisTestFixtureOptions,
38
+ RedisTestFixture,
39
+ TestRedisEndpoint,
40
+ } from './redis-test-utils.js';
49
41
 
50
42
  // Container Utils
51
43
  export {
@@ -69,10 +61,7 @@ export {
69
61
  MockNetronClient,
70
62
  MockWorkerHandle,
71
63
  } from './pm/index.js';
72
- export type {
73
- ITestProcessManagerConfig,
74
- IOperationRecord,
75
- } from './pm/index.js';
64
+ export type { ITestProcessManagerConfig, IOperationRecord } from './pm/index.js';
76
65
 
77
66
  // Nexus DI Testing
78
67
  export {
@@ -132,6 +121,7 @@ export type {
132
121
  // Database Testing
133
122
  export {
134
123
  DatabaseTestingModule,
124
+ DATABASE_TESTING_SERVICE,
135
125
  DatabaseTestingService,
136
126
  createTestDatabase,
137
127
  withTestDatabase,
@@ -140,8 +130,4 @@ export {
140
130
  getRecommendedTestDatabase,
141
131
  isDockerAvailable,
142
132
  } from './database/index.js';
143
- export type {
144
- DatabaseTestingOptions,
145
- DatabaseTestOptions,
146
- DatabaseTestContext,
147
- } from './database/index.js';
133
+ export type { DatabaseTestingOptions, DatabaseTestOptions, DatabaseTestContext } from './database/index.js';
@@ -1,7 +1,7 @@
1
1
  import { ProviderDefinition, InjectionToken as Token } from '@omnitron-dev/titan/nexus';
2
2
 
3
- // Jest type declaration (for build compatibility)
4
- declare const jest: any;
3
+ // Vitest type declaration (for build compatibility)
4
+ declare const vi: any;
5
5
 
6
6
  /**
7
7
  * Mock provider configuration
@@ -40,12 +40,12 @@ export class MockProviderDI<T> {
40
40
  * Create an automatic mock
41
41
  */
42
42
  private createAutoMock(): T {
43
- // Create a proxy that returns jest mocks for all properties
43
+ // Create a proxy that returns vi mocks for all properties
44
44
  return new Proxy({} as any, {
45
45
  get(target, prop) {
46
46
  if (typeof prop === 'string') {
47
47
  if (!(prop in target)) {
48
- (target as any)[prop] = jest.fn();
48
+ (target as any)[prop] = vi.fn();
49
49
  }
50
50
  return (target as any)[prop];
51
51
  }
@@ -73,12 +73,12 @@ export class MockProviderDI<T> {
73
73
  }
74
74
 
75
75
  if (typeof mock === 'object' && mock !== null) {
76
- // Wrap all functions with jest spies
76
+ // Wrap all functions with vi spies
77
77
  const spy = { ...mock } as any;
78
78
 
79
79
  for (const key in spy) {
80
80
  if (typeof spy[key] === 'function') {
81
- spy[key] = jest.fn(spy[key]);
81
+ spy[key] = vi.fn(spy[key]);
82
82
  }
83
83
  }
84
84
 
@@ -107,17 +107,17 @@ export function createAutoMockProvider<T>(token: Token<T>): MockProviderDI<T> {
107
107
  }
108
108
 
109
109
  /**
110
- * Mock provider that wraps jest mocks (for test utilities)
110
+ * Mock provider that wraps vi mocks (for test utilities)
111
111
  */
112
112
  export class MockProvider {
113
113
  constructor(private mockImplementation: Record<string, any>) {
114
114
  // Copy all mock methods to the provider instance
115
115
  for (const [key, value] of Object.entries(mockImplementation)) {
116
- if (typeof value === 'function' && jest.isMockFunction && jest.isMockFunction(value)) {
116
+ if (typeof value === 'function' && vi.isMockFunction && vi.isMockFunction(value)) {
117
117
  (this as any)[key] = value;
118
118
  } else {
119
- // Wrap non-mock functions with jest.fn()
120
- (this as any)[key] = typeof value === 'function' ? jest.fn(value) : value;
119
+ // Wrap non-mock functions with vi.fn()
120
+ (this as any)[key] = typeof value === 'function' ? vi.fn(value) : value;
121
121
  }
122
122
  }
123
123
  }
@@ -138,7 +138,7 @@ export class SpyProvider {
138
138
  ) {
139
139
  for (const method of methods) {
140
140
  if (typeof this.original[method] === 'function') {
141
- const spy = jest.spyOn(this.original, method);
141
+ const spy = vi.spyOn(this.original, method);
142
142
  this.spies.set(method, spy);
143
143
 
144
144
  // Wrap to track calls manually too
@@ -183,7 +183,7 @@ export class SpyProvider {
183
183
  export class StubProvider {
184
184
  constructor(private stubs: Record<string, any>) {
185
185
  for (const [key, value] of Object.entries(stubs)) {
186
- (this as any)[key] = jest.fn().mockReturnValue(value);
186
+ (this as any)[key] = vi.fn().mockReturnValue(value);
187
187
  }
188
188
  }
189
189
  }
@@ -3,7 +3,14 @@
3
3
  */
4
4
 
5
5
  import { Container } from '@omnitron-dev/titan/nexus';
6
- import { IModule, Provider, ProviderDefinition, Constructor, InjectionToken, RegistrationOptions } from '@omnitron-dev/titan/nexus';
6
+ import {
7
+ IModule,
8
+ Provider,
9
+ ProviderDefinition,
10
+ Constructor,
11
+ InjectionToken,
12
+ RegistrationOptions,
13
+ } from '@omnitron-dev/titan/nexus';
7
14
 
8
15
  /**
9
16
  * Mock provider configuration
@@ -133,8 +140,8 @@ export class NeverCalledExpectation implements SpyExpectation {
133
140
  /**
134
141
  * Test container with testing utilities
135
142
  */
136
- // Jest types workaround for build
137
- declare const jest: any;
143
+ // Vitest types workaround for build
144
+ declare const vi: any;
138
145
 
139
146
  export class TestContainer extends Container {
140
147
  private mocks = new Map<InjectionToken<any>, any>();
@@ -229,7 +236,7 @@ export class TestContainer extends Container {
229
236
  for (const key in mock) {
230
237
  if (typeof mock[key] === 'function') {
231
238
  const original = mock[key];
232
- mock[key] = jest.fn(original);
239
+ mock[key] = vi.fn(original);
233
240
  }
234
241
  }
235
242
 
@@ -250,7 +257,7 @@ export class TestContainer extends Container {
250
257
  for (const key in wrapped) {
251
258
  if (typeof wrapped[key] === 'function') {
252
259
  const originalFn = wrapped[key];
253
- wrapped[key] = jest.fn((...args: any[]) => {
260
+ wrapped[key] = vi.fn((...args: any[]) => {
254
261
  try {
255
262
  const result = originalFn(...args);
256
263
  this.recordInteraction(token, {
@@ -281,7 +288,7 @@ export class TestContainer extends Container {
281
288
 
282
289
  for (const key in mock as any) {
283
290
  const value = (mock as any)[key];
284
- if (typeof value === 'function' && jest.isMockFunction(value)) {
291
+ if (typeof value === 'function' && vi.isMockFunction(value)) {
285
292
  spyMap.set(key, value);
286
293
  }
287
294
  }
@@ -299,7 +306,7 @@ export class TestContainer extends Container {
299
306
  throw new Error(`Cannot spy on ${String(method)} of ${String(token)}`);
300
307
  }
301
308
 
302
- const spy = jest.spyOn(instance as any, method as string);
309
+ const spy = vi.spyOn(instance as any, method as string);
303
310
 
304
311
  let spyMap = this.spies.get(token);
305
312
  if (!spyMap) {
@@ -327,7 +334,7 @@ export class TestContainer extends Container {
327
334
  stubObject[key] = value;
328
335
  } else {
329
336
  // Otherwise, create a function that returns the value
330
- stubObject[key] = jest.fn(() => value);
337
+ stubObject[key] = vi.fn(() => value);
331
338
  }
332
339
  }
333
340
 
@@ -487,7 +494,7 @@ export class TestContainer extends Container {
487
494
  if (mock && typeof mock === 'object') {
488
495
  for (const key in mock) {
489
496
  const value = mock[key];
490
- if (value && jest.isMockFunction && jest.isMockFunction(value)) {
497
+ if (value && vi.isMockFunction && vi.isMockFunction(value)) {
491
498
  value.mockReset();
492
499
  }
493
500
  }
@@ -518,7 +525,10 @@ export class TestContainer extends Container {
518
525
  /**
519
526
  * Add expectation for a spy
520
527
  */
521
- expect<T>(token: InjectionToken<T>, method: keyof T): {
528
+ expect<T>(
529
+ token: InjectionToken<T>,
530
+ method: keyof T
531
+ ): {
522
532
  toBeCalledTimes: (count: number) => void;
523
533
  toBeCalledWith: (...args: any[]) => void;
524
534
  toBeCalledAtLeast: (count: number) => void;
@@ -612,9 +622,7 @@ export class TestContainer extends Container {
612
622
  for (const expectation of expectations) {
613
623
  if (!expectation.verify(spy)) {
614
624
  const tokenName = typeof token === 'string' ? token : String(token);
615
- violations.push(
616
- `Expectation failed for ${tokenName}.${method as string}: ${expectation.getMessage()}`
617
- );
625
+ violations.push(`Expectation failed for ${tokenName}.${method as string}: ${expectation.getMessage()}`);
618
626
  }
619
627
  }
620
628
  }
@@ -677,7 +685,7 @@ export class TestContainer extends Container {
677
685
  this.resolvedTokens.add(token);
678
686
  }
679
687
  return result;
680
- } catch (originalError) {
688
+ } catch (_originalError) {
681
689
  // Continue to auto-mock if enabled
682
690
  }
683
691
  }
@@ -697,7 +705,7 @@ export class TestContainer extends Container {
697
705
  * Create automatic mock
698
706
  */
699
707
  private createAutoMock<T>(token: InjectionToken<any>): T {
700
- const name =
708
+ const _name =
701
709
  typeof token === 'string'
702
710
  ? token
703
711
  : typeof token === 'symbol'
@@ -709,7 +717,7 @@ export class TestContainer extends Container {
709
717
  get: (target, prop) => {
710
718
  if (typeof prop === 'string') {
711
719
  // Return a mock function for methods
712
- return jest.fn().mockImplementation((...args: any[]) => {
720
+ return vi.fn().mockImplementation((...args: any[]) => {
713
721
  this.recordInteraction(token, {
714
722
  method: prop,
715
723
  args,
@@ -784,7 +792,7 @@ export class TestContainer extends Container {
784
792
  stubObject[key] = value;
785
793
  } else {
786
794
  // Create a function that returns the stubbed value
787
- stubObject[key] = jest.fn().mockReturnValue(value);
795
+ stubObject[key] = vi.fn().mockReturnValue(value);
788
796
  }
789
797
  }
790
798