@zimic/interceptor 0.16.0-canary.5 → 0.16.0-canary.7
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 +0 -1
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/cli.mjs.map +1 -1
- package/dist/http.d.ts +180 -141
- package/dist/http.js +88 -55
- package/dist/http.js.map +1 -1
- package/dist/http.mjs +88 -56
- package/dist/http.mjs.map +1 -1
- package/package.json +2 -2
- package/src/http/index.ts +5 -2
- package/src/http/interceptor/HttpInterceptorClient.ts +30 -15
- package/src/http/interceptor/LocalHttpInterceptor.ts +8 -8
- package/src/http/interceptor/RemoteHttpInterceptor.ts +8 -8
- package/src/http/interceptor/errors/RequestSavingSafeLimitExceededError.ts +22 -0
- package/src/http/interceptor/types/options.ts +3 -10
- package/src/http/interceptor/types/public.ts +44 -12
- package/src/http/requestHandler/HttpRequestHandlerClient.ts +15 -5
- package/src/http/requestHandler/errors/DisabledRequestSavingError.ts +1 -1
- package/src/http/requestHandler/errors/TimesCheckError.ts +5 -4
- package/src/http/requestHandler/types/public.ts +16 -8
package/dist/http.d.ts
CHANGED
|
@@ -1,22 +1,4 @@
|
|
|
1
|
-
import { HttpMethodSchema, HttpRequest, HttpHeaders, HttpRequestHeadersSchema, InferPathParams, HttpSearchParams, HttpRequestSearchParamsSchema, HttpRequestBodySchema, HttpStatusCode, HttpResponseSchema, HttpHeadersInit, HttpResponse, HttpResponseHeadersSchema, HttpResponseBodySchema, HttpSchema, HttpSchemaMethod, HttpSchemaPath, HttpHeadersSchema, HttpSearchParamsSchema,
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Error thrown when a value is not valid JSON. HTTP interceptors might throw this error when trying to parse the body
|
|
5
|
-
* of a request or response with the header `'content-type': 'application/json'`, if the content cannot be parsed to
|
|
6
|
-
* JSON.
|
|
7
|
-
*/
|
|
8
|
-
declare class InvalidJSONError extends SyntaxError {
|
|
9
|
-
constructor(value: string);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Error thrown when a value is not valid {@link https://developer.mozilla.org/docs/Web/API/FormData FormData}. HTTP
|
|
14
|
-
* interceptors might throw this error when trying to parse the body of a request or response with the header
|
|
15
|
-
* `'content-type': 'multipart/form-data'`, if the content cannot be parsed to form data.
|
|
16
|
-
*/
|
|
17
|
-
declare class InvalidFormDataError extends SyntaxError {
|
|
18
|
-
constructor(value: string);
|
|
19
|
-
}
|
|
1
|
+
import { HttpMethodSchema, HttpRequest, HttpHeaders, HttpRequestHeadersSchema, InferPathParams, HttpSearchParams, HttpRequestSearchParamsSchema, HttpRequestBodySchema, HttpStatusCode, HttpResponseSchema, HttpHeadersInit, HttpResponse, HttpResponseHeadersSchema, HttpResponseBodySchema, HttpSchema, HttpBody, HttpSchemaMethod, HttpSchemaPath, HttpHeadersSchema, HttpSearchParamsSchema, HttpFormData, HttpResponseSchemaStatusCode, HttpMethod, LiteralHttpSchemaPathFromNonLiteral } from '@zimic/http';
|
|
20
2
|
|
|
21
3
|
/**
|
|
22
4
|
* An error thrown when the interceptor is running and some operation requires it to be stopped first.
|
|
@@ -54,6 +36,33 @@ declare class UnknownHttpInterceptorTypeError extends TypeError {
|
|
|
54
36
|
constructor(unknownType: unknown);
|
|
55
37
|
}
|
|
56
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Error thrown when the safe limit of saved intercepted requests is exceeded.
|
|
41
|
+
*
|
|
42
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests Saving intercepted requests}
|
|
43
|
+
*/
|
|
44
|
+
declare class RequestSavingSafeLimitExceededError extends TypeError {
|
|
45
|
+
constructor(numberOfSavedRequests: number, safeLimit: number);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Error thrown when a value is not valid {@link https://developer.mozilla.org/docs/Web/API/FormData FormData}. HTTP
|
|
50
|
+
* interceptors might throw this error when trying to parse the body of a request or response with the header
|
|
51
|
+
* `'content-type': 'multipart/form-data'`, if the content cannot be parsed to form data.
|
|
52
|
+
*/
|
|
53
|
+
declare class InvalidFormDataError extends SyntaxError {
|
|
54
|
+
constructor(value: string);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Error thrown when a value is not valid JSON. HTTP interceptors might throw this error when trying to parse the body
|
|
59
|
+
* of a request or response with the header `'content-type': 'application/json'`, if the content cannot be parsed to
|
|
60
|
+
* JSON.
|
|
61
|
+
*/
|
|
62
|
+
declare class InvalidJSONError extends SyntaxError {
|
|
63
|
+
constructor(value: string);
|
|
64
|
+
}
|
|
65
|
+
|
|
57
66
|
/**
|
|
58
67
|
* An error thrown when the browser mock service worker is not found.
|
|
59
68
|
*
|
|
@@ -151,97 +160,6 @@ interface InterceptedHttpInterceptorRequest<Path extends string, MethodSchema ex
|
|
|
151
160
|
response: StatusCode extends [never] ? never : HttpInterceptorResponse<MethodSchema, StatusCode>;
|
|
152
161
|
}
|
|
153
162
|
|
|
154
|
-
type PartialHttpHeadersOrSchema<Schema extends HttpHeadersSchema> = IfNever<Schema, never, Partial<Schema> | HttpHeaders<Partial<Schema>> | HttpHeaders<Schema>>;
|
|
155
|
-
/**
|
|
156
|
-
* A static headers restriction to match intercepted requests.
|
|
157
|
-
*
|
|
158
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
|
|
159
|
-
*/
|
|
160
|
-
type HttpRequestHandlerHeadersStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = PartialHttpHeadersOrSchema<HttpRequestHeadersSchema<Default<Schema[Path][Method]>>>;
|
|
161
|
-
type PartialHttpSearchParamsOrSchema<Schema extends HttpSearchParamsSchema> = IfNever<Schema, never, Partial<Schema> | HttpSearchParams<Partial<Schema>> | HttpSearchParams<Schema>>;
|
|
162
|
-
/**
|
|
163
|
-
* A static search params restriction to match intercepted requests.
|
|
164
|
-
*
|
|
165
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
|
|
166
|
-
*/
|
|
167
|
-
type HttpRequestHandlerSearchParamsStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = PartialHttpSearchParamsOrSchema<HttpRequestSearchParamsSchema<Default<Schema[Path][Method]>>>;
|
|
168
|
-
type PartialBodyOrSchema<Body extends HttpBody> = Body extends HttpFormData<infer Schema> ? HttpFormData<Partial<Schema>> | HttpFormData<Schema> : Body extends HttpSearchParams<infer Schema> ? HttpSearchParams<Partial<Schema>> | HttpSearchParams<Schema> : Body extends Blob ? Body : DeepPartial<Body>;
|
|
169
|
-
/**
|
|
170
|
-
* A static body restriction to match intercepted requests.
|
|
171
|
-
*
|
|
172
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
|
|
173
|
-
*/
|
|
174
|
-
type HttpRequestHandlerBodyStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = PartialBodyOrSchema<HttpRequestBodySchema<Default<Schema[Path][Method]>>>;
|
|
175
|
-
/**
|
|
176
|
-
* A static restriction to match intercepted requests.
|
|
177
|
-
*
|
|
178
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
|
|
179
|
-
*/
|
|
180
|
-
interface HttpRequestHandlerStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> {
|
|
181
|
-
/**
|
|
182
|
-
* A set of headers that the intercepted request must contain to match the handler. If exact is `true`, the request
|
|
183
|
-
* must contain exactly these headers and no others.
|
|
184
|
-
*/
|
|
185
|
-
headers?: HttpRequestHandlerHeadersStaticRestriction<Schema, Method, Path>;
|
|
186
|
-
/**
|
|
187
|
-
* A set of search params that the intercepted request must contain to match the handler. If exact is `true`, the
|
|
188
|
-
* request must contain exactly these search params and no others.
|
|
189
|
-
*/
|
|
190
|
-
searchParams?: HttpRequestHandlerSearchParamsStaticRestriction<Schema, Method, Path>;
|
|
191
|
-
/**
|
|
192
|
-
* The body that the intercepted request must contain to match the handler. If exact is `true`, the request must
|
|
193
|
-
* contain exactly this body and no other.
|
|
194
|
-
*/
|
|
195
|
-
body?: HttpRequestHandlerBodyStaticRestriction<Schema, Method, Path>;
|
|
196
|
-
/**
|
|
197
|
-
* If `true`, the request must contain **exactly** the headers, search params, and body declared in this restriction.
|
|
198
|
-
* Otherwise, the request must contain **at least** them.
|
|
199
|
-
*/
|
|
200
|
-
exact?: boolean;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* A computed restriction to match intercepted requests.
|
|
204
|
-
*
|
|
205
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
|
|
206
|
-
*/
|
|
207
|
-
type HttpRequestHandlerComputedRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = (request: HttpInterceptorRequest<Path, Default<Schema[Path][Method]>>) => PossiblePromise<boolean>;
|
|
208
|
-
/**
|
|
209
|
-
* A restriction to match intercepted requests.
|
|
210
|
-
*
|
|
211
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
|
|
212
|
-
*/
|
|
213
|
-
type HttpRequestHandlerRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = HttpRequestHandlerStaticRestriction<Schema, Method, Path> | HttpRequestHandlerComputedRestriction<Schema, Method, Path>;
|
|
214
|
-
interface RestrictionDiff<Value> {
|
|
215
|
-
expected: Value;
|
|
216
|
-
received: Value;
|
|
217
|
-
}
|
|
218
|
-
interface RestrictionDiffs {
|
|
219
|
-
computed?: RestrictionDiff<boolean>;
|
|
220
|
-
headers?: RestrictionDiff<HttpHeaders<never>>;
|
|
221
|
-
searchParams?: RestrictionDiff<HttpSearchParams<never>>;
|
|
222
|
-
body?: RestrictionDiff<unknown>;
|
|
223
|
-
}
|
|
224
|
-
interface UnmatchedHttpInterceptorRequestGroup {
|
|
225
|
-
request: HttpInterceptorRequest<string, never>;
|
|
226
|
-
diff: RestrictionDiffs;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
declare class TimesDeclarationPointer extends Error {
|
|
230
|
-
constructor(minNumberOfRequests: number, maxNumberOfRequests?: number);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
interface TimesCheckErrorOptions {
|
|
234
|
-
requestLimits: Range<number>;
|
|
235
|
-
numberOfMatchedRequests: number;
|
|
236
|
-
declarationPointer: TimesDeclarationPointer | undefined;
|
|
237
|
-
unmatchedRequestGroups: UnmatchedHttpInterceptorRequestGroup[];
|
|
238
|
-
hasRestrictions: boolean;
|
|
239
|
-
hasSavedRequests: boolean;
|
|
240
|
-
}
|
|
241
|
-
declare class TimesCheckError extends TypeError {
|
|
242
|
-
constructor(options: TimesCheckErrorOptions);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
163
|
type UnhandledHttpInterceptorRequestMethodSchema = HttpSchema.Method<{
|
|
246
164
|
request: {
|
|
247
165
|
headers: Record<string, string>;
|
|
@@ -351,20 +269,12 @@ interface SharedHttpInterceptorOptions {
|
|
|
351
269
|
*/
|
|
352
270
|
baseURL: string;
|
|
353
271
|
/**
|
|
354
|
-
*
|
|
355
|
-
* should save their intercepted requests in memory and make them accessible through
|
|
356
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerrequests `handler.requests`}.
|
|
357
|
-
*
|
|
358
|
-
* **Important**: If `saveRequests` is true, make sure to regularly clear the interceptor to avoid that the requests
|
|
359
|
-
* accumulate in memory. A common practice is to call
|
|
360
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorclear `interceptor.clear()`}
|
|
361
|
-
* after each test.
|
|
272
|
+
* Configures if the intercepted requests are saved and how they are handled.
|
|
362
273
|
*
|
|
363
|
-
* @default false
|
|
364
274
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests Saving intercepted requests}
|
|
365
275
|
* @see {@link https://github.com/zimicjs/zimic/wiki/guides‐testing‐interceptor Testing}
|
|
366
276
|
*/
|
|
367
|
-
|
|
277
|
+
requestSaving?: Partial<HttpInterceptorRequestSaving>;
|
|
368
278
|
}
|
|
369
279
|
/**
|
|
370
280
|
* The options to create a
|
|
@@ -408,6 +318,81 @@ interface RemoteHttpInterceptorOptions extends SharedHttpInterceptorOptions {
|
|
|
408
318
|
*/
|
|
409
319
|
type HttpInterceptorOptions = LocalHttpInterceptorOptions | RemoteHttpInterceptorOptions;
|
|
410
320
|
|
|
321
|
+
type PartialHttpHeadersOrSchema<Schema extends HttpHeadersSchema> = IfNever<Schema, never, Partial<Schema> | HttpHeaders<Partial<Schema>> | HttpHeaders<Schema>>;
|
|
322
|
+
/**
|
|
323
|
+
* A static headers restriction to match intercepted requests.
|
|
324
|
+
*
|
|
325
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
|
|
326
|
+
*/
|
|
327
|
+
type HttpRequestHandlerHeadersStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = PartialHttpHeadersOrSchema<HttpRequestHeadersSchema<Default<Schema[Path][Method]>>>;
|
|
328
|
+
type PartialHttpSearchParamsOrSchema<Schema extends HttpSearchParamsSchema> = IfNever<Schema, never, Partial<Schema> | HttpSearchParams<Partial<Schema>> | HttpSearchParams<Schema>>;
|
|
329
|
+
/**
|
|
330
|
+
* A static search params restriction to match intercepted requests.
|
|
331
|
+
*
|
|
332
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
|
|
333
|
+
*/
|
|
334
|
+
type HttpRequestHandlerSearchParamsStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = PartialHttpSearchParamsOrSchema<HttpRequestSearchParamsSchema<Default<Schema[Path][Method]>>>;
|
|
335
|
+
type PartialBodyOrSchema<Body extends HttpBody> = Body extends HttpFormData<infer Schema> ? HttpFormData<Partial<Schema>> | HttpFormData<Schema> : Body extends HttpSearchParams<infer Schema> ? HttpSearchParams<Partial<Schema>> | HttpSearchParams<Schema> : Body extends Blob ? Body : DeepPartial<Body>;
|
|
336
|
+
/**
|
|
337
|
+
* A static body restriction to match intercepted requests.
|
|
338
|
+
*
|
|
339
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
|
|
340
|
+
*/
|
|
341
|
+
type HttpRequestHandlerBodyStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = PartialBodyOrSchema<HttpRequestBodySchema<Default<Schema[Path][Method]>>>;
|
|
342
|
+
/**
|
|
343
|
+
* A static restriction to match intercepted requests.
|
|
344
|
+
*
|
|
345
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
|
|
346
|
+
*/
|
|
347
|
+
interface HttpRequestHandlerStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> {
|
|
348
|
+
/**
|
|
349
|
+
* A set of headers that the intercepted request must contain to match the handler. If exact is `true`, the request
|
|
350
|
+
* must contain exactly these headers and no others.
|
|
351
|
+
*/
|
|
352
|
+
headers?: HttpRequestHandlerHeadersStaticRestriction<Schema, Method, Path>;
|
|
353
|
+
/**
|
|
354
|
+
* A set of search params that the intercepted request must contain to match the handler. If exact is `true`, the
|
|
355
|
+
* request must contain exactly these search params and no others.
|
|
356
|
+
*/
|
|
357
|
+
searchParams?: HttpRequestHandlerSearchParamsStaticRestriction<Schema, Method, Path>;
|
|
358
|
+
/**
|
|
359
|
+
* The body that the intercepted request must contain to match the handler. If exact is `true`, the request must
|
|
360
|
+
* contain exactly this body and no other.
|
|
361
|
+
*/
|
|
362
|
+
body?: HttpRequestHandlerBodyStaticRestriction<Schema, Method, Path>;
|
|
363
|
+
/**
|
|
364
|
+
* If `true`, the request must contain **exactly** the headers, search params, and body declared in this restriction.
|
|
365
|
+
* Otherwise, the request must contain **at least** them.
|
|
366
|
+
*/
|
|
367
|
+
exact?: boolean;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* A computed restriction to match intercepted requests.
|
|
371
|
+
*
|
|
372
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
|
|
373
|
+
*/
|
|
374
|
+
type HttpRequestHandlerComputedRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = (request: HttpInterceptorRequest<Path, Default<Schema[Path][Method]>>) => PossiblePromise<boolean>;
|
|
375
|
+
/**
|
|
376
|
+
* A restriction to match intercepted requests.
|
|
377
|
+
*
|
|
378
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
|
|
379
|
+
*/
|
|
380
|
+
type HttpRequestHandlerRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = HttpRequestHandlerStaticRestriction<Schema, Method, Path> | HttpRequestHandlerComputedRestriction<Schema, Method, Path>;
|
|
381
|
+
interface RestrictionDiff<Value> {
|
|
382
|
+
expected: Value;
|
|
383
|
+
received: Value;
|
|
384
|
+
}
|
|
385
|
+
interface RestrictionDiffs {
|
|
386
|
+
computed?: RestrictionDiff<boolean>;
|
|
387
|
+
headers?: RestrictionDiff<HttpHeaders<never>>;
|
|
388
|
+
searchParams?: RestrictionDiff<HttpSearchParams<never>>;
|
|
389
|
+
body?: RestrictionDiff<unknown>;
|
|
390
|
+
}
|
|
391
|
+
interface UnmatchedHttpInterceptorRequestGroup {
|
|
392
|
+
request: HttpInterceptorRequest<string, never>;
|
|
393
|
+
diff: RestrictionDiffs;
|
|
394
|
+
}
|
|
395
|
+
|
|
411
396
|
/**
|
|
412
397
|
* An HTTP request handler to declare responses for intercepted requests.
|
|
413
398
|
*
|
|
@@ -512,8 +497,9 @@ interface LocalHttpRequestHandler<Schema extends HttpSchema, Method extends Http
|
|
|
512
497
|
* that was not satisfied.
|
|
513
498
|
*
|
|
514
499
|
* When
|
|
515
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#
|
|
516
|
-
*
|
|
500
|
+
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests
|
|
501
|
+
* `requestSaving.enabled`} is
|
|
502
|
+
* `true` in your interceptor, the `TimesCheckError` errors will also list each unmatched request with diff of the
|
|
517
503
|
* expected and received data. This is useful for debugging requests that did not match a handler with
|
|
518
504
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction restrictions}.
|
|
519
505
|
*
|
|
@@ -541,11 +527,14 @@ interface LocalHttpRequestHandler<Schema extends HttpSchema, Method extends Http
|
|
|
541
527
|
* The intercepted requests that matched this handler, along with the responses returned to each of them. This is
|
|
542
528
|
* useful for testing that the correct requests were made by your application.
|
|
543
529
|
*
|
|
544
|
-
* **Important**: This method can only be used if
|
|
530
|
+
* **Important**: This method can only be used if
|
|
531
|
+
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests
|
|
532
|
+
* `requestSaving.enabled`} is
|
|
533
|
+
* `true` in the interceptor. See
|
|
545
534
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests Saving intercepted requests}
|
|
546
535
|
* for more information.
|
|
547
536
|
*
|
|
548
|
-
* @throws {DisabledRequestSavingError} If the interceptor
|
|
537
|
+
* @throws {DisabledRequestSavingError} If the interceptor has `requestSaving.enabled: false`.
|
|
549
538
|
* @readonly
|
|
550
539
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerrequests `handler.requests` API reference}
|
|
551
540
|
*/
|
|
@@ -627,8 +616,9 @@ interface SyncedRemoteHttpRequestHandler<Schema extends HttpSchema, Method exten
|
|
|
627
616
|
* that was not satisfied.
|
|
628
617
|
*
|
|
629
618
|
* When
|
|
630
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#
|
|
631
|
-
*
|
|
619
|
+
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests
|
|
620
|
+
* `requestSaving.enabled`} is
|
|
621
|
+
* true in your interceptor, the `TimesCheckError` errors will also list each unmatched request with diff of the
|
|
632
622
|
* expected and received data. This is useful for debugging requests that did not match a handler with
|
|
633
623
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction restrictions}.
|
|
634
624
|
*
|
|
@@ -656,11 +646,14 @@ interface SyncedRemoteHttpRequestHandler<Schema extends HttpSchema, Method exten
|
|
|
656
646
|
* The intercepted requests that matched this handler, along with the responses returned to each of them. This is
|
|
657
647
|
* useful for testing that the correct requests were made by your application.
|
|
658
648
|
*
|
|
659
|
-
* **Important**: This method can only be used if
|
|
649
|
+
* **Important**: This method can only be used if
|
|
650
|
+
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests
|
|
651
|
+
* `requestSaving.enabled`} is
|
|
652
|
+
* `true` in the interceptor. See
|
|
660
653
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests Saving intercepted requests}
|
|
661
654
|
* for more information.
|
|
662
655
|
*
|
|
663
|
-
* @throws {DisabledRequestSavingError} If the interceptor
|
|
656
|
+
* @throws {DisabledRequestSavingError} If the interceptor has `requestSaving.enabled: false`.
|
|
664
657
|
* @readonly
|
|
665
658
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerrequests `handler.requests` API reference}
|
|
666
659
|
*/
|
|
@@ -709,6 +702,43 @@ type RemoteHttpRequestHandler<Schema extends HttpSchema, Method extends HttpSche
|
|
|
709
702
|
type SyncHttpInterceptorMethodHandler<Schema extends HttpSchema, Method extends HttpMethod> = Method extends HttpSchemaMethod<Schema> ? <Path extends HttpSchemaPath.NonLiteral<Schema, Method>>(path: Path) => LocalHttpRequestHandler<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>> : (path: never) => LocalHttpRequestHandler<any, any, never>;
|
|
710
703
|
type AsyncHttpInterceptorMethodHandler<Schema extends HttpSchema, Method extends HttpMethod> = Method extends HttpSchemaMethod<Schema> ? <Path extends HttpSchemaPath.NonLiteral<Schema, Method>>(path: Path) => RemoteHttpRequestHandler<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>> : (path: never) => RemoteHttpRequestHandler<any, any, never>;
|
|
711
704
|
|
|
705
|
+
/**
|
|
706
|
+
* Configures if the intercepted requests are saved and how they are handled.
|
|
707
|
+
*
|
|
708
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests Saving intercepted requests}
|
|
709
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/guides‐testing‐interceptor Testing}
|
|
710
|
+
*/
|
|
711
|
+
interface HttpInterceptorRequestSaving {
|
|
712
|
+
/**
|
|
713
|
+
* Whether {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httprequesthandler request handlers}
|
|
714
|
+
* should save their intercepted requests in memory and make them accessible through
|
|
715
|
+
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerrequests `handler.requests`}.
|
|
716
|
+
*
|
|
717
|
+
* If you are using
|
|
718
|
+
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorchecktimes `interceptor.checkTimes()`}
|
|
719
|
+
* or
|
|
720
|
+
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerchecktimes `handler.checkTimes()`}
|
|
721
|
+
* during tests, consider enabling this option to get more detailed information in `TimesCheckError` errors.
|
|
722
|
+
*
|
|
723
|
+
* **Important**: If `requestSaving.enabled` is `true`, make sure to regularly clear the interceptor to avoid requests
|
|
724
|
+
* accumulating in memory. A common practice is to call
|
|
725
|
+
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorclear `interceptor.clear()`}
|
|
726
|
+
* after each test.
|
|
727
|
+
*
|
|
728
|
+
* @default process.env.NODE_ENV === 'test'
|
|
729
|
+
*/
|
|
730
|
+
enabled: boolean;
|
|
731
|
+
/**
|
|
732
|
+
* The safe number of requests to save in memory before logging warnings in the console. If `requestSaving.enabled` is
|
|
733
|
+
* `true` and the interceptor is not regularly cleared with
|
|
734
|
+
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorclear `interceptor.clear()`},
|
|
735
|
+
* the requests may accumulate in memory and cause performance issues. This option does not limit the number of
|
|
736
|
+
* requests saved in memory, only when to log warnings.
|
|
737
|
+
*
|
|
738
|
+
* @default 1000
|
|
739
|
+
*/
|
|
740
|
+
safeLimit: number;
|
|
741
|
+
}
|
|
712
742
|
/**
|
|
713
743
|
* An interceptor to handle HTTP requests and return mock responses. The methods, paths, status codes, parameters, and
|
|
714
744
|
* responses are statically-typed based on the provided service schema.
|
|
@@ -723,20 +753,12 @@ interface HttpInterceptor<_Schema extends HttpSchema> {
|
|
|
723
753
|
*/
|
|
724
754
|
baseURL: string;
|
|
725
755
|
/**
|
|
726
|
-
*
|
|
727
|
-
* should save their intercepted requests in memory and make them accessible through
|
|
728
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerrequests `handler.requests`}.
|
|
729
|
-
*
|
|
730
|
-
* **Important**: If `saveRequests` is true, make sure to regularly clear the interceptor to avoid that the requests
|
|
731
|
-
* accumulate in memory. A common practice is to call
|
|
732
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorclear `interceptor.clear()`}
|
|
733
|
-
* after each test.
|
|
756
|
+
* Configures if the intercepted requests are saved and how they are handled.
|
|
734
757
|
*
|
|
735
|
-
* @default process.env.NODE_ENV === 'test'
|
|
736
758
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests Saving intercepted requests}
|
|
737
759
|
* @see {@link https://github.com/zimicjs/zimic/wiki/guides‐testing‐interceptor Testing}
|
|
738
760
|
*/
|
|
739
|
-
|
|
761
|
+
requestSaving: HttpInterceptorRequestSaving;
|
|
740
762
|
/**
|
|
741
763
|
* The platform the interceptor is running on.
|
|
742
764
|
*
|
|
@@ -784,8 +806,9 @@ interface HttpInterceptor<_Schema extends HttpSchema> {
|
|
|
784
806
|
* of each test.
|
|
785
807
|
*
|
|
786
808
|
* When
|
|
787
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#
|
|
788
|
-
*
|
|
809
|
+
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests
|
|
810
|
+
* `requestSaving.enabled`} is
|
|
811
|
+
* `true` in your interceptor, the `TimesCheckError` errors will also list each unmatched request with diff of the
|
|
789
812
|
* expected and received data. This is useful for debugging requests that did not match a handler with
|
|
790
813
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction restrictions}.
|
|
791
814
|
*
|
|
@@ -1241,6 +1264,22 @@ interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpIntercept
|
|
|
1241
1264
|
clear: () => Promise<void>;
|
|
1242
1265
|
}
|
|
1243
1266
|
|
|
1267
|
+
declare class TimesDeclarationPointer extends Error {
|
|
1268
|
+
constructor(minNumberOfRequests: number, maxNumberOfRequests?: number);
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
interface TimesCheckErrorOptions {
|
|
1272
|
+
requestLimits: Range<number>;
|
|
1273
|
+
numberOfMatchedRequests: number;
|
|
1274
|
+
declarationPointer: TimesDeclarationPointer | undefined;
|
|
1275
|
+
unmatchedRequestGroups: UnmatchedHttpInterceptorRequestGroup[];
|
|
1276
|
+
hasRestrictions: boolean;
|
|
1277
|
+
requestSaving: HttpInterceptorRequestSaving;
|
|
1278
|
+
}
|
|
1279
|
+
declare class TimesCheckError extends TypeError {
|
|
1280
|
+
constructor(options: TimesCheckErrorOptions);
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1244
1283
|
/**
|
|
1245
1284
|
* Infers the schema of an
|
|
1246
1285
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httpinterceptor `HttpInterceptor`}.
|
|
@@ -1285,4 +1324,4 @@ declare function createHttpInterceptor<Schema extends HttpSchema>(options: Local
|
|
|
1285
1324
|
declare function createHttpInterceptor<Schema extends HttpSchema>(options: RemoteHttpInterceptorOptions): RemoteHttpInterceptor<Schema>;
|
|
1286
1325
|
declare function createHttpInterceptor<Schema extends HttpSchema>(options: HttpInterceptorOptions): LocalHttpInterceptor<Schema> | RemoteHttpInterceptor<Schema>;
|
|
1287
1326
|
|
|
1288
|
-
export { DisabledRequestSavingError, type HttpInterceptor, type HttpInterceptorOptions, type HttpInterceptorPlatform, type HttpInterceptorRequest, type HttpInterceptorResponse, type HttpInterceptorType, type HttpRequestHandler, type HttpRequestHandlerBodyStaticRestriction, type HttpRequestHandlerComputedRestriction, type HttpRequestHandlerHeadersStaticRestriction, type HttpRequestHandlerResponseDeclaration, type HttpRequestHandlerResponseDeclarationFactory, type HttpRequestHandlerRestriction, type HttpRequestHandlerSearchParamsStaticRestriction, type HttpRequestHandlerStaticRestriction, type InferHttpInterceptorSchema, type InterceptedHttpInterceptorRequest, InvalidFormDataError, InvalidJSONError, type LocalHttpInterceptor, type LocalHttpInterceptorOptions, type LocalHttpRequestHandler, NotRunningHttpInterceptorError, type PendingRemoteHttpRequestHandler, type RemoteHttpInterceptor, type RemoteHttpInterceptorOptions, type RemoteHttpRequestHandler, RunningHttpInterceptorError, type SyncedRemoteHttpRequestHandler, TimesCheckError, type UnhandledHttpInterceptorRequest, UnhandledRequestStrategy, UnknownHttpInterceptorPlatformError, UnknownHttpInterceptorTypeError, UnregisteredBrowserServiceWorkerError, createHttpInterceptor };
|
|
1327
|
+
export { DisabledRequestSavingError, type HttpInterceptor, type HttpInterceptorOptions, type HttpInterceptorPlatform, type HttpInterceptorRequest, type HttpInterceptorResponse, type HttpInterceptorType, type HttpRequestHandler, type HttpRequestHandlerBodyStaticRestriction, type HttpRequestHandlerComputedRestriction, type HttpRequestHandlerHeadersStaticRestriction, type HttpRequestHandlerResponseDeclaration, type HttpRequestHandlerResponseDeclarationFactory, type HttpRequestHandlerRestriction, type HttpRequestHandlerSearchParamsStaticRestriction, type HttpRequestHandlerStaticRestriction, type InferHttpInterceptorSchema, type InterceptedHttpInterceptorRequest, InvalidFormDataError, InvalidJSONError, type LocalHttpInterceptor, type LocalHttpInterceptorOptions, type LocalHttpRequestHandler, NotRunningHttpInterceptorError, type PendingRemoteHttpRequestHandler, type RemoteHttpInterceptor, type RemoteHttpInterceptorOptions, type RemoteHttpRequestHandler, RequestSavingSafeLimitExceededError, RunningHttpInterceptorError, type SyncedRemoteHttpRequestHandler, TimesCheckError, type UnhandledHttpInterceptorRequest, UnhandledRequestStrategy, UnknownHttpInterceptorPlatformError, UnknownHttpInterceptorTypeError, UnregisteredBrowserServiceWorkerError, createHttpInterceptor };
|