@omnitron-dev/testing 0.2.0 → 0.3.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 (65) hide show
  1. package/dist/async/events.js.map +1 -1
  2. package/dist/async/retry.js.map +1 -1
  3. package/dist/async/wait.js.map +1 -1
  4. package/dist/docker/database-manager.js.map +1 -1
  5. package/dist/docker/docker-test-manager.d.ts +8 -0
  6. package/dist/docker/docker-test-manager.js +194 -45
  7. package/dist/docker/docker-test-manager.js.map +1 -1
  8. package/dist/docker/redis-manager.js +24 -50
  9. package/dist/docker/redis-manager.js.map +1 -1
  10. package/dist/errors.js.map +1 -1
  11. package/dist/index.d.ts +1 -1
  12. package/dist/runtime/bun-adapter.d.ts +23 -1
  13. package/dist/runtime/bun-adapter.js +3 -0
  14. package/dist/runtime/bun-adapter.js.map +1 -1
  15. package/dist/runtime/deno-adapter.d.ts +72 -16
  16. package/dist/runtime/deno-adapter.js +79 -77
  17. package/dist/runtime/deno-adapter.js.map +1 -1
  18. package/dist/runtime/node-adapter.d.ts +14 -2
  19. package/dist/titan/database/database-testing.module.d.ts +1 -1
  20. package/dist/titan/database/database-testing.module.js.map +1 -1
  21. package/dist/titan/database/test-utilities.d.ts +1 -1
  22. package/dist/titan/database/test-utilities.js +1 -1
  23. package/dist/titan/database/test-utilities.js.map +1 -1
  24. package/dist/titan/index.d.ts +2 -2
  25. package/dist/titan/index.js +1 -1
  26. package/dist/titan/index.js.map +1 -1
  27. package/dist/titan/nexus/mock-provider.js.map +1 -1
  28. package/dist/titan/nexus/test-container.js.map +1 -1
  29. package/dist/titan/nexus/test-utilities.js.map +1 -1
  30. package/dist/titan/pm/mock-process-spawner.js.map +1 -1
  31. package/dist/titan/pm/mock-spawner.js.map +1 -1
  32. package/dist/titan/pm/test-process-manager.js.map +1 -1
  33. package/dist/titan/redis-test-utils.d.ts +6 -0
  34. package/dist/titan/redis-test-utils.js +29 -0
  35. package/dist/titan/redis-test-utils.js.map +1 -1
  36. package/dist/titan/test-application.js.map +1 -1
  37. package/dist/titan/test-fixtures.js.map +1 -1
  38. package/dist/titan/test-mocks.js.map +1 -1
  39. package/dist/titan/test-module.js.map +1 -1
  40. package/package.json +36 -29
  41. package/src/docker/a-port-the-network-could-reach.spec.ts +66 -0
  42. package/src/docker/docker-orphan-reaper.spec.ts +175 -0
  43. package/src/docker/docker-port-collision.spec.ts +97 -0
  44. package/src/docker/docker-test-manager.spec.ts +122 -0
  45. package/src/docker/docker-test-manager.ts +329 -20
  46. package/src/docker/docker-volume-cleanup.spec.ts +66 -0
  47. package/src/docker/redis-manager.ts +41 -58
  48. package/src/docker/types.ts +1 -0
  49. package/src/runtime/adapter-surface.spec.ts +83 -0
  50. package/src/runtime/bun-adapter.ts +21 -0
  51. package/src/runtime/deno-adapter.ts +149 -104
  52. package/src/titan/database/database-testing.module.ts +1 -1
  53. package/src/titan/database/test-utilities.ts +1 -1
  54. package/src/titan/index.ts +6 -1
  55. package/src/titan/nexus/test-utilities.ts +1 -0
  56. package/src/titan/pm/test-process-manager.ts +12 -2
  57. package/src/titan/redis-test-utils.ts +67 -0
  58. package/runtime/bun.d.ts +0 -2
  59. package/runtime/bun.js +0 -5
  60. package/runtime/bun.ts +0 -7
  61. package/runtime/deno.d.ts +0 -2
  62. package/runtime/deno.js +0 -4
  63. package/runtime/vitest.d.ts +0 -2
  64. package/runtime/vitest.js +0 -16
  65. package/runtime/vitest.ts +0 -7
@@ -5,6 +5,9 @@
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
12
  import { RedisManager } from '@omnitron-dev/titan-redis';
10
13
  import { RedisService } from '@omnitron-dev/titan-redis';
@@ -12,6 +15,70 @@ 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 = 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
  */
package/runtime/bun.d.ts DELETED
@@ -1,2 +0,0 @@
1
- // Type definitions for Bun runtime adapter
2
- export {};
package/runtime/bun.js DELETED
@@ -1,5 +0,0 @@
1
- // Bun runtime adapter
2
- // This file sets up global test functions for Bun runtime
3
-
4
- // Bun already provides describe, test, expect globally
5
- // No additional setup needed
package/runtime/bun.ts DELETED
@@ -1,7 +0,0 @@
1
- /**
2
- * Bun runtime adapter
3
- * This file is imported in Bun tests to provide Jest compatibility
4
- */
5
-
6
- // Import the Bun adapter which sets up global Jest-like APIs
7
- import '../src/runtime/bun-adapter';
package/runtime/deno.d.ts DELETED
@@ -1,2 +0,0 @@
1
- // Type definitions for Deno runtime adapter
2
- export {};
package/runtime/deno.js DELETED
@@ -1,4 +0,0 @@
1
- // Deno runtime adapter
2
- // This file sets up global test functions for Deno runtime
3
-
4
- // Deno uses built-in test functions, no additional setup needed
@@ -1,2 +0,0 @@
1
- // Type definitions for Vitest runtime adapter
2
- export {};
package/runtime/vitest.js DELETED
@@ -1,16 +0,0 @@
1
- // Vitest runtime adapter
2
- // Vitest provides all globals automatically when globals: true
3
-
4
- // Re-export vitest globals if needed
5
- if (typeof globalThis !== 'undefined' && globalThis.vi) {
6
- module.exports = {
7
- describe: globalThis.describe,
8
- test: globalThis.test,
9
- it: globalThis.it,
10
- expect: globalThis.expect,
11
- beforeAll: globalThis.beforeAll,
12
- beforeEach: globalThis.beforeEach,
13
- afterEach: globalThis.afterEach,
14
- afterAll: globalThis.afterAll,
15
- };
16
- }
package/runtime/vitest.ts DELETED
@@ -1,7 +0,0 @@
1
- /**
2
- * Vitest runtime adapter
3
- * This file is imported in vitest setup for Node.js tests
4
- */
5
-
6
- // Vitest is already available in Node.js environment
7
- // This file exists for consistency across runtimes