@omnitron-dev/testing 0.1.3 → 0.3.0
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.
- package/dist/async/events.js.map +1 -1
- package/dist/async/retry.js.map +1 -1
- package/dist/async/wait.js.map +1 -1
- package/dist/docker/database-manager.js.map +1 -1
- package/dist/docker/docker-test-manager.d.ts +8 -0
- package/dist/docker/docker-test-manager.js +194 -45
- package/dist/docker/docker-test-manager.js.map +1 -1
- package/dist/docker/redis-manager.js +24 -50
- package/dist/docker/redis-manager.js.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/runtime/bun-adapter.d.ts +23 -1
- package/dist/runtime/bun-adapter.js +3 -0
- package/dist/runtime/bun-adapter.js.map +1 -1
- package/dist/runtime/deno-adapter.d.ts +72 -16
- package/dist/runtime/deno-adapter.js +79 -77
- package/dist/runtime/deno-adapter.js.map +1 -1
- package/dist/runtime/node-adapter.d.ts +14 -2
- package/dist/titan/database/database-testing.module.d.ts +1 -1
- package/dist/titan/database/database-testing.module.js.map +1 -1
- package/dist/titan/database/test-utilities.d.ts +1 -1
- package/dist/titan/database/test-utilities.js +1 -1
- package/dist/titan/database/test-utilities.js.map +1 -1
- package/dist/titan/index.d.ts +2 -2
- package/dist/titan/index.js +1 -1
- package/dist/titan/index.js.map +1 -1
- package/dist/titan/nexus/mock-provider.js.map +1 -1
- package/dist/titan/nexus/test-container.js.map +1 -1
- package/dist/titan/nexus/test-utilities.js.map +1 -1
- package/dist/titan/pm/mock-process-spawner.js.map +1 -1
- package/dist/titan/pm/mock-spawner.js.map +1 -1
- package/dist/titan/pm/test-process-manager.js.map +1 -1
- package/dist/titan/redis-test-utils.d.ts +6 -0
- package/dist/titan/redis-test-utils.js +29 -0
- package/dist/titan/redis-test-utils.js.map +1 -1
- package/dist/titan/test-application.js.map +1 -1
- package/dist/titan/test-fixtures.js.map +1 -1
- package/dist/titan/test-mocks.js.map +1 -1
- package/dist/titan/test-module.js.map +1 -1
- package/package.json +37 -30
- package/src/docker/a-port-the-network-could-reach.spec.ts +66 -0
- package/src/docker/docker-orphan-reaper.spec.ts +175 -0
- package/src/docker/docker-port-collision.spec.ts +97 -0
- package/src/docker/docker-test-manager.spec.ts +122 -0
- package/src/docker/docker-test-manager.ts +329 -20
- package/src/docker/docker-volume-cleanup.spec.ts +66 -0
- package/src/docker/redis-manager.ts +41 -58
- package/src/docker/types.ts +1 -0
- package/src/runtime/adapter-surface.spec.ts +83 -0
- package/src/runtime/bun-adapter.ts +21 -0
- package/src/runtime/deno-adapter.ts +149 -104
- package/src/titan/database/database-testing.module.ts +1 -1
- package/src/titan/database/test-utilities.ts +1 -1
- package/src/titan/index.ts +6 -1
- package/src/titan/nexus/test-utilities.ts +1 -0
- package/src/titan/pm/test-process-manager.ts +12 -2
- package/src/titan/redis-test-utils.ts +67 -0
- package/runtime/bun.d.ts +0 -2
- package/runtime/bun.js +0 -5
- package/runtime/bun.ts +0 -7
- package/runtime/deno.d.ts +0 -2
- package/runtime/deno.js +0 -4
- package/runtime/vitest.d.ts +0 -2
- package/runtime/vitest.js +0 -16
- 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
package/runtime/bun.js
DELETED
package/runtime/bun.ts
DELETED
package/runtime/deno.d.ts
DELETED
package/runtime/deno.js
DELETED
package/runtime/vitest.d.ts
DELETED
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
|
-
}
|