@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
@@ -5,13 +5,80 @@
5
5
  * Provides comprehensive fixtures and helpers for testing Redis functionality
6
6
  */
7
7
 
8
+ import { existsSync, readFileSync } from 'node:fs';
9
+ import { join } from 'node:path';
10
+
8
11
  import { Redis, RedisOptions } from 'ioredis';
9
- import { RedisManager } from '@omnitron-dev/titan/module/redis';
10
- import { RedisService } from '@omnitron-dev/titan/module/redis';
12
+ import { RedisManager } from '@omnitron-dev/titan-redis';
13
+ import { RedisService } from '@omnitron-dev/titan-redis';
11
14
  import { EventEmitter } from '@omnitron-dev/eventemitter';
12
15
  import { Errors } from '@omnitron-dev/titan/errors';
13
16
  import type { ILogger } from '@omnitron-dev/titan/module/logger';
14
17
 
18
+ /** Where a Vitest `globalSetup` publishes the endpoint it found or started. */
19
+ const REDIS_INFO_FILE = '.redis-test-info.json';
20
+
21
+ export interface TestRedisEndpoint {
22
+ host: string;
23
+ port: number;
24
+ /** True when no real Redis was available and the caller should mock. */
25
+ isMock: boolean;
26
+ }
27
+
28
+ /**
29
+ * The Redis a test suite should talk to.
30
+ *
31
+ * Four packages had grown their own copy of this resolution, and each copy
32
+ * ended in a hard-coded `TEST_REDIS_PORT ?? 16379` — the `redis-test` service
33
+ * in the monorepo's `docker-compose.test.yml`. That is a fine default and a
34
+ * terrible fallback: with no `globalSetup` registered, the earlier steps can
35
+ * never answer, and nothing listens on 16379 unless that compose file is up.
36
+ * Suites then hung until the 120 s per-test timeout rather than failing, which
37
+ * reads as "slow" instead of "misconfigured".
38
+ *
39
+ * Order: the file a `globalSetup` published, then `globalThis.globalRedis`
40
+ * (set in the main process, so workers rarely see it), then `USE_MOCK_REDIS` /
41
+ * `SKIP_DOCKER_TESTS`, then the compose default.
42
+ *
43
+ * It deliberately does NOT fall back to 6379. A Redis answering on the default
44
+ * port is whatever the developer happens to be running — on a machine with the
45
+ * downstream stand up, that is main/storage/messaging/pricing/payments/geo in
46
+ * db0..db5, and these suites call `flushdb`. titan's `globalSetup` will only
47
+ * use 6379 when `TEST_REDIS_ALLOW_DEFAULT_PORT=true` says so, and publishes
48
+ * the choice here.
49
+ */
50
+ export function resolveTestRedisEndpoint(): TestRedisEndpoint {
51
+ try {
52
+ const infoPath = process.env['TITAN_TEST_REDIS_INFO'] ?? join(process.cwd(), REDIS_INFO_FILE);
53
+ if (existsSync(infoPath)) {
54
+ const info = JSON.parse(readFileSync(infoPath, 'utf-8')) as {
55
+ port?: number;
56
+ isMock?: boolean;
57
+ };
58
+ if (info.isMock) return { host: 'localhost', port: 0, isMock: true };
59
+ if (info.port) return { host: 'localhost', port: info.port, isMock: false };
60
+ }
61
+ } catch {
62
+ // A malformed or half-written file is not a reason to fail the suite;
63
+ // fall through to the other sources.
64
+ }
65
+
66
+ const fromGlobal = (globalThis as { globalRedis?: { host?: string; port?: number } }).globalRedis;
67
+ if (fromGlobal?.port) {
68
+ return { host: fromGlobal.host ?? 'localhost', port: fromGlobal.port, isMock: false };
69
+ }
70
+
71
+ if (process.env['USE_MOCK_REDIS'] === 'true' || process.env['SKIP_DOCKER_TESTS'] === 'true') {
72
+ return { host: 'localhost', port: 0, isMock: true };
73
+ }
74
+
75
+ return {
76
+ host: process.env['TEST_REDIS_HOST'] ?? 'localhost',
77
+ port: Number(process.env['TEST_REDIS_PORT'] ?? 16379),
78
+ isMock: false,
79
+ };
80
+ }
81
+
15
82
  /**
16
83
  * Create a null logger for testing
17
84
  */
