@jterrazz/test 3.0.0 → 3.2.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/README.md +109 -60
- package/dist/assets/cpufeatures-B-FC6C9Z.node +0 -0
- package/dist/assets/sshcrypto-D82met6T.node +0 -0
- package/dist/build.cjs +122200 -0
- package/dist/build.cjs.map +1 -0
- package/dist/build.js +122193 -0
- package/dist/build.js.map +1 -0
- package/dist/chunk.cjs +64 -0
- package/dist/chunk.js +37 -0
- package/dist/dist.cjs +6587 -0
- package/dist/dist.cjs.map +1 -0
- package/dist/dist.js +6582 -0
- package/dist/dist.js.map +1 -0
- package/dist/dist2.cjs +20838 -0
- package/dist/dist2.cjs.map +1 -0
- package/dist/dist2.js +20834 -0
- package/dist/dist2.js.map +1 -0
- package/dist/index.cjs +5129 -15
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +316 -0
- package/dist/index.d.ts +316 -2
- package/dist/index.js +5119 -2
- package/dist/index.js.map +1 -1
- package/package.json +37 -17
- package/dist/msw/main.d.ts +0 -2
- package/dist/msw/main.js +0 -4
- package/dist/msw/main.js.map +0 -1
- package/dist/vitest/main.d.ts +0 -9
- package/dist/vitest/main.js +0 -9
- package/dist/vitest/main.js.map +0 -1
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { DeepMockProxy } from "vitest-mock-extended";
|
|
2
|
+
|
|
3
|
+
//#region src/mocking/mock-of-date.d.ts
|
|
4
|
+
interface MockDatePort {
|
|
5
|
+
reset: () => void;
|
|
6
|
+
set: (date: Date | number | string) => void;
|
|
7
|
+
}
|
|
8
|
+
declare const mockOfDate: MockDatePort;
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/mocking/mock-of.d.ts
|
|
11
|
+
type MockPort = <T>() => DeepMockProxy<T>;
|
|
12
|
+
declare const mockOf: MockPort;
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/specification/ports/database.port.d.ts
|
|
15
|
+
/**
|
|
16
|
+
* Abstract database interface for specification runners.
|
|
17
|
+
* Implement this to plug in your database stack.
|
|
18
|
+
*/
|
|
19
|
+
interface DatabasePort {
|
|
20
|
+
/** Execute raw SQL (for seeding test data). */
|
|
21
|
+
seed(sql: string): Promise<void>;
|
|
22
|
+
/** Query a table and return rows as arrays of values. */
|
|
23
|
+
query(table: string, columns: string[]): Promise<unknown[][]>;
|
|
24
|
+
/** Reset database to clean state between tests. */
|
|
25
|
+
reset(): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/infrastructure/services/service.port.d.ts
|
|
29
|
+
/**
|
|
30
|
+
* A service handle — returned by factory functions like postgres(), redis().
|
|
31
|
+
* Mutable: connectionString is populated after the orchestrator starts containers.
|
|
32
|
+
*/
|
|
33
|
+
interface ServiceHandle {
|
|
34
|
+
/** Service type identifier. */
|
|
35
|
+
readonly type: string;
|
|
36
|
+
/** Compose service name (if linked). */
|
|
37
|
+
readonly composeName: null | string;
|
|
38
|
+
/** Default container port for this service type. */
|
|
39
|
+
readonly defaultPort: number;
|
|
40
|
+
/** Default Docker image for this service type. */
|
|
41
|
+
readonly defaultImage: string;
|
|
42
|
+
/** Environment variables to pass to the container. */
|
|
43
|
+
readonly environment: Record<string, string>;
|
|
44
|
+
/** Connection string — populated after start. */
|
|
45
|
+
connectionString: string;
|
|
46
|
+
/** Whether this service has been started. */
|
|
47
|
+
started: boolean;
|
|
48
|
+
/** Build the connection string from host and port. */
|
|
49
|
+
buildConnectionString(host: string, port: number): string;
|
|
50
|
+
/** Create a DatabasePort adapter (if this is a database). Returns null otherwise. */
|
|
51
|
+
createDatabaseAdapter(): DatabasePort | null;
|
|
52
|
+
/** Verify the service is ready and accepting connections. Throws with context if not. */
|
|
53
|
+
healthcheck(): Promise<void>;
|
|
54
|
+
/** Run initialization scripts (e.g., init.sql). Throws with SQL error context if it fails. */
|
|
55
|
+
initialize(composeDir: string): Promise<void>;
|
|
56
|
+
/** Reset state between tests (truncate tables, flush cache, etc.) */
|
|
57
|
+
reset(): Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/infrastructure/orchestrator.d.ts
|
|
61
|
+
interface OrchestratorOptions {
|
|
62
|
+
services: ServiceHandle[];
|
|
63
|
+
mode: "e2e" | "integration";
|
|
64
|
+
root?: string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Orchestrator for test infrastructure.
|
|
68
|
+
* Integration: starts services via testcontainers.
|
|
69
|
+
* E2E: runs full docker compose up.
|
|
70
|
+
*/
|
|
71
|
+
declare class Orchestrator {
|
|
72
|
+
private services;
|
|
73
|
+
private mode;
|
|
74
|
+
private root;
|
|
75
|
+
private running;
|
|
76
|
+
private composeStack;
|
|
77
|
+
private composeHandles;
|
|
78
|
+
private started;
|
|
79
|
+
constructor(options: OrchestratorOptions);
|
|
80
|
+
/**
|
|
81
|
+
* Start declared services via testcontainers (integration mode).
|
|
82
|
+
* Reads image/env config from docker-compose.test.yaml if a service has compose: "name".
|
|
83
|
+
*/
|
|
84
|
+
start(): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Stop testcontainers (integration mode).
|
|
87
|
+
*/
|
|
88
|
+
stop(): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Start full docker compose stack (e2e mode).
|
|
91
|
+
* Auto-detects infra services and creates handles for them.
|
|
92
|
+
*/
|
|
93
|
+
startCompose(): Promise<void>;
|
|
94
|
+
/**
|
|
95
|
+
* Stop docker compose stack (e2e mode).
|
|
96
|
+
*/
|
|
97
|
+
stopCompose(): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Get a database service by compose name, or the first one if no name given.
|
|
100
|
+
*/
|
|
101
|
+
getDatabase(serviceName?: string): DatabasePort | null;
|
|
102
|
+
/**
|
|
103
|
+
* Get all database services keyed by compose name.
|
|
104
|
+
*/
|
|
105
|
+
getDatabases(): Map<string, DatabasePort>;
|
|
106
|
+
/**
|
|
107
|
+
* Get app URL from compose (e2e mode).
|
|
108
|
+
*/
|
|
109
|
+
getAppUrl(): null | string;
|
|
110
|
+
}
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/specification/ports/server.port.d.ts
|
|
113
|
+
/**
|
|
114
|
+
* HTTP response returned by a server port.
|
|
115
|
+
*/
|
|
116
|
+
interface ServerResponse {
|
|
117
|
+
status: number;
|
|
118
|
+
body: unknown;
|
|
119
|
+
headers: Record<string, string>;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Abstract server interface for specification runners.
|
|
123
|
+
* Integration mode uses in-process app, E2E mode uses real HTTP.
|
|
124
|
+
*/
|
|
125
|
+
interface ServerPort {
|
|
126
|
+
/** Send an HTTP request and return the response. */
|
|
127
|
+
request(method: string, path: string, body?: unknown): Promise<ServerResponse>;
|
|
128
|
+
}
|
|
129
|
+
//#endregion
|
|
130
|
+
//#region src/specification/specification.d.ts
|
|
131
|
+
interface SpecificationConfig {
|
|
132
|
+
database?: DatabasePort;
|
|
133
|
+
databases?: Map<string, DatabasePort>;
|
|
134
|
+
server: ServerPort;
|
|
135
|
+
}
|
|
136
|
+
interface RequestInfo {
|
|
137
|
+
method: string;
|
|
138
|
+
path: string;
|
|
139
|
+
body?: unknown;
|
|
140
|
+
}
|
|
141
|
+
declare class SpecificationResult {
|
|
142
|
+
private response;
|
|
143
|
+
private config;
|
|
144
|
+
private testDir;
|
|
145
|
+
private requestInfo;
|
|
146
|
+
constructor(response: ServerResponse, config: SpecificationConfig, testDir: string, requestInfo: RequestInfo);
|
|
147
|
+
expectStatus(code: number): this;
|
|
148
|
+
expectResponse(file: string): this;
|
|
149
|
+
expectTable(table: string, options: {
|
|
150
|
+
columns: string[];
|
|
151
|
+
rows: unknown[][];
|
|
152
|
+
service?: string;
|
|
153
|
+
}): Promise<this>;
|
|
154
|
+
private resolveDatabase;
|
|
155
|
+
}
|
|
156
|
+
declare class SpecificationBuilder {
|
|
157
|
+
private config;
|
|
158
|
+
private testDir;
|
|
159
|
+
private label;
|
|
160
|
+
private seeds;
|
|
161
|
+
private mocks;
|
|
162
|
+
private request;
|
|
163
|
+
constructor(config: SpecificationConfig, testDir: string, label: string);
|
|
164
|
+
seed(file: string, options?: {
|
|
165
|
+
service?: string;
|
|
166
|
+
}): this;
|
|
167
|
+
mock(file: string): this;
|
|
168
|
+
get(path: string): this;
|
|
169
|
+
post(path: string, bodyFile?: string): this;
|
|
170
|
+
put(path: string, bodyFile?: string): this;
|
|
171
|
+
delete(path: string): this;
|
|
172
|
+
run(): Promise<SpecificationResult>;
|
|
173
|
+
}
|
|
174
|
+
type SpecificationRunner = (label: string) => SpecificationBuilder;
|
|
175
|
+
//#endregion
|
|
176
|
+
//#region src/infrastructure/services/postgres.d.ts
|
|
177
|
+
interface PostgresOptions {
|
|
178
|
+
/** Map to a service in docker-compose.test.yaml. */
|
|
179
|
+
compose?: string;
|
|
180
|
+
/** Override image. */
|
|
181
|
+
image?: string;
|
|
182
|
+
/** Override environment variables. */
|
|
183
|
+
env?: Record<string, string>;
|
|
184
|
+
}
|
|
185
|
+
declare class PostgresHandle implements DatabasePort, ServiceHandle {
|
|
186
|
+
readonly type = "postgres";
|
|
187
|
+
readonly composeName: null | string;
|
|
188
|
+
readonly defaultPort = 5432;
|
|
189
|
+
readonly defaultImage: string;
|
|
190
|
+
readonly environment: Record<string, string>;
|
|
191
|
+
connectionString: string;
|
|
192
|
+
started: boolean;
|
|
193
|
+
constructor(options?: PostgresOptions);
|
|
194
|
+
buildConnectionString(host: string, port: number): string;
|
|
195
|
+
createDatabaseAdapter(): DatabasePort;
|
|
196
|
+
healthcheck(): Promise<void>;
|
|
197
|
+
initialize(composeDir: string): Promise<void>;
|
|
198
|
+
private getClient;
|
|
199
|
+
seed(sql: string): Promise<void>;
|
|
200
|
+
query(table: string, columns: string[]): Promise<unknown[][]>;
|
|
201
|
+
reset(): Promise<void>;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Create a PostgreSQL service handle.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* const db = postgres({ compose: "db" });
|
|
208
|
+
* // After start: db.connectionString is populated
|
|
209
|
+
*/
|
|
210
|
+
declare function postgres(options?: PostgresOptions): PostgresHandle;
|
|
211
|
+
//#endregion
|
|
212
|
+
//#region src/infrastructure/services/redis.d.ts
|
|
213
|
+
interface RedisOptions {
|
|
214
|
+
/** Map to a service in docker-compose.test.yaml. */
|
|
215
|
+
compose?: string;
|
|
216
|
+
/** Override image. */
|
|
217
|
+
image?: string;
|
|
218
|
+
}
|
|
219
|
+
declare class RedisHandle implements ServiceHandle {
|
|
220
|
+
readonly type = "redis";
|
|
221
|
+
readonly composeName: null | string;
|
|
222
|
+
readonly defaultPort = 6379;
|
|
223
|
+
readonly defaultImage: string;
|
|
224
|
+
readonly environment: Record<string, string>;
|
|
225
|
+
connectionString: string;
|
|
226
|
+
started: boolean;
|
|
227
|
+
constructor(options?: RedisOptions);
|
|
228
|
+
buildConnectionString(host: string, port: number): string;
|
|
229
|
+
createDatabaseAdapter(): DatabasePort | null;
|
|
230
|
+
healthcheck(): Promise<void>;
|
|
231
|
+
initialize(): Promise<void>;
|
|
232
|
+
reset(): Promise<void>;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Create a Redis service handle.
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* const cache = redis({ compose: "cache" });
|
|
239
|
+
* // After start: cache.connectionString is populated
|
|
240
|
+
*/
|
|
241
|
+
declare function redis(options?: RedisOptions): RedisHandle;
|
|
242
|
+
//#endregion
|
|
243
|
+
//#region src/specification/adapters/fetch.adapter.d.ts
|
|
244
|
+
/**
|
|
245
|
+
* Server adapter for real HTTP — sends actual fetch requests.
|
|
246
|
+
* Used by e2e() specification runner.
|
|
247
|
+
*/
|
|
248
|
+
declare class FetchAdapter implements ServerPort {
|
|
249
|
+
private baseUrl;
|
|
250
|
+
constructor(url: string);
|
|
251
|
+
request(method: string, path: string, body?: unknown): Promise<ServerResponse>;
|
|
252
|
+
}
|
|
253
|
+
//#endregion
|
|
254
|
+
//#region src/specification/adapters/hono.adapter.d.ts
|
|
255
|
+
/**
|
|
256
|
+
* Server adapter for Hono — in-process requests, no real HTTP.
|
|
257
|
+
* Used by integration() specification runner.
|
|
258
|
+
*/
|
|
259
|
+
declare class HonoAdapter implements ServerPort {
|
|
260
|
+
private app;
|
|
261
|
+
constructor(app: {
|
|
262
|
+
request: (path: string, init?: RequestInit) => Promise<Response> | Response;
|
|
263
|
+
});
|
|
264
|
+
request(method: string, path: string, body?: unknown): Promise<ServerResponse>;
|
|
265
|
+
}
|
|
266
|
+
//#endregion
|
|
267
|
+
//#region src/infrastructure/reporter.d.ts
|
|
268
|
+
declare function stripAnsi(str: string): string;
|
|
269
|
+
declare function normalizeOutput(str: string): string;
|
|
270
|
+
//#endregion
|
|
271
|
+
//#region src/specification/index.d.ts
|
|
272
|
+
type HonoApp = {
|
|
273
|
+
fetch: (...args: any[]) => any;
|
|
274
|
+
request: (path: string, init?: RequestInit) => Promise<Response> | Response;
|
|
275
|
+
};
|
|
276
|
+
interface IntegrationOptions {
|
|
277
|
+
/** Declared services — started via testcontainers. */
|
|
278
|
+
services: ServiceHandle[];
|
|
279
|
+
/** Factory that returns a Hono app — called after services start. */
|
|
280
|
+
app: () => HonoApp;
|
|
281
|
+
/** Project root for compose detection (relative paths supported). */
|
|
282
|
+
root?: string;
|
|
283
|
+
}
|
|
284
|
+
interface E2eOptions {
|
|
285
|
+
/** Project root — must contain docker/compose.test.yaml. */
|
|
286
|
+
root?: string;
|
|
287
|
+
}
|
|
288
|
+
interface SpecificationRunnerWithCleanup extends SpecificationRunner {
|
|
289
|
+
cleanup: () => Promise<void>;
|
|
290
|
+
orchestrator: Orchestrator;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Create an integration specification runner.
|
|
294
|
+
* Starts infra containers via testcontainers, app runs in-process.
|
|
295
|
+
*
|
|
296
|
+
* @example
|
|
297
|
+
* const db = postgres({ compose: "db" });
|
|
298
|
+
* export const spec = await integration({
|
|
299
|
+
* services: [db],
|
|
300
|
+
* app: () => createApp({ databaseUrl: db.connectionString }),
|
|
301
|
+
* });
|
|
302
|
+
*/
|
|
303
|
+
declare function integration(options: IntegrationOptions): Promise<SpecificationRunnerWithCleanup>;
|
|
304
|
+
/**
|
|
305
|
+
* Create an E2E specification runner.
|
|
306
|
+
* Starts full docker compose stack. App URL and database auto-detected.
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* export const spec = await e2e({
|
|
310
|
+
* root: "../fixtures/app",
|
|
311
|
+
* });
|
|
312
|
+
*/
|
|
313
|
+
declare function e2e(options?: E2eOptions): Promise<SpecificationRunnerWithCleanup>;
|
|
314
|
+
//#endregion
|
|
315
|
+
export { type DatabasePort, FetchAdapter, HonoAdapter, type MockDatePort, type MockPort, Orchestrator, type ServerPort, type ServerResponse, e2e, integration, mockOf, mockOfDate, normalizeOutput, postgres, redis, stripAnsi };
|
|
316
|
+
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,316 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { DeepMockProxy } from "vitest-mock-extended";
|
|
2
|
+
|
|
3
|
+
//#region src/mocking/mock-of-date.d.ts
|
|
4
|
+
interface MockDatePort {
|
|
5
|
+
reset: () => void;
|
|
6
|
+
set: (date: Date | number | string) => void;
|
|
7
|
+
}
|
|
8
|
+
declare const mockOfDate: MockDatePort;
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/mocking/mock-of.d.ts
|
|
11
|
+
type MockPort = <T>() => DeepMockProxy<T>;
|
|
12
|
+
declare const mockOf: MockPort;
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/specification/ports/database.port.d.ts
|
|
15
|
+
/**
|
|
16
|
+
* Abstract database interface for specification runners.
|
|
17
|
+
* Implement this to plug in your database stack.
|
|
18
|
+
*/
|
|
19
|
+
interface DatabasePort {
|
|
20
|
+
/** Execute raw SQL (for seeding test data). */
|
|
21
|
+
seed(sql: string): Promise<void>;
|
|
22
|
+
/** Query a table and return rows as arrays of values. */
|
|
23
|
+
query(table: string, columns: string[]): Promise<unknown[][]>;
|
|
24
|
+
/** Reset database to clean state between tests. */
|
|
25
|
+
reset(): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/infrastructure/services/service.port.d.ts
|
|
29
|
+
/**
|
|
30
|
+
* A service handle — returned by factory functions like postgres(), redis().
|
|
31
|
+
* Mutable: connectionString is populated after the orchestrator starts containers.
|
|
32
|
+
*/
|
|
33
|
+
interface ServiceHandle {
|
|
34
|
+
/** Service type identifier. */
|
|
35
|
+
readonly type: string;
|
|
36
|
+
/** Compose service name (if linked). */
|
|
37
|
+
readonly composeName: null | string;
|
|
38
|
+
/** Default container port for this service type. */
|
|
39
|
+
readonly defaultPort: number;
|
|
40
|
+
/** Default Docker image for this service type. */
|
|
41
|
+
readonly defaultImage: string;
|
|
42
|
+
/** Environment variables to pass to the container. */
|
|
43
|
+
readonly environment: Record<string, string>;
|
|
44
|
+
/** Connection string — populated after start. */
|
|
45
|
+
connectionString: string;
|
|
46
|
+
/** Whether this service has been started. */
|
|
47
|
+
started: boolean;
|
|
48
|
+
/** Build the connection string from host and port. */
|
|
49
|
+
buildConnectionString(host: string, port: number): string;
|
|
50
|
+
/** Create a DatabasePort adapter (if this is a database). Returns null otherwise. */
|
|
51
|
+
createDatabaseAdapter(): DatabasePort | null;
|
|
52
|
+
/** Verify the service is ready and accepting connections. Throws with context if not. */
|
|
53
|
+
healthcheck(): Promise<void>;
|
|
54
|
+
/** Run initialization scripts (e.g., init.sql). Throws with SQL error context if it fails. */
|
|
55
|
+
initialize(composeDir: string): Promise<void>;
|
|
56
|
+
/** Reset state between tests (truncate tables, flush cache, etc.) */
|
|
57
|
+
reset(): Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/infrastructure/orchestrator.d.ts
|
|
61
|
+
interface OrchestratorOptions {
|
|
62
|
+
services: ServiceHandle[];
|
|
63
|
+
mode: "e2e" | "integration";
|
|
64
|
+
root?: string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Orchestrator for test infrastructure.
|
|
68
|
+
* Integration: starts services via testcontainers.
|
|
69
|
+
* E2E: runs full docker compose up.
|
|
70
|
+
*/
|
|
71
|
+
declare class Orchestrator {
|
|
72
|
+
private services;
|
|
73
|
+
private mode;
|
|
74
|
+
private root;
|
|
75
|
+
private running;
|
|
76
|
+
private composeStack;
|
|
77
|
+
private composeHandles;
|
|
78
|
+
private started;
|
|
79
|
+
constructor(options: OrchestratorOptions);
|
|
80
|
+
/**
|
|
81
|
+
* Start declared services via testcontainers (integration mode).
|
|
82
|
+
* Reads image/env config from docker-compose.test.yaml if a service has compose: "name".
|
|
83
|
+
*/
|
|
84
|
+
start(): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Stop testcontainers (integration mode).
|
|
87
|
+
*/
|
|
88
|
+
stop(): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Start full docker compose stack (e2e mode).
|
|
91
|
+
* Auto-detects infra services and creates handles for them.
|
|
92
|
+
*/
|
|
93
|
+
startCompose(): Promise<void>;
|
|
94
|
+
/**
|
|
95
|
+
* Stop docker compose stack (e2e mode).
|
|
96
|
+
*/
|
|
97
|
+
stopCompose(): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Get a database service by compose name, or the first one if no name given.
|
|
100
|
+
*/
|
|
101
|
+
getDatabase(serviceName?: string): DatabasePort | null;
|
|
102
|
+
/**
|
|
103
|
+
* Get all database services keyed by compose name.
|
|
104
|
+
*/
|
|
105
|
+
getDatabases(): Map<string, DatabasePort>;
|
|
106
|
+
/**
|
|
107
|
+
* Get app URL from compose (e2e mode).
|
|
108
|
+
*/
|
|
109
|
+
getAppUrl(): null | string;
|
|
110
|
+
}
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/specification/ports/server.port.d.ts
|
|
113
|
+
/**
|
|
114
|
+
* HTTP response returned by a server port.
|
|
115
|
+
*/
|
|
116
|
+
interface ServerResponse {
|
|
117
|
+
status: number;
|
|
118
|
+
body: unknown;
|
|
119
|
+
headers: Record<string, string>;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Abstract server interface for specification runners.
|
|
123
|
+
* Integration mode uses in-process app, E2E mode uses real HTTP.
|
|
124
|
+
*/
|
|
125
|
+
interface ServerPort {
|
|
126
|
+
/** Send an HTTP request and return the response. */
|
|
127
|
+
request(method: string, path: string, body?: unknown): Promise<ServerResponse>;
|
|
128
|
+
}
|
|
129
|
+
//#endregion
|
|
130
|
+
//#region src/specification/specification.d.ts
|
|
131
|
+
interface SpecificationConfig {
|
|
132
|
+
database?: DatabasePort;
|
|
133
|
+
databases?: Map<string, DatabasePort>;
|
|
134
|
+
server: ServerPort;
|
|
135
|
+
}
|
|
136
|
+
interface RequestInfo {
|
|
137
|
+
method: string;
|
|
138
|
+
path: string;
|
|
139
|
+
body?: unknown;
|
|
140
|
+
}
|
|
141
|
+
declare class SpecificationResult {
|
|
142
|
+
private response;
|
|
143
|
+
private config;
|
|
144
|
+
private testDir;
|
|
145
|
+
private requestInfo;
|
|
146
|
+
constructor(response: ServerResponse, config: SpecificationConfig, testDir: string, requestInfo: RequestInfo);
|
|
147
|
+
expectStatus(code: number): this;
|
|
148
|
+
expectResponse(file: string): this;
|
|
149
|
+
expectTable(table: string, options: {
|
|
150
|
+
columns: string[];
|
|
151
|
+
rows: unknown[][];
|
|
152
|
+
service?: string;
|
|
153
|
+
}): Promise<this>;
|
|
154
|
+
private resolveDatabase;
|
|
155
|
+
}
|
|
156
|
+
declare class SpecificationBuilder {
|
|
157
|
+
private config;
|
|
158
|
+
private testDir;
|
|
159
|
+
private label;
|
|
160
|
+
private seeds;
|
|
161
|
+
private mocks;
|
|
162
|
+
private request;
|
|
163
|
+
constructor(config: SpecificationConfig, testDir: string, label: string);
|
|
164
|
+
seed(file: string, options?: {
|
|
165
|
+
service?: string;
|
|
166
|
+
}): this;
|
|
167
|
+
mock(file: string): this;
|
|
168
|
+
get(path: string): this;
|
|
169
|
+
post(path: string, bodyFile?: string): this;
|
|
170
|
+
put(path: string, bodyFile?: string): this;
|
|
171
|
+
delete(path: string): this;
|
|
172
|
+
run(): Promise<SpecificationResult>;
|
|
173
|
+
}
|
|
174
|
+
type SpecificationRunner = (label: string) => SpecificationBuilder;
|
|
175
|
+
//#endregion
|
|
176
|
+
//#region src/infrastructure/services/postgres.d.ts
|
|
177
|
+
interface PostgresOptions {
|
|
178
|
+
/** Map to a service in docker-compose.test.yaml. */
|
|
179
|
+
compose?: string;
|
|
180
|
+
/** Override image. */
|
|
181
|
+
image?: string;
|
|
182
|
+
/** Override environment variables. */
|
|
183
|
+
env?: Record<string, string>;
|
|
184
|
+
}
|
|
185
|
+
declare class PostgresHandle implements DatabasePort, ServiceHandle {
|
|
186
|
+
readonly type = "postgres";
|
|
187
|
+
readonly composeName: null | string;
|
|
188
|
+
readonly defaultPort = 5432;
|
|
189
|
+
readonly defaultImage: string;
|
|
190
|
+
readonly environment: Record<string, string>;
|
|
191
|
+
connectionString: string;
|
|
192
|
+
started: boolean;
|
|
193
|
+
constructor(options?: PostgresOptions);
|
|
194
|
+
buildConnectionString(host: string, port: number): string;
|
|
195
|
+
createDatabaseAdapter(): DatabasePort;
|
|
196
|
+
healthcheck(): Promise<void>;
|
|
197
|
+
initialize(composeDir: string): Promise<void>;
|
|
198
|
+
private getClient;
|
|
199
|
+
seed(sql: string): Promise<void>;
|
|
200
|
+
query(table: string, columns: string[]): Promise<unknown[][]>;
|
|
201
|
+
reset(): Promise<void>;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Create a PostgreSQL service handle.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* const db = postgres({ compose: "db" });
|
|
208
|
+
* // After start: db.connectionString is populated
|
|
209
|
+
*/
|
|
210
|
+
declare function postgres(options?: PostgresOptions): PostgresHandle;
|
|
211
|
+
//#endregion
|
|
212
|
+
//#region src/infrastructure/services/redis.d.ts
|
|
213
|
+
interface RedisOptions {
|
|
214
|
+
/** Map to a service in docker-compose.test.yaml. */
|
|
215
|
+
compose?: string;
|
|
216
|
+
/** Override image. */
|
|
217
|
+
image?: string;
|
|
218
|
+
}
|
|
219
|
+
declare class RedisHandle implements ServiceHandle {
|
|
220
|
+
readonly type = "redis";
|
|
221
|
+
readonly composeName: null | string;
|
|
222
|
+
readonly defaultPort = 6379;
|
|
223
|
+
readonly defaultImage: string;
|
|
224
|
+
readonly environment: Record<string, string>;
|
|
225
|
+
connectionString: string;
|
|
226
|
+
started: boolean;
|
|
227
|
+
constructor(options?: RedisOptions);
|
|
228
|
+
buildConnectionString(host: string, port: number): string;
|
|
229
|
+
createDatabaseAdapter(): DatabasePort | null;
|
|
230
|
+
healthcheck(): Promise<void>;
|
|
231
|
+
initialize(): Promise<void>;
|
|
232
|
+
reset(): Promise<void>;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Create a Redis service handle.
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* const cache = redis({ compose: "cache" });
|
|
239
|
+
* // After start: cache.connectionString is populated
|
|
240
|
+
*/
|
|
241
|
+
declare function redis(options?: RedisOptions): RedisHandle;
|
|
242
|
+
//#endregion
|
|
243
|
+
//#region src/specification/adapters/fetch.adapter.d.ts
|
|
244
|
+
/**
|
|
245
|
+
* Server adapter for real HTTP — sends actual fetch requests.
|
|
246
|
+
* Used by e2e() specification runner.
|
|
247
|
+
*/
|
|
248
|
+
declare class FetchAdapter implements ServerPort {
|
|
249
|
+
private baseUrl;
|
|
250
|
+
constructor(url: string);
|
|
251
|
+
request(method: string, path: string, body?: unknown): Promise<ServerResponse>;
|
|
252
|
+
}
|
|
253
|
+
//#endregion
|
|
254
|
+
//#region src/specification/adapters/hono.adapter.d.ts
|
|
255
|
+
/**
|
|
256
|
+
* Server adapter for Hono — in-process requests, no real HTTP.
|
|
257
|
+
* Used by integration() specification runner.
|
|
258
|
+
*/
|
|
259
|
+
declare class HonoAdapter implements ServerPort {
|
|
260
|
+
private app;
|
|
261
|
+
constructor(app: {
|
|
262
|
+
request: (path: string, init?: RequestInit) => Promise<Response> | Response;
|
|
263
|
+
});
|
|
264
|
+
request(method: string, path: string, body?: unknown): Promise<ServerResponse>;
|
|
265
|
+
}
|
|
266
|
+
//#endregion
|
|
267
|
+
//#region src/infrastructure/reporter.d.ts
|
|
268
|
+
declare function stripAnsi(str: string): string;
|
|
269
|
+
declare function normalizeOutput(str: string): string;
|
|
270
|
+
//#endregion
|
|
271
|
+
//#region src/specification/index.d.ts
|
|
272
|
+
type HonoApp = {
|
|
273
|
+
fetch: (...args: any[]) => any;
|
|
274
|
+
request: (path: string, init?: RequestInit) => Promise<Response> | Response;
|
|
275
|
+
};
|
|
276
|
+
interface IntegrationOptions {
|
|
277
|
+
/** Declared services — started via testcontainers. */
|
|
278
|
+
services: ServiceHandle[];
|
|
279
|
+
/** Factory that returns a Hono app — called after services start. */
|
|
280
|
+
app: () => HonoApp;
|
|
281
|
+
/** Project root for compose detection (relative paths supported). */
|
|
282
|
+
root?: string;
|
|
283
|
+
}
|
|
284
|
+
interface E2eOptions {
|
|
285
|
+
/** Project root — must contain docker/compose.test.yaml. */
|
|
286
|
+
root?: string;
|
|
287
|
+
}
|
|
288
|
+
interface SpecificationRunnerWithCleanup extends SpecificationRunner {
|
|
289
|
+
cleanup: () => Promise<void>;
|
|
290
|
+
orchestrator: Orchestrator;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Create an integration specification runner.
|
|
294
|
+
* Starts infra containers via testcontainers, app runs in-process.
|
|
295
|
+
*
|
|
296
|
+
* @example
|
|
297
|
+
* const db = postgres({ compose: "db" });
|
|
298
|
+
* export const spec = await integration({
|
|
299
|
+
* services: [db],
|
|
300
|
+
* app: () => createApp({ databaseUrl: db.connectionString }),
|
|
301
|
+
* });
|
|
302
|
+
*/
|
|
303
|
+
declare function integration(options: IntegrationOptions): Promise<SpecificationRunnerWithCleanup>;
|
|
304
|
+
/**
|
|
305
|
+
* Create an E2E specification runner.
|
|
306
|
+
* Starts full docker compose stack. App URL and database auto-detected.
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* export const spec = await e2e({
|
|
310
|
+
* root: "../fixtures/app",
|
|
311
|
+
* });
|
|
312
|
+
*/
|
|
313
|
+
declare function e2e(options?: E2eOptions): Promise<SpecificationRunnerWithCleanup>;
|
|
314
|
+
//#endregion
|
|
315
|
+
export { type DatabasePort, FetchAdapter, HonoAdapter, type MockDatePort, type MockPort, Orchestrator, type ServerPort, type ServerResponse, e2e, integration, mockOf, mockOfDate, normalizeOutput, postgres, redis, stripAnsi };
|
|
316
|
+
//# sourceMappingURL=index.d.ts.map
|