@zimic/interceptor 0.15.0-canary.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.
Files changed (41) hide show
  1. package/README.md +6 -7
  2. package/dist/{chunk-YGJD3JT6.mjs → chunk-3O3YPVEG.mjs} +69 -104
  3. package/dist/chunk-3O3YPVEG.mjs.map +1 -0
  4. package/dist/{chunk-L6Y4EV6T.js → chunk-CWBDZYUG.js} +69 -104
  5. package/dist/chunk-CWBDZYUG.js.map +1 -0
  6. package/dist/cli.js +7 -7
  7. package/dist/cli.js.map +1 -1
  8. package/dist/cli.mjs +3 -3
  9. package/dist/cli.mjs.map +1 -1
  10. package/dist/http.d.ts +38 -35
  11. package/dist/http.js +173 -235
  12. package/dist/http.js.map +1 -1
  13. package/dist/http.mjs +173 -235
  14. package/dist/http.mjs.map +1 -1
  15. package/dist/server.d.ts +15 -10
  16. package/dist/server.js +5 -5
  17. package/dist/server.mjs +1 -1
  18. package/package.json +2 -2
  19. package/src/cli/server/start.ts +1 -1
  20. package/src/http/interceptor/HttpInterceptorClient.ts +23 -34
  21. package/src/http/interceptor/HttpInterceptorStore.ts +2 -2
  22. package/src/http/interceptor/LocalHttpInterceptor.ts +22 -25
  23. package/src/http/interceptor/RemoteHttpInterceptor.ts +22 -25
  24. package/src/http/interceptor/errors/NotStartedHttpInterceptorError.ts +1 -1
  25. package/src/http/interceptor/errors/UnknownHttpInterceptorPlatformError.ts +1 -1
  26. package/src/http/interceptor/types/options.ts +3 -3
  27. package/src/http/interceptor/types/public.ts +12 -9
  28. package/src/http/interceptorWorker/HttpInterceptorWorker.ts +10 -28
  29. package/src/http/interceptorWorker/LocalHttpInterceptorWorker.ts +21 -25
  30. package/src/http/interceptorWorker/RemoteHttpInterceptorWorker.ts +22 -26
  31. package/src/http/requestHandler/HttpRequestHandlerClient.ts +11 -22
  32. package/src/http/requestHandler/LocalHttpRequestHandler.ts +16 -20
  33. package/src/http/requestHandler/RemoteHttpRequestHandler.ts +18 -28
  34. package/src/http/requestHandler/types/public.ts +22 -24
  35. package/src/server/InterceptorServer.ts +45 -68
  36. package/src/server/types/public.ts +15 -10
  37. package/src/webSocket/WebSocketClient.ts +1 -1
  38. package/src/webSocket/WebSocketHandler.ts +11 -19
  39. package/src/webSocket/WebSocketServer.ts +4 -4
  40. package/dist/chunk-L6Y4EV6T.js.map +0 -1
  41. package/dist/chunk-YGJD3JT6.mjs.map +0 -1
package/dist/http.d.ts CHANGED
@@ -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()` API reference}
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
- * **IMPORTANT**: Saving the intercepted requests will lead to a memory leak if not accompanied by clearing of the
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
- * @returns The method that matches this handler.
336
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlermethod `handler.method()` API reference}
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: () => Method;
339
+ method: Method;
339
340
  /**
340
- * @returns The path that matches this handler. The base URL of the interceptor is not included, but it is used when
341
- * matching requests.
342
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerpath `handler.path()` API reference}
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: () => 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
- * **IMPORTANT**: To make sure that all expected requests were made, use
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
- * Returns the intercepted requests that matched this handler, along with the responses returned to each of them. This
450
- * is useful for testing that the correct requests were made by your application.
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
- * **IMPORTANT**: This method can only be used if `saveRequests` was set to `true` when creating the interceptor. See
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()` API reference}
459
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerrequests `handler.requests` API reference}
459
460
  */
460
- requests: () => readonly InterceptedHttpInterceptorRequest<Path, Default<Schema[Path][Method]>, StatusCode>[];
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
- * **IMPORTANT**: To make sure that all expected requests were made, use
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
- * Returns the intercepted requests that matched this handler, along with the responses returned to each of them. This
564
- * is useful for testing that the correct requests were made by your application.
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
- * **IMPORTANT**: This method can only be used if `saveRequests` was set to `true` when creating the interceptor. See
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()` API reference}
572
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerrequests `handler.requests` API reference}
573
573
  */
574
- requests: () => Promise<readonly InterceptedHttpInterceptorRequest<Path, Default<Schema[Path][Method]>, StatusCode>[]>;
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
- * @returns The base URL used by the interceptor.
628
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorbaseurl `interceptor.baseURL()` API reference}
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: () => string;
631
+ baseURL: string;
631
632
  /**
632
- * @returns The platform the interceptor is running on.
633
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorplatform `interceptor.platform()` API reference}
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: () => HttpInterceptorPlatform | null;
637
+ platform: HttpInterceptorPlatform | null;
636
638
  /**
637
- * @returns Whether the interceptor is currently running and ready to use.
638
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorisrunning `interceptor.isRunning()` API reference}
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: () => boolean;
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()` API reference}
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()` API reference}
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();