@@ -64,12 +131,16 @@ export interface RedisTestFixture {
64
131
  * Create a Redis test fixture with proper cleanup
65
132
  */
66
133
  export async function createRedisTestFixture(options: RedisTestFixtureOptions = {}): Promise<RedisTestFixture> {
134
+ const endpoint = resolveTestRedisEndpoint();
135
+ if (endpoint.isMock && options.port === undefined) {
136
+ throw new Error('A real Redis fixture requires a test endpoint; Redis setup selected mock mode.');
137
+ }
67
138
  const {
68
139
  withManager = false,
69
140
  withService = false,
70
141
  db = 15, // Use test database
71
- host = 'localhost',
72
- port = 6379,
142
+ host = endpoint.host,
143
+ port = endpoint.port,
73
144
  namespace = 'test',
74
145
  lazyConnect = false,
75
146
  enableReadyCheck = true,
@@ -90,66 +161,83 @@ export async function createRedisTestFixture(options: RedisTestFixtureOptions =
90
161
 
91
162
  // Create primary client
92
163
  const client = new Redis(redisOptions);
93
-
94
- // Wait for connection if not lazy
95
- if (!lazyConnect) {
96
- await new Promise<void>((resolve, reject) => {
97
- const timeout = setTimeout(() => {
98
- client.removeAllListeners();
99
- reject(Errors.timeout('Redis connection in test fixture', 10000));
100
- }, 10000); // 10 second timeout
101
-
102
- client.once('ready', () => {
103
- clearTimeout(timeout);
104
- resolve();
105
- });
106
- client.once('error', (error) => {
107
- clearTimeout(timeout);
108
- reject(error);
109
- });
110
-
111
- // Ensure connection starts
112
- if (client.status === 'wait') {
113
- client.connect().catch(reject);
114
- }
115
- });
116
- }
117
-
118
164
  let manager: RedisManager | undefined;
119
165
  let service: RedisService | undefined;
120
166
 
121
- // Create manager if requested
122
- if (withManager) {
123
- // Use type assertion to avoid ioredis version compatibility issues
124
- const clientConfigs = [
125
- {
126
- namespace: 'default',
127
- ...redisOptions,
128
- db: redisOptions.db, // Use the test DB
129
- },
130
- {
131
- namespace,
132
- ...redisOptions,
133
- db: redisOptions.db, // Use the test DB
134
- },
135
- ...(namespace !== 'cache'
136
- ? [
137
- {
138
- namespace: 'cache',
139
- ...redisOptions,
140
- db: 14, // Use different DB for cache namespace
141
- },
142
- ]
143
- : []),
144
- ] as any;
145
-
146
- manager = new RedisManager({ clients: clientConfigs }, createTestNullLogger());
147
- await manager.onModuleInit();
148
- }
167
+ try {
168
+ // Wait for connection if not lazy
169
+ if (!lazyConnect) {
170
+ await new Promise<void>((resolve, reject) => {
171
+ const timeout = setTimeout(() => {
172
+ removeListeners();
173
+ reject(Errors.timeout('Redis connection in test fixture', 10000));
174
+ }, 10000); // 10 second timeout
175
+
176
+ const removeListeners = () => {
177
+ clearTimeout(timeout);
178
+ client.off('ready', onReady);
179
+ client.off('error', onError);
180
+ };
181
+ const onReady = () => {
182
+ removeListeners();
183
+ resolve();
184
+ };
185
+ const onError = (error: Error) => {
186
+ removeListeners();
187
+ reject(error);
188
+ };
189
+ client.once('ready', onReady);
190
+ client.once('error', onError);
191
+
192
+ // Ensure connection starts
193
+ if (client.status === 'wait') {
194
+ client.connect().catch(onError);
195
+ }
196
+ });
197
+ }
198
+
199
+ // Create manager if requested
200
+ if (withManager) {
201
+ // Use type assertion to avoid ioredis version compatibility issues
202
+ const clientConfigs = [
203
+ {
204
+ namespace: 'default',
205
+ ...redisOptions,
206
+ db: redisOptions.db, // Use the test DB
207
+ },
208
+ {
209
+ namespace,
210
+ ...redisOptions,
211
+ db: redisOptions.db, // Use the test DB
212
+ },
213
+ ...(namespace !== 'cache'
214
+ ? [
215
+ {
216
+ namespace: 'cache',
217
+ ...redisOptions,
218
+ db: 14, // Use different DB for cache namespace
219
+ },
220
+ ]
221
+ : []),
222
+ ] as any;
223
+
224
+ manager = new RedisManager({ clients: clientConfigs }, createTestNullLogger());
225
+ await manager.onModuleInit();
226
+ }
149
227
 
150
- // Create service if requested
151
- if (withService && manager) {
152
- service = new RedisService(manager);
228
+ // Create service if requested
229
+ if (withService && manager) {
230
+ service = new RedisService(manager);
231
+ }
232
+ } catch (error) {
233
+ try {
234
+ await manager?.onModuleDestroy();
235
+ } catch (cleanupError) {
236
+ throw new AggregateError([error, cleanupError], 'Redis fixture initialization and cleanup failed', { cause: cleanupError });
237
+ } finally {
238
+ client.disconnect();
239
+ }
240
+ throw error;
153
241
  }
154
242
 
155
243
  // Cleanup function
@@ -157,19 +245,13 @@ export async function createRedisTestFixture(options: RedisTestFixtureOptions =
157
245
  try {
158
246
  // Clear all data in test database
159
247
  await client.flushdb();
160
-
161
- // Cleanup manager
162
- if (manager) {
163
- await manager.onModuleDestroy();
248
+ } finally {
249
+ try {
250
+ await manager?.onModuleDestroy();
251
+ } finally {
252
+ client.disconnect();
253
+ client.removeAllListeners();
164
254
  }
165
-
166
- // Close client
167
- client.disconnect();
168
-
169
- // Remove all listeners
170
- client.removeAllListeners();
171
- } catch (error) {
172
- console.error('Cleanup error:', error);
173
255
  }
174
256
  };
175
257
 
@@ -211,17 +293,17 @@ export function createMockRedis(): any {
211
293
 
212
294
  const mock = {
213
295
  // Connection
214
- connect: jest.fn().mockResolvedValue(undefined),
215
- disconnect: jest.fn().mockImplementation(() => {
296
+ connect: vi.fn().mockResolvedValue(undefined),
297
+ disconnect: vi.fn().mockImplementation(() => {
216
298
  mock.emit('close');
217
299
  }),
218
- quit: jest.fn().mockResolvedValue('OK'),
219
- ping: jest.fn().mockResolvedValue('PONG'),
300
+ quit: vi.fn().mockResolvedValue('OK'),
301
+ ping: vi.fn().mockResolvedValue('PONG'),
220
302
 
221
303
  // Basic operations
222
- get: jest.fn().mockImplementation(async (key: string) => data.get(key) ?? null),
304
+ get: vi.fn().mockImplementation(async (key: string) => data.get(key) ?? null),
223
305
 
224
- set: jest.fn().mockImplementation(async (key: string, value: any, ...args: any[]) => {
306
+ set: vi.fn().mockImplementation(async (key: string, value: any, ...args: any[]) => {
225
307
  data.set(key, typeof value === 'object' ? JSON.stringify(value) : String(value));
226
308
 
227
309
  // Handle TTL
@@ -234,13 +316,13 @@ export function createMockRedis(): any {
234
316
  return 'OK';
235
317
  }),
236
318
 
237
- setex: jest.fn().mockImplementation(async (key: string, ttl: number, value: any) => {
319
+ setex: vi.fn().mockImplementation(async (key: string, ttl: number, value: any) => {
238
320
  data.set(key, String(value));
239
321
  setTimeout(() => data.delete(key), ttl * 1000);
240
322
  return 'OK';
241
323
  }),
242
324
 
243
- del: jest.fn().mockImplementation(async (...keys: string[]) => {
325
+ del: vi.fn().mockImplementation(async (...keys: string[]) => {
244
326
  let count = 0;
245
327
  for (const key of keys) {
246
328
  if (data.delete(key)) count++;
@@ -248,9 +330,9 @@ export function createMockRedis(): any {
248
330
  return count;
249
331
  }),
250
332
 
251
- exists: jest.fn().mockImplementation(async (...keys: string[]) => keys.filter((k) => data.has(k)).length),
333
+ exists: vi.fn().mockImplementation(async (...keys: string[]) => keys.filter((k) => data.has(k)).length),
252
334
 
253
- expire: jest.fn().mockImplementation(async (key: string, ttl: number) => {
335
+ expire: vi.fn().mockImplementation(async (key: string, ttl: number) => {
254
336
  if (data.has(key)) {
255
337
  setTimeout(() => data.delete(key), ttl * 1000);
256
338
  return 1;
@@ -258,22 +340,22 @@ export function createMockRedis(): any {
258
340
  return 0;
259
341
  }),
260
342
 
261
- ttl: jest.fn().mockImplementation(async (key: string) => (data.has(key) ? -1 : -2)),
343
+ ttl: vi.fn().mockImplementation(async (key: string) => (data.has(key) ? -1 : -2)),
262
344
 
263
- keys: jest.fn().mockImplementation(async (pattern: string) => {
345
+ keys: vi.fn().mockImplementation(async (pattern: string) => {
264
346
  if (pattern === '*') return Array.from(data.keys());
265
347
  const regex = new RegExp(pattern.replace('*', '.*'));
266
348
  return Array.from(data.keys()).filter((k) => regex.test(k));
267
349
  }),
268
350
 
269
351
  // Hash operations
270
- hget: jest.fn().mockImplementation(async (key: string, field: string) => {
352
+ hget: vi.fn().mockImplementation(async (key: string, field: string) => {
271
353
  const hash = data.get(key);
272
354
  if (!hash || typeof hash !== 'object') return null;
273
355
  return hash[field] ?? null;
274
356
  }),
275
357
 
276
- hset: jest.fn().mockImplementation(async (key: string, field: string, value: any) => {
358
+ hset: vi.fn().mockImplementation(async (key: string, field: string, value: any) => {
277
359
  let hash = data.get(key);
278
360
  if (!hash || typeof hash !== 'object') {
279
361
  hash = {};
@@ -284,13 +366,13 @@ export function createMockRedis(): any {
284
366
  return isNew ? 1 : 0;
285
367
  }),
286
368
 
287
- hgetall: jest.fn().mockImplementation(async (key: string) => {
369
+ hgetall: vi.fn().mockImplementation(async (key: string) => {
288
370
  const hash = data.get(key);
289
371
  return hash && typeof hash === 'object' ? hash : {};
290
372
  }),
291
373
 
292
374
  // List operations
293
- lpush: jest.fn().mockImplementation(async (key: string, ...values: any[]) => {
375
+ lpush: vi.fn().mockImplementation(async (key: string, ...values: any[]) => {
294
376
  let list = data.get(key);
295
377
  if (!Array.isArray(list)) {
296
378
  list = [];
@@ -300,7 +382,7 @@ export function createMockRedis(): any {
300
382
  return list.length;
301
383
  }),
302
384
 
303
- rpush: jest.fn().mockImplementation(async (key: string, ...values: any[]) => {
385
+ rpush: vi.fn().mockImplementation(async (key: string, ...values: any[]) => {
304
386
  let list = data.get(key);
305
387
  if (!Array.isArray(list)) {
306
388
  list = [];
@@ -310,26 +392,26 @@ export function createMockRedis(): any {
310
392
  return list.length;
311
393
  }),
312
394
 
313
- lpop: jest.fn().mockImplementation(async (key: string) => {
395
+ lpop: vi.fn().mockImplementation(async (key: string) => {
314
396
  const list = data.get(key);
315
397
  if (!Array.isArray(list) || list.length === 0) return null;
316
398
  return list.shift();
317
399
  }),
318
400
 
319
- rpop: jest.fn().mockImplementation(async (key: string) => {
401
+ rpop: vi.fn().mockImplementation(async (key: string) => {
320
402
  const list = data.get(key);
321
403
  if (!Array.isArray(list) || list.length === 0) return null;
322
404
  return list.pop();
323
405
  }),
324
406
 
325
- lrange: jest.fn().mockImplementation(async (key: string, start: number, stop: number) => {
407
+ lrange: vi.fn().mockImplementation(async (key: string, start: number, stop: number) => {
326
408
  const list = data.get(key);
327
409
  if (!Array.isArray(list)) return [];
328
410
  return list.slice(start, stop + 1);
329
411
  }),
330
412
 
331
413
  // Set operations
332
- sadd: jest.fn().mockImplementation(async (key: string, ...members: any[]) => {
414
+ sadd: vi.fn().mockImplementation(async (key: string, ...members: any[]) => {
333
415
  let set = data.get(key);
334
416
  if (!set || !(set instanceof Set)) {
335
417
  set = new Set();
@@ -345,41 +427,41 @@ export function createMockRedis(): any {
345
427
  return added;
346
428
  }),
347
429
 
348
- smembers: jest.fn().mockImplementation(async (key: string) => {
430
+ smembers: vi.fn().mockImplementation(async (key: string) => {
349
431
  const set = data.get(key);
350
432
  if (!set || !(set instanceof Set)) return [];
351
433
  return Array.from(set);
352
434
  }),
353
435
 
354
- sismember: jest.fn().mockImplementation(async (key: string, member: any) => {
436
+ sismember: vi.fn().mockImplementation(async (key: string, member: any) => {
355
437
  const set = data.get(key);
356
438
  if (!set || !(set instanceof Set)) return 0;
357
439
  return set.has(member) ? 1 : 0;
358
440
  }),
359
441
 
360
442
  // Pub/Sub
361
- subscribe: jest.fn().mockImplementation(async (...channels: string[]) => {
443
+ subscribe: vi.fn().mockImplementation(async (...channels: string[]) => {
362
444
  for (const channel of channels) {
363
445
  pubsub.on(channel, () => {});
364
446
  }
365
447
  return channels.length;
366
448
  }),
367
449
 
368
- unsubscribe: jest.fn().mockImplementation(async (...channels: string[]) => {
450
+ unsubscribe: vi.fn().mockImplementation(async (...channels: string[]) => {
369
451
  for (const channel of channels) {
370
452
  pubsub.removeAllListeners(channel);
371
453
  }
372
454
  return channels.length;
373
455
  }),
374
456
 
375
- publish: jest.fn().mockImplementation(async (channel: string, message: string) => {
457
+ publish: vi.fn().mockImplementation(async (channel: string, message: string) => {
376
458
  const listeners = pubsub.listenerCount(channel);
377
459
  pubsub.emit(channel, message);
378
460
  return listeners;
379
461
  }),
380
462
 
381
463
  // Transactions
382
- multi: jest.fn().mockImplementation(() => {
464
+ multi: vi.fn().mockImplementation(() => {
383
465
  const commands: any[] = [];
384
466
  const multi = {
385
467
  get: (key: string) => {
@@ -394,7 +476,7 @@ export function createMockRedis(): any {
394
476
  commands.push(['del', ...keys]);
395
477
  return multi;
396
478
  },
397
- exec: jest.fn().mockImplementation(async () => {
479
+ exec: vi.fn().mockImplementation(async () => {
398
480
  const results = [];
399
481
  for (const [cmd, ...args] of commands) {
400
482
  try {
@@ -411,7 +493,7 @@ export function createMockRedis(): any {
411
493
  }),
412
494
 
413
495
  // Lock operations (for RedisLock decorator)
414
- eval: jest.fn().mockImplementation(async (script: string, ...args: any[]) => {
496
+ eval: vi.fn().mockImplementation(async (script: string, ...args: any[]) => {
415
497
  // Simple lock implementation
416
498
  const [numKeys, ...params] = args;
417
499
  const keys = params.slice(0, numKeys);
@@ -453,40 +535,40 @@ export function createMockRedis(): any {
453
535
  }),
454
536
 
455
537
  // Utility
456
- flushdb: jest.fn().mockImplementation(async () => {
538
+ flushdb: vi.fn().mockImplementation(async () => {
457
539
  data.clear();
458
540
  locks.clear();
459
541
  return 'OK';
460
542
  }),
461
543
 
462
- flushall: jest.fn().mockImplementation(async () => {
544
+ flushall: vi.fn().mockImplementation(async () => {
463
545
  data.clear();
464
546
  locks.clear();
465
547
  return 'OK';
466
548
  }),
467
549
 
468
550
  // Event emitter methods
469
- on: jest.fn().mockImplementation((event: string, handler: (...args: any[]) => any) => {
551
+ on: vi.fn().mockImplementation((event: string, handler: (...args: any[]) => any) => {
470
552
  pubsub.on(event, handler);
471
553
  return mock;
472
554
  }),
473
555
 
474
- once: jest.fn().mockImplementation((event: string, handler: (...args: any[]) => any) => {
556
+ once: vi.fn().mockImplementation((event: string, handler: (...args: any[]) => any) => {
475
557
  pubsub.once(event, handler);
476
558
  return mock;
477
559
  }),
478
560
 
479
- off: jest.fn().mockImplementation((event: string, handler: (...args: any[]) => any) => {
561
+ off: vi.fn().mockImplementation((event: string, handler: (...args: any[]) => any) => {
480
562
  pubsub.off(event, handler);
481
563
  return mock;
482
564
  }),
483
565
 
484
- emit: jest.fn().mockImplementation((event: string, ...args: any[]) => {
566
+ emit: vi.fn().mockImplementation((event: string, ...args: any[]) => {
485
567
  pubsub.emit(event, ...args);
486
568
  return true;
487
569
  }),
488
570
 
489
- removeAllListeners: jest.fn().mockImplementation((event?: string) => {
571
+ removeAllListeners: vi.fn().mockImplementation((event?: string) => {
490
572
  if (event) {
491
573
  pubsub.removeAllListeners(event);
492
574
  } else {
@@ -496,7 +578,7 @@ export function createMockRedis(): any {
496
578
  }),
497
579
 
498
580
  // Duplicate for creating subscriber clients
499
- duplicate: jest.fn().mockImplementation(() => createMockRedis()),
581
+ duplicate: vi.fn().mockImplementation(() => createMockRedis()),
500
582
 
501
583
  // Status
502
584
  status: 'ready',
@@ -111,8 +111,8 @@ export class TestApplication {
111
111
  /**
112
112
  * Create spy for service method
113
113
  */
114
- spyOn<T>(service: T, method: keyof T): jest.SpyInstance {
115
- const spy = jest.spyOn(service as any, method as any);
114
+ spyOn<T>(service: T, method: keyof T): any {
115
+ const spy = vi.spyOn(service as any, method as any);
116
116
  this.addCleanup(() => spy.mockRestore());
117
117
  return spy;
118
118
  }
@@ -120,7 +120,6 @@ export const TestConfigs = {
120
120
  } as ConfigModuleOptions,
121
121
 
122
122
  withValidation: {
123
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
124
123
  schema: TestSchemas.FullConfig as any,
125
124
  sources: [
126
125
  {