@zimic/interceptor 0.14.0 → 0.15.0-canary.1
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 +7 -8
- package/dist/{chunk-FEGMEAEO.mjs → chunk-3O3YPVEG.mjs} +69 -104
- package/dist/chunk-3O3YPVEG.mjs.map +1 -0
- package/dist/{chunk-3623PRKE.js → chunk-CWBDZYUG.js} +69 -104
- package/dist/chunk-CWBDZYUG.js.map +1 -0
- package/dist/cli.js +7 -7
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +3 -3
- package/dist/cli.mjs.map +1 -1
- package/dist/http.d.ts +47 -38
- package/dist/http.js +173 -235
- package/dist/http.js.map +1 -1
- package/dist/http.mjs +173 -235
- package/dist/http.mjs.map +1 -1
- package/dist/server.d.ts +15 -10
- package/dist/server.js +5 -5
- package/dist/server.mjs +1 -1
- package/package.json +3 -3
- package/src/cli/server/start.ts +1 -1
- package/src/http/index.ts +14 -1
- package/src/http/interceptor/HttpInterceptorClient.ts +23 -34
- package/src/http/interceptor/HttpInterceptorStore.ts +2 -2
- package/src/http/interceptor/LocalHttpInterceptor.ts +22 -25
- package/src/http/interceptor/RemoteHttpInterceptor.ts +22 -25
- package/src/http/interceptor/errors/NotStartedHttpInterceptorError.ts +1 -1
- package/src/http/interceptor/errors/UnknownHttpInterceptorPlatformError.ts +1 -1
- package/src/http/interceptor/types/options.ts +3 -3
- package/src/http/interceptor/types/public.ts +12 -9
- package/src/http/interceptorWorker/HttpInterceptorWorker.ts +10 -28
- package/src/http/interceptorWorker/LocalHttpInterceptorWorker.ts +21 -25
- package/src/http/interceptorWorker/RemoteHttpInterceptorWorker.ts +22 -26
- package/src/http/requestHandler/HttpRequestHandlerClient.ts +13 -23
- package/src/http/requestHandler/LocalHttpRequestHandler.ts +17 -21
- package/src/http/requestHandler/RemoteHttpRequestHandler.ts +19 -29
- package/src/http/requestHandler/types/public.ts +23 -23
- package/src/http/requestHandler/types/requests.ts +1 -1
- package/src/server/InterceptorServer.ts +45 -68
- package/src/server/types/public.ts +15 -10
- package/src/webSocket/WebSocketClient.ts +1 -1
- package/src/webSocket/WebSocketHandler.ts +11 -19
- package/src/webSocket/WebSocketServer.ts +4 -4
- package/dist/chunk-3623PRKE.js.map +0 -1
- package/dist/chunk-FEGMEAEO.mjs.map +0 -1
package/dist/http.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HttpMethodSchema, HttpRequest, HttpHeaders, HttpRequestHeadersSchema, InferPathParams, HttpSearchParams, HttpRequestSearchParamsSchema, HttpRequestBodySchema,
|
|
1
|
+
import { HttpMethodSchema, HttpStatusCode, HttpRequest, HttpHeaders, HttpRequestHeadersSchema, InferPathParams, HttpSearchParams, HttpRequestSearchParamsSchema, HttpRequestBodySchema, HttpResponse, HttpResponseHeadersSchema, HttpResponseBodySchema, HttpResponseSchema, HttpHeadersInit, HttpSchema, HttpBody, HttpSchemaMethod, HttpSchemaPath, HttpHeadersSchema, HttpSearchParamsSchema, HttpFormData, HttpResponseSchemaStatusCode, HttpMethod, LiteralHttpSchemaPathFromNonLiteral } from '@zimic/http';
|
|
2
2
|
|
|
3
3
|
type Default<Type, IfEmpty = never> = [undefined | void] extends [Type] ? IfEmpty : Exclude<Type, undefined | void>;
|
|
4
4
|
type IfNever<Type, Yes, No = Type> = [Type] extends [never] ? Yes : No;
|
|
@@ -73,7 +73,7 @@ interface HttpInterceptorResponse<MethodSchema extends HttpMethodSchema, StatusC
|
|
|
73
73
|
* A strict representation of an intercepted HTTP request, along with its response. The body, search params and path
|
|
74
74
|
* params are already parsed by default.
|
|
75
75
|
*/
|
|
76
|
-
interface
|
|
76
|
+
interface InterceptedHttpInterceptorRequest<Path extends string, MethodSchema extends HttpMethodSchema, StatusCode extends HttpStatusCode = never> extends HttpInterceptorRequest<Path, MethodSchema> {
|
|
77
77
|
/** The response that was returned for the intercepted request. */
|
|
78
78
|
response: StatusCode extends [never] ? never : HttpInterceptorResponse<MethodSchema, StatusCode>;
|
|
79
79
|
}
|
|
@@ -96,7 +96,7 @@ type HttpInterceptorType = 'local' | 'remote';
|
|
|
96
96
|
/**
|
|
97
97
|
* The platform where an HTTP interceptor is running.
|
|
98
98
|
*
|
|
99
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorplatform `interceptor.platform
|
|
99
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorplatform `interceptor.platform` API reference}
|
|
100
100
|
*/
|
|
101
101
|
type HttpInterceptorPlatform = 'node' | 'browser';
|
|
102
102
|
/**
|
|
@@ -189,9 +189,9 @@ interface SharedHttpInterceptorOptions {
|
|
|
189
189
|
/**
|
|
190
190
|
* Whether {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httprequesthandler request handlers}
|
|
191
191
|
* should save their intercepted requests in memory and make them accessible through
|
|
192
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerrequests `handler.requests
|
|
192
|
+
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerrequests `handler.requests`}.
|
|
193
193
|
*
|
|
194
|
-
* **
|
|
194
|
+
* **Important**: Saving the intercepted requests will lead to a memory leak if not accompanied by clearing of the
|
|
195
195
|
* interceptor or disposal of the handlers (i.e. garbage collection). If you plan on accessing those requests, such as
|
|
196
196
|
* to assert them in your tests, set this option to `true` and make sure to regularly clear the interceptor. A common
|
|
197
197
|
* practice is to call
|
|
@@ -332,16 +332,18 @@ interface UnmatchedHttpInterceptorRequestGroup {
|
|
|
332
332
|
*/
|
|
333
333
|
interface HttpRequestHandler<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> {
|
|
334
334
|
/**
|
|
335
|
-
*
|
|
336
|
-
*
|
|
335
|
+
* The method that matches this handler.
|
|
336
|
+
*
|
|
337
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlermethod `handler.method` API reference}
|
|
337
338
|
*/
|
|
338
|
-
method:
|
|
339
|
+
method: Method;
|
|
339
340
|
/**
|
|
340
|
-
*
|
|
341
|
-
*
|
|
342
|
-
*
|
|
341
|
+
* The path that matches this handler. The base URL of the interceptor is not included, but it is used when matching
|
|
342
|
+
* requests.
|
|
343
|
+
*
|
|
344
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerpath `handler.path` API reference}
|
|
343
345
|
*/
|
|
344
|
-
path:
|
|
346
|
+
path: Path;
|
|
345
347
|
}
|
|
346
348
|
/**
|
|
347
349
|
* A local HTTP request handler to declare responses for intercepted requests. In a local handler, the mocking
|
|
@@ -397,7 +399,7 @@ interface LocalHttpRequestHandler<Schema extends HttpSchema, Method extends Http
|
|
|
397
399
|
* intercepted request in the
|
|
398
400
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptormethodpath `interceptor.<method>(path)` API reference}.
|
|
399
401
|
*
|
|
400
|
-
* **
|
|
402
|
+
* **Important**: To make sure that all expected requests were made, use
|
|
401
403
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorchecktimes `interceptor.checkTimes()`}
|
|
402
404
|
* or {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlertimes `handler.times()`}.
|
|
403
405
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorchecktimes `interceptor.checkTimes()`}
|
|
@@ -446,18 +448,17 @@ interface LocalHttpRequestHandler<Schema extends HttpSchema, Method extends Http
|
|
|
446
448
|
*/
|
|
447
449
|
clear: () => this;
|
|
448
450
|
/**
|
|
449
|
-
*
|
|
450
|
-
*
|
|
451
|
+
* The intercepted requests that matched this handler, along with the responses returned to each of them. This is
|
|
452
|
+
* useful for testing that the correct requests were made by your application.
|
|
451
453
|
*
|
|
452
|
-
* **
|
|
454
|
+
* **Important**: This method can only be used if `saveRequests` was set to `true` when creating the interceptor. See
|
|
453
455
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests Saving intercepted requests}
|
|
454
456
|
* for more information.
|
|
455
457
|
*
|
|
456
|
-
* @returns The intercepted requests.
|
|
457
458
|
* @throws {DisabledRequestSavingError} If the interceptor was not created with `saveRequests: true`.
|
|
458
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerrequests `handler.requests
|
|
459
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerrequests `handler.requests` API reference}
|
|
459
460
|
*/
|
|
460
|
-
requests:
|
|
461
|
+
requests: readonly InterceptedHttpInterceptorRequest<Path, Default<Schema[Path][Method]>, StatusCode>[];
|
|
461
462
|
}
|
|
462
463
|
/**
|
|
463
464
|
* A synced remote HTTP request handler. When a remote handler is synced, it is guaranteed that all of the mocking
|
|
@@ -510,7 +511,7 @@ interface SyncedRemoteHttpRequestHandler<Schema extends HttpSchema, Method exten
|
|
|
510
511
|
* intercepted request in the
|
|
511
512
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptormethodpath `interceptor.<method>(path)` API reference}.
|
|
512
513
|
*
|
|
513
|
-
* **
|
|
514
|
+
* **Important**: To make sure that all expected requests were made, use
|
|
514
515
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorchecktimes `interceptor.checkTimes()`}
|
|
515
516
|
* or
|
|
516
517
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerchecktimes `handler.checkTimes()`}.
|
|
@@ -560,18 +561,17 @@ interface SyncedRemoteHttpRequestHandler<Schema extends HttpSchema, Method exten
|
|
|
560
561
|
*/
|
|
561
562
|
clear: () => PendingRemoteHttpRequestHandler<Schema, Method, Path, StatusCode>;
|
|
562
563
|
/**
|
|
563
|
-
*
|
|
564
|
-
*
|
|
564
|
+
* The intercepted requests that matched this handler, along with the responses returned to each of them. This is
|
|
565
|
+
* useful for testing that the correct requests were made by your application.
|
|
565
566
|
*
|
|
566
|
-
* **
|
|
567
|
+
* **Important**: This method can only be used if `saveRequests` was set to `true` when creating the interceptor. See
|
|
567
568
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests Saving intercepted requests}
|
|
568
569
|
* for more information.
|
|
569
570
|
*
|
|
570
|
-
* @returns The intercepted requests.
|
|
571
571
|
* @throws {DisabledRequestSavingError} If the interceptor was not created with `saveRequests: true`.
|
|
572
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerrequests `handler.requests
|
|
572
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerrequests `handler.requests` API reference}
|
|
573
573
|
*/
|
|
574
|
-
requests:
|
|
574
|
+
requests: readonly InterceptedHttpInterceptorRequest<Path, Default<Schema[Path][Method]>, StatusCode>[];
|
|
575
575
|
}
|
|
576
576
|
/**
|
|
577
577
|
* A pending remote HTTP request handler. When a remote handler is pending, it is not guaranteed that all of the mocking
|
|
@@ -624,20 +624,23 @@ type AsyncHttpInterceptorMethodHandler<Schema extends HttpSchema, Method extends
|
|
|
624
624
|
*/
|
|
625
625
|
interface HttpInterceptor<_Schema extends HttpSchema> {
|
|
626
626
|
/**
|
|
627
|
-
*
|
|
628
|
-
*
|
|
627
|
+
* The base URL used by the interceptor.
|
|
628
|
+
*
|
|
629
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorbaseurl `interceptor.baseURL` API reference}
|
|
629
630
|
*/
|
|
630
|
-
baseURL:
|
|
631
|
+
baseURL: string;
|
|
631
632
|
/**
|
|
632
|
-
*
|
|
633
|
-
*
|
|
633
|
+
* The platform the interceptor is running on.
|
|
634
|
+
*
|
|
635
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorplatform `interceptor.platform` API reference}
|
|
634
636
|
*/
|
|
635
|
-
platform:
|
|
637
|
+
platform: HttpInterceptorPlatform | null;
|
|
636
638
|
/**
|
|
637
|
-
*
|
|
638
|
-
*
|
|
639
|
+
* Whether the interceptor is currently running and ready to use.
|
|
640
|
+
*
|
|
641
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorisrunning `interceptor.isRunning` API reference}
|
|
639
642
|
*/
|
|
640
|
-
isRunning:
|
|
643
|
+
isRunning: boolean;
|
|
641
644
|
/**
|
|
642
645
|
* Starts the interceptor, allowing it to intercept HTTP requests.
|
|
643
646
|
*
|
|
@@ -1198,7 +1201,7 @@ declare class InvalidFormDataError extends SyntaxError {
|
|
|
1198
1201
|
*
|
|
1199
1202
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorstart `interceptor.start()` API reference}
|
|
1200
1203
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorstop `interceptor.stop()` API reference}
|
|
1201
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorisrunning `interceptor.isRunning
|
|
1204
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorisrunning `interceptor.isRunning` API reference}
|
|
1202
1205
|
*/
|
|
1203
1206
|
declare class NotStartedHttpInterceptorError extends Error {
|
|
1204
1207
|
constructor();
|
|
@@ -1208,7 +1211,7 @@ declare class NotStartedHttpInterceptorError extends Error {
|
|
|
1208
1211
|
* An error thrown when an unknown interceptor platform is detected. Currently, the platforms `node` and `browser` are
|
|
1209
1212
|
* supported.
|
|
1210
1213
|
*
|
|
1211
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorplatform `interceptor.platform
|
|
1214
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorplatform `interceptor.platform` API reference}
|
|
1212
1215
|
*/
|
|
1213
1216
|
declare class UnknownHttpInterceptorPlatformError extends Error {
|
|
1214
1217
|
constructor();
|
|
@@ -1284,6 +1287,12 @@ declare class TimesCheckError extends TypeError {
|
|
|
1284
1287
|
*/
|
|
1285
1288
|
type InferHttpInterceptorSchema<Interceptor> = Interceptor extends LocalHttpInterceptor<infer Schema> ? Schema : Interceptor extends RemoteHttpInterceptor<infer Schema> ? Schema : never;
|
|
1286
1289
|
|
|
1290
|
+
/**
|
|
1291
|
+
* @deprecated This type was renamed to {@link InterceptedHttpInterceptorRequest `InterceptedHttpInterceptorRequest`}.
|
|
1292
|
+
* Please use it instead.
|
|
1293
|
+
*/
|
|
1294
|
+
type TrackedHttpInterceptorRequest<Path extends string, MethodSchema extends HttpMethodSchema, StatusCode extends HttpStatusCode = never> = InterceptedHttpInterceptorRequest<Path, MethodSchema, StatusCode>;
|
|
1295
|
+
|
|
1287
1296
|
/**
|
|
1288
1297
|
* A namespace of interceptor resources for mocking HTTP requests.
|
|
1289
1298
|
*
|
|
@@ -1291,4 +1300,4 @@ type InferHttpInterceptorSchema<Interceptor> = Interceptor extends LocalHttpInte
|
|
|
1291
1300
|
*/
|
|
1292
1301
|
declare const httpInterceptor: Readonly<HttpInterceptorNamespace>;
|
|
1293
1302
|
|
|
1294
|
-
export { DisabledRequestSavingError, type HttpInterceptor, HttpInterceptorNamespace, HttpInterceptorNamespaceDefault, 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, InvalidFormDataError, InvalidJSONError, type LocalHttpInterceptor, type LocalHttpInterceptorOptions, type LocalHttpRequestHandler, NotStartedHttpInterceptorError, type PendingRemoteHttpRequestHandler, type RemoteHttpInterceptor, type RemoteHttpInterceptorOptions, type RemoteHttpRequestHandler, type SyncedRemoteHttpRequestHandler, TimesCheckError, type TrackedHttpInterceptorRequest, type UnhandledHttpInterceptorRequest, UnhandledRequestStrategy, UnknownHttpInterceptorPlatformError, UnknownHttpInterceptorTypeError, UnregisteredBrowserServiceWorkerError, httpInterceptor };
|
|
1303
|
+
export { DisabledRequestSavingError, type HttpInterceptor, HttpInterceptorNamespace, HttpInterceptorNamespaceDefault, 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, NotStartedHttpInterceptorError, type PendingRemoteHttpRequestHandler, type RemoteHttpInterceptor, type RemoteHttpInterceptorOptions, type RemoteHttpRequestHandler, type SyncedRemoteHttpRequestHandler, TimesCheckError, type TrackedHttpInterceptorRequest, type UnhandledHttpInterceptorRequest, UnhandledRequestStrategy, UnknownHttpInterceptorPlatformError, UnknownHttpInterceptorTypeError, UnregisteredBrowserServiceWorkerError, httpInterceptor };
|