@jterrazz/test 8.0.0 → 9.0.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 +209 -230
- package/dist/checker.d.ts +1 -0
- package/dist/checker.js +741 -0
- package/dist/index.d.ts +1249 -728
- package/dist/index.js +3133 -1538
- package/dist/intercept.js +129 -299
- package/dist/match.js +153 -0
- package/dist/oxlint.cjs +2931 -0
- package/dist/oxlint.d.cts +150 -0
- package/dist/oxlint.d.ts +150 -0
- package/dist/oxlint.js +2925 -0
- package/package.json +47 -41
- package/dist/chunk.cjs +0 -28
- package/dist/index.cjs +0 -2264
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -980
- package/dist/index.js.map +0 -1
- package/dist/intercept.cjs +0 -323
- package/dist/intercept.cjs.map +0 -1
- package/dist/intercept.d.cts +0 -115
- package/dist/intercept.d.ts +0 -115
- package/dist/intercept.js.map +0 -1
- package/dist/intercept2.cjs +0 -81
- package/dist/intercept2.cjs.map +0 -1
- package/dist/intercept2.js +0 -81
- package/dist/intercept2.js.map +0 -1
- package/dist/mock-of.cjs +0 -32
- package/dist/mock-of.cjs.map +0 -1
- package/dist/mock-of.d.cts +0 -27
- package/dist/mock-of.d.ts +0 -27
- package/dist/mock-of.js +0 -19
- package/dist/mock-of.js.map +0 -1
- package/dist/mock.cjs +0 -4
- package/dist/mock.d.cts +0 -2
- package/dist/mock.d.ts +0 -2
- package/dist/mock.js +0 -2
- package/dist/services.cjs +0 -5
- package/dist/services.d.cts +0 -2
- package/dist/services.d.ts +0 -2
- package/dist/services.js +0 -2
- package/dist/sqlite.cjs +0 -350
- package/dist/sqlite.cjs.map +0 -1
- package/dist/sqlite.d.cts +0 -209
- package/dist/sqlite.d.ts +0 -209
- package/dist/sqlite.js +0 -331
- package/dist/sqlite.js.map +0 -1
- package/dist/types.d.cts +0 -42
- package/dist/types.d.ts +0 -42
package/dist/sqlite.d.ts
DELETED
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
//#region src/spec/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/spec/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/spec/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/services/postgres.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/services/redis.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/services/sqlite.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.d.ts.map
|
package/dist/sqlite.js
DELETED
|
@@ -1,331 +0,0 @@
|
|
|
1
|
-
import { resolve } from "node:path";
|
|
2
|
-
import { copyFileSync, existsSync, readFileSync, unlinkSync } from "node:fs";
|
|
3
|
-
import { Client } from "pg";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
import Database from "better-sqlite3";
|
|
6
|
-
//#region src/services/postgres.ts
|
|
7
|
-
var PostgresHandle = class {
|
|
8
|
-
type = "postgres";
|
|
9
|
-
composeName;
|
|
10
|
-
defaultPort = 5432;
|
|
11
|
-
defaultImage;
|
|
12
|
-
environment;
|
|
13
|
-
connectionString = "";
|
|
14
|
-
started = false;
|
|
15
|
-
client = null;
|
|
16
|
-
originalConnectionString = "";
|
|
17
|
-
schema = "public";
|
|
18
|
-
constructor(options = {}) {
|
|
19
|
-
this.composeName = options.compose ?? null;
|
|
20
|
-
this.defaultImage = options.image ?? "postgres:17";
|
|
21
|
-
this.environment = {
|
|
22
|
-
POSTGRES_DB: "test",
|
|
23
|
-
POSTGRES_PASSWORD: "test",
|
|
24
|
-
POSTGRES_USER: "test",
|
|
25
|
-
...options.env
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
buildConnectionString(host, port) {
|
|
29
|
-
return `postgresql://${this.environment.POSTGRES_USER ?? "test"}:${this.environment.POSTGRES_PASSWORD ?? "test"}@${host}:${port}/${this.environment.POSTGRES_DB ?? "test"}`;
|
|
30
|
-
}
|
|
31
|
-
createDatabaseAdapter() {
|
|
32
|
-
return this;
|
|
33
|
-
}
|
|
34
|
-
async healthcheck() {
|
|
35
|
-
if (!this.connectionString) throw new Error("postgres: cannot healthcheck — no connection string");
|
|
36
|
-
try {
|
|
37
|
-
const client = new Client({ connectionString: this.connectionString });
|
|
38
|
-
await client.connect();
|
|
39
|
-
await client.query("SELECT 1");
|
|
40
|
-
await client.end();
|
|
41
|
-
} catch (error) {
|
|
42
|
-
throw new Error(`postgres healthcheck failed: ${error.message || error.code || String(error)}`, { cause: error });
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
async initialize(composeDir) {
|
|
46
|
-
if (!this.composeName) return;
|
|
47
|
-
const initPaths = [resolve(composeDir, `${this.composeName}/init.sql`), resolve(composeDir, "postgres/init.sql")];
|
|
48
|
-
for (const initPath of initPaths) if (existsSync(initPath)) {
|
|
49
|
-
const sql = readFileSync(initPath, "utf8");
|
|
50
|
-
try {
|
|
51
|
-
await this.seed(sql);
|
|
52
|
-
} catch (error) {
|
|
53
|
-
throw new Error(`postgres init script failed (${initPath}):\n${error.message}`, { cause: error });
|
|
54
|
-
}
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
async getClient() {
|
|
59
|
-
if (this.client) return this.client;
|
|
60
|
-
const client = new Client({ connectionString: this.connectionString });
|
|
61
|
-
client.on("error", () => {
|
|
62
|
-
this.client = null;
|
|
63
|
-
});
|
|
64
|
-
await client.connect();
|
|
65
|
-
this.client = client;
|
|
66
|
-
return client;
|
|
67
|
-
}
|
|
68
|
-
async seed(sql) {
|
|
69
|
-
await (await this.getClient()).query(sql);
|
|
70
|
-
}
|
|
71
|
-
async reset() {
|
|
72
|
-
const client = await this.getClient();
|
|
73
|
-
const result = await client.query(`
|
|
74
|
-
SELECT tablename FROM pg_tables
|
|
75
|
-
WHERE schemaname = '${this.schema}'
|
|
76
|
-
AND tablename NOT LIKE '_prisma%'
|
|
77
|
-
`);
|
|
78
|
-
for (const row of result.rows) await client.query(`TRUNCATE "${this.schema}"."${row.tablename}" CASCADE`);
|
|
79
|
-
}
|
|
80
|
-
async query(table, columns) {
|
|
81
|
-
const client = await this.getClient();
|
|
82
|
-
const columnList = columns.join(", ");
|
|
83
|
-
return (await client.query(`SELECT ${columnList} FROM "${this.schema}"."${table}" ORDER BY 1`)).rows.map((row) => columns.map((col) => row[col]));
|
|
84
|
-
}
|
|
85
|
-
isolation() {
|
|
86
|
-
return {
|
|
87
|
-
acquire: async (workerId) => {
|
|
88
|
-
const workerSchema = `worker_${workerId}`;
|
|
89
|
-
this.originalConnectionString = this.connectionString;
|
|
90
|
-
const client = await this.getClient();
|
|
91
|
-
await client.query(`DROP SCHEMA IF EXISTS "${workerSchema}" CASCADE`);
|
|
92
|
-
await client.query(`CREATE SCHEMA "${workerSchema}"`);
|
|
93
|
-
const tables = await client.query(`
|
|
94
|
-
SELECT tablename FROM pg_tables
|
|
95
|
-
WHERE schemaname = 'public'
|
|
96
|
-
AND tablename NOT LIKE '_prisma%'
|
|
97
|
-
`);
|
|
98
|
-
for (const row of tables.rows) await client.query(`CREATE TABLE "${workerSchema}"."${row.tablename}" (LIKE "public"."${row.tablename}" INCLUDING ALL)`);
|
|
99
|
-
this.schema = workerSchema;
|
|
100
|
-
await client.query(`SET search_path TO "${workerSchema}", public`);
|
|
101
|
-
const url = new URL(this.connectionString);
|
|
102
|
-
url.searchParams.set("options", `-c search_path=${workerSchema},public`);
|
|
103
|
-
this.connectionString = url.toString();
|
|
104
|
-
},
|
|
105
|
-
reset: async () => {
|
|
106
|
-
await this.reset();
|
|
107
|
-
},
|
|
108
|
-
release: async () => {
|
|
109
|
-
const client = await this.getClient();
|
|
110
|
-
const workerSchema = this.schema;
|
|
111
|
-
this.schema = "public";
|
|
112
|
-
this.connectionString = this.originalConnectionString;
|
|
113
|
-
await client.query(`SET search_path TO public`);
|
|
114
|
-
await client.query(`DROP SCHEMA IF EXISTS "${workerSchema}" CASCADE`);
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
/**
|
|
120
|
-
* Create a PostgreSQL service handle.
|
|
121
|
-
*
|
|
122
|
-
* @example
|
|
123
|
-
* const db = postgres({ compose: "db" });
|
|
124
|
-
* // After start: db.connectionString is populated
|
|
125
|
-
*/
|
|
126
|
-
function postgres(options = {}) {
|
|
127
|
-
return new PostgresHandle(options);
|
|
128
|
-
}
|
|
129
|
-
//#endregion
|
|
130
|
-
//#region src/services/redis.ts
|
|
131
|
-
var RedisHandle = class {
|
|
132
|
-
type = "redis";
|
|
133
|
-
composeName;
|
|
134
|
-
defaultPort = 6379;
|
|
135
|
-
defaultImage;
|
|
136
|
-
environment = {};
|
|
137
|
-
connectionString = "";
|
|
138
|
-
started = false;
|
|
139
|
-
dbIndex = 0;
|
|
140
|
-
constructor(options = {}) {
|
|
141
|
-
this.composeName = options.compose ?? null;
|
|
142
|
-
this.defaultImage = options.image ?? "redis:7";
|
|
143
|
-
}
|
|
144
|
-
buildConnectionString(host, port) {
|
|
145
|
-
return `redis://${host}:${port}`;
|
|
146
|
-
}
|
|
147
|
-
createDatabaseAdapter() {
|
|
148
|
-
return null;
|
|
149
|
-
}
|
|
150
|
-
async healthcheck() {
|
|
151
|
-
if (!this.connectionString) throw new Error("redis: cannot healthcheck — no connection string");
|
|
152
|
-
try {
|
|
153
|
-
const { createClient } = await import("redis");
|
|
154
|
-
const client = createClient({ url: this.connectionString });
|
|
155
|
-
await client.connect();
|
|
156
|
-
await client.ping();
|
|
157
|
-
await client.disconnect();
|
|
158
|
-
} catch (error) {
|
|
159
|
-
throw new Error(`redis healthcheck failed: ${error.message || error.code || String(error)}`, { cause: error });
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
async initialize() {}
|
|
163
|
-
async reset() {
|
|
164
|
-
const { createClient } = await import("redis");
|
|
165
|
-
const client = createClient({
|
|
166
|
-
url: this.connectionString,
|
|
167
|
-
database: this.dbIndex
|
|
168
|
-
});
|
|
169
|
-
await client.connect();
|
|
170
|
-
try {
|
|
171
|
-
await client.flushDb();
|
|
172
|
-
} finally {
|
|
173
|
-
await client.disconnect();
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
isolation() {
|
|
177
|
-
return {
|
|
178
|
-
acquire: async (workerId) => {
|
|
179
|
-
this.dbIndex = (Number.parseInt(workerId, 10) || 0) % 15 + 1;
|
|
180
|
-
},
|
|
181
|
-
reset: async () => {
|
|
182
|
-
await this.reset();
|
|
183
|
-
},
|
|
184
|
-
release: async () => {
|
|
185
|
-
await this.reset();
|
|
186
|
-
this.dbIndex = 0;
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
/**
|
|
192
|
-
* Create a Redis service handle.
|
|
193
|
-
*
|
|
194
|
-
* @example
|
|
195
|
-
* const cache = redis({ compose: "cache" });
|
|
196
|
-
* // After start: cache.connectionString is populated
|
|
197
|
-
*/
|
|
198
|
-
function redis(options = {}) {
|
|
199
|
-
return new RedisHandle(options);
|
|
200
|
-
}
|
|
201
|
-
//#endregion
|
|
202
|
-
//#region src/services/sqlite.ts
|
|
203
|
-
var SqliteHandle = class {
|
|
204
|
-
type = "sqlite";
|
|
205
|
-
composeName = null;
|
|
206
|
-
defaultPort = 0;
|
|
207
|
-
defaultImage = "";
|
|
208
|
-
environment = {};
|
|
209
|
-
connectionString = "";
|
|
210
|
-
started = false;
|
|
211
|
-
db = null;
|
|
212
|
-
templatePath = "";
|
|
213
|
-
workerDbPath = "";
|
|
214
|
-
initSql;
|
|
215
|
-
prismaSchema;
|
|
216
|
-
constructor(options = {}) {
|
|
217
|
-
this.initSql = options.init ?? null;
|
|
218
|
-
this.prismaSchema = options.prismaSchema ?? null;
|
|
219
|
-
}
|
|
220
|
-
buildConnectionString() {
|
|
221
|
-
return `file:${this.workerDbPath || this.templatePath}`;
|
|
222
|
-
}
|
|
223
|
-
createDatabaseAdapter() {
|
|
224
|
-
return this;
|
|
225
|
-
}
|
|
226
|
-
async healthcheck() {}
|
|
227
|
-
async initialize() {
|
|
228
|
-
this.templatePath = resolve(tmpdir(), "jterrazz-test-sqlite-template.sqlite");
|
|
229
|
-
const lockPath = `${this.templatePath}.lock`;
|
|
230
|
-
if (existsSync(lockPath)) {
|
|
231
|
-
const start = Date.now();
|
|
232
|
-
while (existsSync(lockPath) && Date.now() - start < 3e4) await new Promise((r) => setTimeout(r, 100));
|
|
233
|
-
}
|
|
234
|
-
if (existsSync(this.templatePath)) {
|
|
235
|
-
this.connectionString = `file:${this.templatePath}`;
|
|
236
|
-
this.started = true;
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
const { writeFileSync } = await import("node:fs");
|
|
240
|
-
writeFileSync(lockPath, process.pid.toString());
|
|
241
|
-
if (this.prismaSchema) {
|
|
242
|
-
const { execSync } = await import("node:child_process");
|
|
243
|
-
execSync("npx prisma db push --force-reset", {
|
|
244
|
-
env: {
|
|
245
|
-
...process.env,
|
|
246
|
-
DATABASE_URL: `file:${this.templatePath}`,
|
|
247
|
-
PRISMA_USER_CONSENT_FOR_DANGEROUS_AI_ACTION: "yes"
|
|
248
|
-
},
|
|
249
|
-
stdio: "pipe"
|
|
250
|
-
});
|
|
251
|
-
const tmpDb = new Database(this.templatePath);
|
|
252
|
-
tmpDb.pragma("wal_checkpoint(TRUNCATE)");
|
|
253
|
-
tmpDb.close();
|
|
254
|
-
} else if (this.initSql) {
|
|
255
|
-
const sql = readFileSync(this.initSql, "utf8");
|
|
256
|
-
const templateDb = new Database(this.templatePath);
|
|
257
|
-
templateDb.exec(sql);
|
|
258
|
-
templateDb.close();
|
|
259
|
-
} else new Database(this.templatePath).close();
|
|
260
|
-
try {
|
|
261
|
-
unlinkSync(lockPath);
|
|
262
|
-
} catch {}
|
|
263
|
-
this.connectionString = `file:${this.templatePath}`;
|
|
264
|
-
this.started = true;
|
|
265
|
-
}
|
|
266
|
-
getDb() {
|
|
267
|
-
const dbPath = this.workerDbPath || this.templatePath;
|
|
268
|
-
if (!this.db) {
|
|
269
|
-
this.db = new Database(dbPath);
|
|
270
|
-
this.db.pragma("journal_mode = WAL");
|
|
271
|
-
}
|
|
272
|
-
return this.db;
|
|
273
|
-
}
|
|
274
|
-
closeDb() {
|
|
275
|
-
if (this.db) {
|
|
276
|
-
this.db.close();
|
|
277
|
-
this.db = null;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
async seed(sql) {
|
|
281
|
-
this.getDb().exec(sql);
|
|
282
|
-
}
|
|
283
|
-
async query(table, columns) {
|
|
284
|
-
const columnList = columns.join(", ");
|
|
285
|
-
return this.getDb().prepare(`SELECT ${columnList} FROM "${table}" ORDER BY 1`).all().map((row) => columns.map((col) => row[col]));
|
|
286
|
-
}
|
|
287
|
-
async reset() {
|
|
288
|
-
const db = this.getDb();
|
|
289
|
-
const tables = db.prepare(`SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE '_prisma%' AND name != 'sqlite_sequence'`).all();
|
|
290
|
-
for (const { name } of tables) db.exec(`DELETE FROM "${name}"`);
|
|
291
|
-
}
|
|
292
|
-
isolation() {
|
|
293
|
-
return {
|
|
294
|
-
acquire: async (workerId) => {
|
|
295
|
-
this.closeDb();
|
|
296
|
-
this.workerDbPath = resolve(tmpdir(), `test-worker-${workerId}-${Date.now()}.sqlite`);
|
|
297
|
-
copyFileSync(this.templatePath, this.workerDbPath);
|
|
298
|
-
this.connectionString = `file:${this.workerDbPath}`;
|
|
299
|
-
},
|
|
300
|
-
reset: async () => {
|
|
301
|
-
await this.reset();
|
|
302
|
-
},
|
|
303
|
-
release: async () => {
|
|
304
|
-
this.closeDb();
|
|
305
|
-
if (this.workerDbPath && existsSync(this.workerDbPath)) unlinkSync(this.workerDbPath);
|
|
306
|
-
this.workerDbPath = "";
|
|
307
|
-
this.connectionString = `file:${this.templatePath}`;
|
|
308
|
-
}
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
};
|
|
312
|
-
/**
|
|
313
|
-
* Create a SQLite service handle. Uses file-copy isolation for parallel tests.
|
|
314
|
-
*
|
|
315
|
-
* @example
|
|
316
|
-
* // With Prisma schema
|
|
317
|
-
* const db = sqlite({ prismaSchema: './prisma/schema' });
|
|
318
|
-
*
|
|
319
|
-
* // With raw SQL init
|
|
320
|
-
* const db = sqlite({ init: './schema.sql' });
|
|
321
|
-
*
|
|
322
|
-
* // Empty database
|
|
323
|
-
* const db = sqlite();
|
|
324
|
-
*/
|
|
325
|
-
function sqlite(options = {}) {
|
|
326
|
-
return new SqliteHandle(options);
|
|
327
|
-
}
|
|
328
|
-
//#endregion
|
|
329
|
-
export { redis as n, postgres as r, sqlite as t };
|
|
330
|
-
|
|
331
|
-
//# sourceMappingURL=sqlite.js.map
|
package/dist/sqlite.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite.js","names":[],"sources":["../src/services/postgres.ts","../src/services/redis.ts","../src/services/sqlite.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport { Client } from 'pg';\n\nimport type { DatabasePort } from '../spec/ports/database.port.js';\nimport type { IsolationStrategy } from '../spec/ports/isolation.port.js';\nimport type { ServiceHandle } from '../spec/ports/service.port.js';\n\nexport interface PostgresOptions {\n /** Map to a service in docker-compose.test.yaml. */\n compose?: string;\n /** Override image. */\n image?: string;\n /** Override environment variables. */\n env?: Record<string, string>;\n}\n\nexport class PostgresHandle implements DatabasePort, ServiceHandle {\n readonly type = 'postgres';\n readonly composeName: null | string;\n readonly defaultPort = 5432;\n readonly defaultImage: string;\n readonly environment: Record<string, string>;\n\n connectionString = '';\n started = false;\n\n private client: Client | null = null;\n private originalConnectionString = '';\n private schema = 'public';\n\n constructor(options: PostgresOptions = {}) {\n this.composeName = options.compose ?? null;\n this.defaultImage = options.image ?? 'postgres:17';\n this.environment = {\n POSTGRES_DB: 'test',\n POSTGRES_PASSWORD: 'test',\n POSTGRES_USER: 'test',\n ...options.env,\n };\n }\n\n buildConnectionString(host: string, port: number): string {\n const user = this.environment.POSTGRES_USER ?? 'test';\n const password = this.environment.POSTGRES_PASSWORD ?? 'test';\n const db = this.environment.POSTGRES_DB ?? 'test';\n return `postgresql://${user}:${password}@${host}:${port}/${db}`;\n }\n\n createDatabaseAdapter(): DatabasePort {\n return this;\n }\n\n async healthcheck(): Promise<void> {\n if (!this.connectionString) {\n throw new Error('postgres: cannot healthcheck — no connection string');\n }\n\n // Healthcheck uses a throwaway client (connection might not be established yet)\n try {\n const client = new Client({ connectionString: this.connectionString });\n await client.connect();\n await client.query('SELECT 1');\n await client.end();\n } catch (error: any) {\n throw new Error(\n `postgres healthcheck failed: ${error.message || error.code || String(error)}`,\n { cause: error },\n );\n }\n }\n\n async initialize(composeDir: string): Promise<void> {\n if (!this.composeName) {\n return;\n }\n\n const initPaths = [\n resolve(composeDir, `${this.composeName}/init.sql`),\n resolve(composeDir, 'postgres/init.sql'),\n ];\n\n for (const initPath of initPaths) {\n if (existsSync(initPath)) {\n const sql = readFileSync(initPath, 'utf8');\n try {\n await this.seed(sql);\n } catch (error: any) {\n throw new Error(\n `postgres init script failed (${initPath}):\\n${error.message}`,\n {\n cause: error,\n },\n );\n }\n return;\n }\n }\n }\n\n private async getClient(): Promise<Client> {\n if (this.client) {\n return this.client;\n }\n const client = new Client({ connectionString: this.connectionString });\n client.on('error', () => {\n // Connection dropped (container stopped) — reset so next call reconnects\n this.client = null;\n });\n await client.connect();\n this.client = client;\n return client;\n }\n\n async seed(sql: string): Promise<void> {\n const client = await this.getClient();\n await client.query(sql);\n }\n\n async reset(): Promise<void> {\n const client = await this.getClient();\n const result = await client.query(`\n SELECT tablename FROM pg_tables\n WHERE schemaname = '${this.schema}'\n AND tablename NOT LIKE '_prisma%'\n `);\n for (const row of result.rows) {\n await client.query(`TRUNCATE \"${this.schema}\".\"${row.tablename}\" CASCADE`);\n }\n }\n\n async query(table: string, columns: string[]): Promise<unknown[][]> {\n const client = await this.getClient();\n const columnList = columns.join(', ');\n const result = await client.query(\n `SELECT ${columnList} FROM \"${this.schema}\".\"${table}\" ORDER BY 1`,\n );\n return result.rows.map((row: Record<string, unknown>) => columns.map((col) => row[col]));\n }\n\n isolation(): IsolationStrategy {\n return {\n acquire: async (workerId: string) => {\n const workerSchema = `worker_${workerId}`;\n this.originalConnectionString = this.connectionString;\n const client = await this.getClient();\n\n // Create schema by cloning all tables from public\n await client.query(`DROP SCHEMA IF EXISTS \"${workerSchema}\" CASCADE`);\n await client.query(`CREATE SCHEMA \"${workerSchema}\"`);\n\n // Copy table structures (no data) from public\n const tables = await client.query(`\n SELECT tablename FROM pg_tables\n WHERE schemaname = 'public'\n AND tablename NOT LIKE '_prisma%'\n `);\n for (const row of tables.rows) {\n await client.query(\n `CREATE TABLE \"${workerSchema}\".\"${row.tablename}\" (LIKE \"public\".\"${row.tablename}\" INCLUDING ALL)`,\n );\n }\n\n // Switch this handle to use the worker schema\n this.schema = workerSchema;\n await client.query(`SET search_path TO \"${workerSchema}\", public`);\n\n // Update connectionString so app connections also use the worker schema\n const url = new URL(this.connectionString);\n url.searchParams.set('options', `-c search_path=${workerSchema},public`);\n this.connectionString = url.toString();\n },\n\n reset: async () => {\n await this.reset();\n },\n\n release: async () => {\n const client = await this.getClient();\n const workerSchema = this.schema;\n this.schema = 'public';\n this.connectionString = this.originalConnectionString;\n await client.query(`SET search_path TO public`);\n await client.query(`DROP SCHEMA IF EXISTS \"${workerSchema}\" CASCADE`);\n },\n };\n }\n}\n\n/**\n * Create a PostgreSQL service handle.\n *\n * @example\n * const db = postgres({ compose: \"db\" });\n * // After start: db.connectionString is populated\n */\nexport function postgres(options: PostgresOptions = {}): PostgresHandle {\n return new PostgresHandle(options);\n}\n","import type { DatabasePort } from '../spec/ports/database.port.js';\nimport type { IsolationStrategy } from '../spec/ports/isolation.port.js';\nimport type { ServiceHandle } from '../spec/ports/service.port.js';\n\nexport interface RedisOptions {\n /** Map to a service in docker-compose.test.yaml. */\n compose?: string;\n /** Override image. */\n image?: string;\n}\n\nexport class RedisHandle implements ServiceHandle {\n readonly type = 'redis';\n readonly composeName: null | string;\n readonly defaultPort = 6379;\n readonly defaultImage: string;\n readonly environment: Record<string, string> = {};\n\n connectionString = '';\n started = false;\n\n private dbIndex = 0;\n\n constructor(options: RedisOptions = {}) {\n this.composeName = options.compose ?? null;\n this.defaultImage = options.image ?? 'redis:7';\n }\n\n buildConnectionString(host: string, port: number): string {\n return `redis://${host}:${port}`;\n }\n\n createDatabaseAdapter(): DatabasePort | null {\n return null;\n }\n\n async healthcheck(): Promise<void> {\n if (!this.connectionString) {\n throw new Error('redis: cannot healthcheck — no connection string');\n }\n\n try {\n const { createClient } = await import('redis');\n const client = createClient({ url: this.connectionString });\n await client.connect();\n await client.ping();\n await client.disconnect();\n } catch (error: any) {\n throw new Error(\n `redis healthcheck failed: ${error.message || error.code || String(error)}`,\n {\n cause: error,\n },\n );\n }\n }\n\n async initialize(): Promise<void> {\n // Redis doesn't need initialization scripts\n }\n\n async reset(): Promise<void> {\n const { createClient } = await import('redis');\n const client = createClient({ url: this.connectionString, database: this.dbIndex });\n await client.connect();\n try {\n await client.flushDb();\n } finally {\n await client.disconnect();\n }\n }\n\n isolation(): IsolationStrategy {\n return {\n acquire: async (workerId: string) => {\n // Use Redis database index 1-15 for workers (0 is default/shared)\n const numericId = Number.parseInt(workerId, 10) || 0;\n this.dbIndex = (numericId % 15) + 1;\n },\n\n reset: async () => {\n await this.reset();\n },\n\n release: async () => {\n await this.reset();\n this.dbIndex = 0;\n },\n };\n }\n}\n\n/**\n * Create a Redis service handle.\n *\n * @example\n * const cache = redis({ compose: \"cache\" });\n * // After start: cache.connectionString is populated\n */\nexport function redis(options: RedisOptions = {}): RedisHandle {\n return new RedisHandle(options);\n}\n","import Database from 'better-sqlite3';\nimport { copyFileSync, existsSync, readFileSync, unlinkSync } from 'node:fs';\nimport { tmpdir } from 'node:os';\nimport { resolve } from 'node:path';\n\nimport type { DatabasePort } from '../spec/ports/database.port.js';\nimport type { IsolationStrategy } from '../spec/ports/isolation.port.js';\nimport type { ServiceHandle } from '../spec/ports/service.port.js';\n\nexport interface SqliteOptions {\n /**\n * Path to a SQL file used to initialize the database schema.\n * Mutually exclusive with `prismaSchema`.\n */\n init?: string;\n /**\n * Path to a Prisma schema directory or file.\n * The adapter runs `prisma db push` to create the template.\n * Mutually exclusive with `init`.\n */\n prismaSchema?: string;\n}\n\nexport class SqliteHandle implements DatabasePort, ServiceHandle {\n readonly type = 'sqlite';\n readonly composeName = null;\n readonly defaultPort = 0;\n readonly defaultImage = '';\n readonly environment: Record<string, string> = {};\n\n connectionString = '';\n started = false;\n\n private db: Database.Database | null = null;\n private templatePath = '';\n private workerDbPath = '';\n private initSql: null | string;\n private prismaSchema: null | string;\n\n constructor(options: SqliteOptions = {}) {\n this.initSql = options.init ?? null;\n this.prismaSchema = options.prismaSchema ?? null;\n }\n\n buildConnectionString(): string {\n return `file:${this.workerDbPath || this.templatePath}`;\n }\n\n createDatabaseAdapter(): DatabasePort {\n return this;\n }\n\n async healthcheck(): Promise<void> {\n // SQLite is always ready — it's a file\n }\n\n async initialize(): Promise<void> {\n // Each test run gets a fresh template; workers share it via lock\n this.templatePath = resolve(tmpdir(), 'jterrazz-test-sqlite-template.sqlite');\n const lockPath = `${this.templatePath}.lock`;\n\n if (existsSync(lockPath)) {\n // Another worker is creating it — wait for it\n const start = Date.now();\n while (existsSync(lockPath) && Date.now() - start < 30_000) {\n await new Promise((r) => setTimeout(r, 100));\n }\n }\n\n if (existsSync(this.templatePath)) {\n this.connectionString = `file:${this.templatePath}`;\n this.started = true;\n return;\n }\n\n // Acquire lock\n const { writeFileSync } = await import('node:fs');\n writeFileSync(lockPath, process.pid.toString());\n\n if (this.prismaSchema) {\n // Use Prisma to create schema\n const { execSync } = await import('node:child_process');\n execSync('npx prisma db push --force-reset', {\n env: {\n ...process.env,\n DATABASE_URL: `file:${this.templatePath}`,\n PRISMA_USER_CONSENT_FOR_DANGEROUS_AI_ACTION: 'yes',\n },\n stdio: 'pipe',\n });\n\n // Checkpoint WAL so the template is a single file (safe to copy)\n const tmpDb = new Database(this.templatePath);\n tmpDb.pragma('wal_checkpoint(TRUNCATE)');\n tmpDb.close();\n } else if (this.initSql) {\n // Use raw SQL to create schema\n const sql = readFileSync(this.initSql, 'utf8');\n const templateDb = new Database(this.templatePath);\n templateDb.exec(sql);\n templateDb.close();\n } else {\n // Empty database — consumer will seed\n const templateDb = new Database(this.templatePath);\n templateDb.close();\n }\n\n // Release lock\n try {\n unlinkSync(lockPath);\n } catch {\n /* Ignore */\n }\n\n this.connectionString = `file:${this.templatePath}`;\n this.started = true;\n }\n\n private getDb(): Database.Database {\n const dbPath = this.workerDbPath || this.templatePath;\n if (!this.db) {\n this.db = new Database(dbPath);\n this.db.pragma('journal_mode = WAL');\n }\n return this.db;\n }\n\n private closeDb(): void {\n if (this.db) {\n this.db.close();\n this.db = null;\n }\n }\n\n async seed(sql: string): Promise<void> {\n this.getDb().exec(sql);\n }\n\n async query(table: string, columns: string[]): Promise<unknown[][]> {\n const columnList = columns.join(', ');\n const rows = this.getDb()\n .prepare(`SELECT ${columnList} FROM \"${table}\" ORDER BY 1`)\n .all() as Record<string, unknown>[];\n return rows.map((row) => columns.map((col) => row[col]));\n }\n\n async reset(): Promise<void> {\n const db = this.getDb();\n const tables = db\n .prepare(\n `SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE '_prisma%' AND name != 'sqlite_sequence'`,\n )\n .all() as { name: string }[];\n for (const { name } of tables) {\n db.exec(`DELETE FROM \"${name}\"`);\n }\n }\n\n isolation(): IsolationStrategy {\n return {\n acquire: async (workerId: string) => {\n this.closeDb();\n this.workerDbPath = resolve(\n tmpdir(),\n `test-worker-${workerId}-${Date.now()}.sqlite`,\n );\n copyFileSync(this.templatePath, this.workerDbPath);\n this.connectionString = `file:${this.workerDbPath}`;\n },\n\n reset: async () => {\n await this.reset();\n },\n\n release: async () => {\n this.closeDb();\n if (this.workerDbPath && existsSync(this.workerDbPath)) {\n unlinkSync(this.workerDbPath);\n }\n this.workerDbPath = '';\n this.connectionString = `file:${this.templatePath}`;\n },\n };\n }\n}\n\n/**\n * Create a SQLite service handle. Uses file-copy isolation for parallel tests.\n *\n * @example\n * // With Prisma schema\n * const db = sqlite({ prismaSchema: './prisma/schema' });\n *\n * // With raw SQL init\n * const db = sqlite({ init: './schema.sql' });\n *\n * // Empty database\n * const db = sqlite();\n */\nexport function sqlite(options: SqliteOptions = {}): SqliteHandle {\n return new SqliteHandle(options);\n}\n"],"mappings":";;;;;;AAiBA,IAAa,iBAAb,MAAmE;CAC/D,OAAgB;CAChB;CACA,cAAuB;CACvB;CACA;CAEA,mBAAmB;CACnB,UAAU;CAEV,SAAgC;CAChC,2BAAmC;CACnC,SAAiB;CAEjB,YAAY,UAA2B,EAAE,EAAE;AACvC,OAAK,cAAc,QAAQ,WAAW;AACtC,OAAK,eAAe,QAAQ,SAAS;AACrC,OAAK,cAAc;GACf,aAAa;GACb,mBAAmB;GACnB,eAAe;GACf,GAAG,QAAQ;GACd;;CAGL,sBAAsB,MAAc,MAAsB;AAItD,SAAO,gBAHM,KAAK,YAAY,iBAAiB,OAGn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WAAW,KAAK,aAAa,CAClD,YAAW,KAAK,aAAa;AAEjC,SAAK,eAAe;AACpB,SAAK,mBAAmB,QAAQ,KAAK;;GAE5C;;;;;;;;;;;;;;;;AAiBT,SAAgB,OAAO,UAAyB,EAAE,EAAgB;AAC9D,QAAO,IAAI,aAAa,QAAQ"}
|
package/dist/types.d.cts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
//#region src/spec/intercept/types.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* An intercept trigger describes which HTTP request to match.
|
|
4
|
-
*/
|
|
5
|
-
interface InterceptTrigger {
|
|
6
|
-
/** Adapter name - must match the folder prefix in file-based intercepts. */
|
|
7
|
-
adapter: string;
|
|
8
|
-
/** HTTP method to match. */
|
|
9
|
-
method: string;
|
|
10
|
-
/** URL pattern to match (string for exact prefix, RegExp for pattern). */
|
|
11
|
-
url: RegExp | string;
|
|
12
|
-
/** Optional request body matcher - the handler only fires if this returns true. */
|
|
13
|
-
match?: (body: unknown) => boolean;
|
|
14
|
-
/**
|
|
15
|
-
* Transform raw JSON data into a provider-specific response envelope.
|
|
16
|
-
* Called when .intercept(trigger, 'adapter/file.json') loads a file.
|
|
17
|
-
*/
|
|
18
|
-
wrap: (data: unknown) => InterceptResponse;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* An intercept response describes what to return when the trigger matches.
|
|
22
|
-
*/
|
|
23
|
-
interface InterceptResponse {
|
|
24
|
-
/** HTTP status code (default: 200). */
|
|
25
|
-
status?: number;
|
|
26
|
-
/** Response body (will be JSON.stringified). */
|
|
27
|
-
body: unknown;
|
|
28
|
-
/** Response headers. */
|
|
29
|
-
headers?: Record<string, string>;
|
|
30
|
-
/** Delay in ms before responding (for timeout testing). */
|
|
31
|
-
delay?: number;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* A fully resolved intercept entry ready to be registered with MSW.
|
|
35
|
-
*/
|
|
36
|
-
interface InterceptEntry {
|
|
37
|
-
trigger: InterceptTrigger;
|
|
38
|
-
response: InterceptResponse;
|
|
39
|
-
}
|
|
40
|
-
//#endregion
|
|
41
|
-
export { InterceptResponse as n, InterceptTrigger as r, InterceptEntry as t };
|
|
42
|
-
//# sourceMappingURL=types.d.cts.map
|
package/dist/types.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
//#region src/spec/intercept/types.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* An intercept trigger describes which HTTP request to match.
|
|
4
|
-
*/
|
|
5
|
-
interface InterceptTrigger {
|
|
6
|
-
/** Adapter name - must match the folder prefix in file-based intercepts. */
|
|
7
|
-
adapter: string;
|
|
8
|
-
/** HTTP method to match. */
|
|
9
|
-
method: string;
|
|
10
|
-
/** URL pattern to match (string for exact prefix, RegExp for pattern). */
|
|
11
|
-
url: RegExp | string;
|
|
12
|
-
/** Optional request body matcher - the handler only fires if this returns true. */
|
|
13
|
-
match?: (body: unknown) => boolean;
|
|
14
|
-
/**
|
|
15
|
-
* Transform raw JSON data into a provider-specific response envelope.
|
|
16
|
-
* Called when .intercept(trigger, 'adapter/file.json') loads a file.
|
|
17
|
-
*/
|
|
18
|
-
wrap: (data: unknown) => InterceptResponse;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* An intercept response describes what to return when the trigger matches.
|
|
22
|
-
*/
|
|
23
|
-
interface InterceptResponse {
|
|
24
|
-
/** HTTP status code (default: 200). */
|
|
25
|
-
status?: number;
|
|
26
|
-
/** Response body (will be JSON.stringified). */
|
|
27
|
-
body: unknown;
|
|
28
|
-
/** Response headers. */
|
|
29
|
-
headers?: Record<string, string>;
|
|
30
|
-
/** Delay in ms before responding (for timeout testing). */
|
|
31
|
-
delay?: number;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* A fully resolved intercept entry ready to be registered with MSW.
|
|
35
|
-
*/
|
|
36
|
-
interface InterceptEntry {
|
|
37
|
-
trigger: InterceptTrigger;
|
|
38
|
-
response: InterceptResponse;
|
|
39
|
-
}
|
|
40
|
-
//#endregion
|
|
41
|
-
export { InterceptResponse as n, InterceptTrigger as r, InterceptEntry as t };
|
|
42
|
-
//# sourceMappingURL=types.d.ts.map
|