@jterrazz/test 5.3.2 → 6.1.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.
@@ -0,0 +1,209 @@
1
+ //#region src/ports/database.port.d.ts
2
+ /**
3
+ * Abstract database interface for specification runners.
4
+ * Implement this to plug in your database stack (e.g. Postgres, SQLite).
5
+ */
6
+ interface DatabasePort {
7
+ /** Execute raw SQL (for seeding test data). */
8
+ seed(sql: string): Promise<void>;
9
+ /** Query a table and return rows as arrays of values. */
10
+ query(table: string, columns: string[]): Promise<unknown[][]>;
11
+ /** Reset database to clean state between tests. */
12
+ reset(): Promise<void>;
13
+ }
14
+ //#endregion
15
+ //#region src/ports/isolation.port.d.ts
16
+ /**
17
+ * Strategy for isolating service state across parallel test workers.
18
+ *
19
+ * Each service handle provides an isolation strategy. The framework
20
+ * calls `acquire()` once per vitest worker, `reset()` before each
21
+ * `spec.run()`, and `release()` when the worker shuts down.
22
+ *
23
+ * Implement this interface to support new service types (e.g. MongoDB,
24
+ * Elasticsearch, S3).
25
+ */
26
+ interface IsolationStrategy {
27
+ /**
28
+ * Create an isolated namespace for this worker.
29
+ * Called once when the worker starts — e.g. clone a template database,
30
+ * set a Redis key prefix.
31
+ *
32
+ * @param workerId - Unique identifier for this vitest worker.
33
+ */
34
+ acquire(workerId: string): Promise<void>;
35
+ /**
36
+ * Fast reset within the namespace between `spec.run()` calls.
37
+ * E.g. truncate tables (without dropping the database).
38
+ */
39
+ reset(): Promise<void>;
40
+ /**
41
+ * Tear down the isolated namespace.
42
+ * Called once when the worker shuts down — e.g. drop the cloned database.
43
+ */
44
+ release(): Promise<void>;
45
+ }
46
+ //#endregion
47
+ //#region src/ports/service.port.d.ts
48
+ /**
49
+ * A service handle — returned by factory functions like postgres(), redis().
50
+ * Mutable: connectionString is populated after the orchestrator starts containers.
51
+ */
52
+ interface ServiceHandle {
53
+ /** Service type identifier. */
54
+ readonly type: string;
55
+ /** Compose service name (if linked). */
56
+ readonly composeName: null | string;
57
+ /** Default container port for this service type. */
58
+ readonly defaultPort: number;
59
+ /** Default Docker image for this service type. */
60
+ readonly defaultImage: string;
61
+ /** Environment variables to pass to the container. */
62
+ readonly environment: Record<string, string>;
63
+ /** Connection string — populated after start. */
64
+ connectionString: string;
65
+ /** Whether this service has been started. */
66
+ started: boolean;
67
+ /** Build the connection string from host and port. */
68
+ buildConnectionString(host: string, port: number): string;
69
+ /** Create a DatabasePort adapter (if this is a database). Returns null otherwise. */
70
+ createDatabaseAdapter(): DatabasePort | null;
71
+ /** Verify the service is ready and accepting connections. Throws with context if not. */
72
+ healthcheck(): Promise<void>;
73
+ /** Run initialization scripts (e.g., init.sql). Throws with SQL error context if it fails. */
74
+ initialize(composeDir: string): Promise<void>;
75
+ /** Reset state between tests (truncate tables, flush cache, etc.) */
76
+ reset(): Promise<void>;
77
+ /** Get the isolation strategy for parallel test execution. */
78
+ isolation(): IsolationStrategy;
79
+ }
80
+ //#endregion
81
+ //#region src/adapters/postgres.adapter.d.ts
82
+ interface PostgresOptions {
83
+ /** Map to a service in docker-compose.test.yaml. */
84
+ compose?: string;
85
+ /** Override image. */
86
+ image?: string;
87
+ /** Override environment variables. */
88
+ env?: Record<string, string>;
89
+ }
90
+ declare class PostgresHandle implements DatabasePort, ServiceHandle {
91
+ readonly type = "postgres";
92
+ readonly composeName: null | string;
93
+ readonly defaultPort = 5432;
94
+ readonly defaultImage: string;
95
+ readonly environment: Record<string, string>;
96
+ connectionString: string;
97
+ started: boolean;
98
+ private client;
99
+ private originalConnectionString;
100
+ private schema;
101
+ constructor(options?: PostgresOptions);
102
+ buildConnectionString(host: string, port: number): string;
103
+ createDatabaseAdapter(): DatabasePort;
104
+ healthcheck(): Promise<void>;
105
+ initialize(composeDir: string): Promise<void>;
106
+ private getClient;
107
+ seed(sql: string): Promise<void>;
108
+ reset(): Promise<void>;
109
+ query(table: string, columns: string[]): Promise<unknown[][]>;
110
+ isolation(): IsolationStrategy;
111
+ }
112
+ /**
113
+ * Create a PostgreSQL service handle.
114
+ *
115
+ * @example
116
+ * const db = postgres({ compose: "db" });
117
+ * // After start: db.connectionString is populated
118
+ */
119
+ declare function postgres(options?: PostgresOptions): PostgresHandle;
120
+ //#endregion
121
+ //#region src/adapters/redis.adapter.d.ts
122
+ interface RedisOptions {
123
+ /** Map to a service in docker-compose.test.yaml. */
124
+ compose?: string;
125
+ /** Override image. */
126
+ image?: string;
127
+ }
128
+ declare class RedisHandle implements ServiceHandle {
129
+ readonly type = "redis";
130
+ readonly composeName: null | string;
131
+ readonly defaultPort = 6379;
132
+ readonly defaultImage: string;
133
+ readonly environment: Record<string, string>;
134
+ connectionString: string;
135
+ started: boolean;
136
+ private dbIndex;
137
+ constructor(options?: RedisOptions);
138
+ buildConnectionString(host: string, port: number): string;
139
+ createDatabaseAdapter(): DatabasePort | null;
140
+ healthcheck(): Promise<void>;
141
+ initialize(): Promise<void>;
142
+ reset(): Promise<void>;
143
+ isolation(): IsolationStrategy;
144
+ }
145
+ /**
146
+ * Create a Redis service handle.
147
+ *
148
+ * @example
149
+ * const cache = redis({ compose: "cache" });
150
+ * // After start: cache.connectionString is populated
151
+ */
152
+ declare function redis(options?: RedisOptions): RedisHandle;
153
+ //#endregion
154
+ //#region src/adapters/sqlite.adapter.d.ts
155
+ interface SqliteOptions {
156
+ /**
157
+ * Path to a SQL file used to initialize the database schema.
158
+ * Mutually exclusive with `prismaSchema`.
159
+ */
160
+ init?: string;
161
+ /**
162
+ * Path to a Prisma schema directory or file.
163
+ * The adapter runs `prisma db push` to create the template.
164
+ * Mutually exclusive with `init`.
165
+ */
166
+ prismaSchema?: string;
167
+ }
168
+ declare class SqliteHandle implements DatabasePort, ServiceHandle {
169
+ readonly type = "sqlite";
170
+ readonly composeName: null;
171
+ readonly defaultPort = 0;
172
+ readonly defaultImage = "";
173
+ readonly environment: Record<string, string>;
174
+ connectionString: string;
175
+ started: boolean;
176
+ private db;
177
+ private templatePath;
178
+ private workerDbPath;
179
+ private initSql;
180
+ private prismaSchema;
181
+ constructor(options?: SqliteOptions);
182
+ buildConnectionString(): string;
183
+ createDatabaseAdapter(): DatabasePort;
184
+ healthcheck(): Promise<void>;
185
+ initialize(): Promise<void>;
186
+ private getDb;
187
+ private closeDb;
188
+ seed(sql: string): Promise<void>;
189
+ query(table: string, columns: string[]): Promise<unknown[][]>;
190
+ reset(): Promise<void>;
191
+ isolation(): IsolationStrategy;
192
+ }
193
+ /**
194
+ * Create a SQLite service handle. Uses file-copy isolation for parallel tests.
195
+ *
196
+ * @example
197
+ * // With Prisma schema
198
+ * const db = sqlite({ prismaSchema: './prisma/schema' });
199
+ *
200
+ * // With raw SQL init
201
+ * const db = sqlite({ init: './schema.sql' });
202
+ *
203
+ * // Empty database
204
+ * const db = sqlite();
205
+ */
206
+ declare function sqlite(options?: SqliteOptions): SqliteHandle;
207
+ //#endregion
208
+ export { PostgresOptions as a, IsolationStrategy as c, redis as i, DatabasePort as l, sqlite as n, postgres as o, RedisOptions as r, ServiceHandle as s, SqliteOptions as t };
209
+ //# sourceMappingURL=sqlite.adapter.d.cts.map
@@ -0,0 +1,209 @@
1
+ //#region src/ports/database.port.d.ts
2
+ /**
3
+ * Abstract database interface for specification runners.
4
+ * Implement this to plug in your database stack (e.g. Postgres, SQLite).
5
+ */
6
+ interface DatabasePort {
7
+ /** Execute raw SQL (for seeding test data). */
8
+ seed(sql: string): Promise<void>;
9
+ /** Query a table and return rows as arrays of values. */
10
+ query(table: string, columns: string[]): Promise<unknown[][]>;
11
+ /** Reset database to clean state between tests. */
12
+ reset(): Promise<void>;
13
+ }
14
+ //#endregion
15
+ //#region src/ports/isolation.port.d.ts
16
+ /**
17
+ * Strategy for isolating service state across parallel test workers.
18
+ *
19
+ * Each service handle provides an isolation strategy. The framework
20
+ * calls `acquire()` once per vitest worker, `reset()` before each
21
+ * `spec.run()`, and `release()` when the worker shuts down.
22
+ *
23
+ * Implement this interface to support new service types (e.g. MongoDB,
24
+ * Elasticsearch, S3).
25
+ */
26
+ interface IsolationStrategy {
27
+ /**
28
+ * Create an isolated namespace for this worker.
29
+ * Called once when the worker starts — e.g. clone a template database,
30
+ * set a Redis key prefix.
31
+ *
32
+ * @param workerId - Unique identifier for this vitest worker.
33
+ */
34
+ acquire(workerId: string): Promise<void>;
35
+ /**
36
+ * Fast reset within the namespace between `spec.run()` calls.
37
+ * E.g. truncate tables (without dropping the database).
38
+ */
39
+ reset(): Promise<void>;
40
+ /**
41
+ * Tear down the isolated namespace.
42
+ * Called once when the worker shuts down — e.g. drop the cloned database.
43
+ */
44
+ release(): Promise<void>;
45
+ }
46
+ //#endregion
47
+ //#region src/ports/service.port.d.ts
48
+ /**
49
+ * A service handle — returned by factory functions like postgres(), redis().
50
+ * Mutable: connectionString is populated after the orchestrator starts containers.
51
+ */
52
+ interface ServiceHandle {
53
+ /** Service type identifier. */
54
+ readonly type: string;
55
+ /** Compose service name (if linked). */
56
+ readonly composeName: null | string;
57
+ /** Default container port for this service type. */
58
+ readonly defaultPort: number;
59
+ /** Default Docker image for this service type. */
60
+ readonly defaultImage: string;
61
+ /** Environment variables to pass to the container. */
62
+ readonly environment: Record<string, string>;
63
+ /** Connection string — populated after start. */
64
+ connectionString: string;
65
+ /** Whether this service has been started. */
66
+ started: boolean;
67
+ /** Build the connection string from host and port. */
68
+ buildConnectionString(host: string, port: number): string;
69
+ /** Create a DatabasePort adapter (if this is a database). Returns null otherwise. */
70
+ createDatabaseAdapter(): DatabasePort | null;
71
+ /** Verify the service is ready and accepting connections. Throws with context if not. */
72
+ healthcheck(): Promise<void>;
73
+ /** Run initialization scripts (e.g., init.sql). Throws with SQL error context if it fails. */
74
+ initialize(composeDir: string): Promise<void>;
75
+ /** Reset state between tests (truncate tables, flush cache, etc.) */
76
+ reset(): Promise<void>;
77
+ /** Get the isolation strategy for parallel test execution. */
78
+ isolation(): IsolationStrategy;
79
+ }
80
+ //#endregion
81
+ //#region src/adapters/postgres.adapter.d.ts
82
+ interface PostgresOptions {
83
+ /** Map to a service in docker-compose.test.yaml. */
84
+ compose?: string;
85
+ /** Override image. */
86
+ image?: string;
87
+ /** Override environment variables. */
88
+ env?: Record<string, string>;
89
+ }
90
+ declare class PostgresHandle implements DatabasePort, ServiceHandle {
91
+ readonly type = "postgres";
92
+ readonly composeName: null | string;
93
+ readonly defaultPort = 5432;
94
+ readonly defaultImage: string;
95
+ readonly environment: Record<string, string>;
96
+ connectionString: string;
97
+ started: boolean;
98
+ private client;
99
+ private originalConnectionString;
100
+ private schema;
101
+ constructor(options?: PostgresOptions);
102
+ buildConnectionString(host: string, port: number): string;
103
+ createDatabaseAdapter(): DatabasePort;
104
+ healthcheck(): Promise<void>;
105
+ initialize(composeDir: string): Promise<void>;
106
+ private getClient;
107
+ seed(sql: string): Promise<void>;
108
+ reset(): Promise<void>;
109
+ query(table: string, columns: string[]): Promise<unknown[][]>;
110
+ isolation(): IsolationStrategy;
111
+ }
112
+ /**
113
+ * Create a PostgreSQL service handle.
114
+ *
115
+ * @example
116
+ * const db = postgres({ compose: "db" });
117
+ * // After start: db.connectionString is populated
118
+ */
119
+ declare function postgres(options?: PostgresOptions): PostgresHandle;
120
+ //#endregion
121
+ //#region src/adapters/redis.adapter.d.ts
122
+ interface RedisOptions {
123
+ /** Map to a service in docker-compose.test.yaml. */
124
+ compose?: string;
125
+ /** Override image. */
126
+ image?: string;
127
+ }
128
+ declare class RedisHandle implements ServiceHandle {
129
+ readonly type = "redis";
130
+ readonly composeName: null | string;
131
+ readonly defaultPort = 6379;
132
+ readonly defaultImage: string;
133
+ readonly environment: Record<string, string>;
134
+ connectionString: string;
135
+ started: boolean;
136
+ private dbIndex;
137
+ constructor(options?: RedisOptions);
138
+ buildConnectionString(host: string, port: number): string;
139
+ createDatabaseAdapter(): DatabasePort | null;
140
+ healthcheck(): Promise<void>;
141
+ initialize(): Promise<void>;
142
+ reset(): Promise<void>;
143
+ isolation(): IsolationStrategy;
144
+ }
145
+ /**
146
+ * Create a Redis service handle.
147
+ *
148
+ * @example
149
+ * const cache = redis({ compose: "cache" });
150
+ * // After start: cache.connectionString is populated
151
+ */
152
+ declare function redis(options?: RedisOptions): RedisHandle;
153
+ //#endregion
154
+ //#region src/adapters/sqlite.adapter.d.ts
155
+ interface SqliteOptions {
156
+ /**
157
+ * Path to a SQL file used to initialize the database schema.
158
+ * Mutually exclusive with `prismaSchema`.
159
+ */
160
+ init?: string;
161
+ /**
162
+ * Path to a Prisma schema directory or file.
163
+ * The adapter runs `prisma db push` to create the template.
164
+ * Mutually exclusive with `init`.
165
+ */
166
+ prismaSchema?: string;
167
+ }
168
+ declare class SqliteHandle implements DatabasePort, ServiceHandle {
169
+ readonly type = "sqlite";
170
+ readonly composeName: null;
171
+ readonly defaultPort = 0;
172
+ readonly defaultImage = "";
173
+ readonly environment: Record<string, string>;
174
+ connectionString: string;
175
+ started: boolean;
176
+ private db;
177
+ private templatePath;
178
+ private workerDbPath;
179
+ private initSql;
180
+ private prismaSchema;
181
+ constructor(options?: SqliteOptions);
182
+ buildConnectionString(): string;
183
+ createDatabaseAdapter(): DatabasePort;
184
+ healthcheck(): Promise<void>;
185
+ initialize(): Promise<void>;
186
+ private getDb;
187
+ private closeDb;
188
+ seed(sql: string): Promise<void>;
189
+ query(table: string, columns: string[]): Promise<unknown[][]>;
190
+ reset(): Promise<void>;
191
+ isolation(): IsolationStrategy;
192
+ }
193
+ /**
194
+ * Create a SQLite service handle. Uses file-copy isolation for parallel tests.
195
+ *
196
+ * @example
197
+ * // With Prisma schema
198
+ * const db = sqlite({ prismaSchema: './prisma/schema' });
199
+ *
200
+ * // With raw SQL init
201
+ * const db = sqlite({ init: './schema.sql' });
202
+ *
203
+ * // Empty database
204
+ * const db = sqlite();
205
+ */
206
+ declare function sqlite(options?: SqliteOptions): SqliteHandle;
207
+ //#endregion
208
+ export { PostgresOptions as a, IsolationStrategy as c, redis as i, DatabasePort as l, sqlite as n, postgres as o, RedisOptions as r, ServiceHandle as s, SqliteOptions as t };
209
+ //# sourceMappingURL=sqlite.adapter.d.ts.map