@zimic/interceptor 0.15.0 → 0.16.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/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "api",
15
15
  "static"
16
16
  ],
17
- "version": "0.15.0",
17
+ "version": "0.16.0-canary.1",
18
18
  "repository": {
19
19
  "type": "git",
20
20
  "url": "https://github.com/zimicjs/zimic.git",
@@ -97,9 +97,9 @@
97
97
  "tsup": "^8.4.0",
98
98
  "typescript": "^5.8.2",
99
99
  "vitest": "^3.0.8",
100
- "@zimic/lint-staged-config": "0.0.0",
101
- "@zimic/tsconfig": "0.0.0",
102
100
  "@zimic/eslint-config-node": "0.0.0",
101
+ "@zimic/tsconfig": "0.0.0",
102
+ "@zimic/lint-staged-config": "0.0.0",
103
103
  "@zimic/utils": "0.0.0"
104
104
  },
105
105
  "peerDependencies": {
@@ -120,7 +120,7 @@
120
120
  "style": "prettier --log-level warn --ignore-unknown --no-error-on-unmatched-pattern --cache",
121
121
  "style:check": "pnpm style --check",
122
122
  "style:format": "pnpm style --write",
123
- "test": "dotenv -v NODE_ENV=test -- vitest",
123
+ "test": "dotenv -v NODE_ENV=test -v FORCE_COLOR=1 -- vitest",
124
124
  "test:turbo": "dotenv -v CI=true -- pnpm run test run --coverage",
125
125
  "types:check": "tsc --noEmit",
126
126
  "deps:install-playwright": "playwright install chromium",
@@ -13,6 +13,8 @@ import excludeURLParams from '@zimic/utils/url/excludeURLParams';
13
13
  import joinURL from '@zimic/utils/url/joinURL';
14
14
  import validateURLProtocol from '@zimic/utils/url/validateURLProtocol';
15
15
 
16
+ import { isServerSide } from '@/utils/environment';
17
+
16
18
  import HttpInterceptorWorker from '../interceptorWorker/HttpInterceptorWorker';
17
19
  import LocalHttpInterceptorWorker from '../interceptorWorker/LocalHttpInterceptorWorker';
18
20
  import HttpRequestHandlerClient, { AnyHttpRequestHandlerClient } from '../requestHandler/HttpRequestHandlerClient';
@@ -36,7 +38,7 @@ class HttpInterceptorClient<
36
38
  private store: HttpInterceptorStore;
37
39
 
38
40
  private _baseURL!: URL;
39
- private _saveRequests = false;
41
+ private _saveRequests?: boolean;
40
42
 
41
43
  onUnhandledRequest?: HandlerConstructor extends typeof LocalHttpRequestHandler
42
44
  ? UnhandledRequestStrategy.Local
@@ -70,7 +72,7 @@ class HttpInterceptorClient<
70
72
  this.store = options.store;
71
73
 
72
74
  this.baseURL = options.baseURL;
73
- this._saveRequests = options.saveRequests ?? false;
75
+ this._saveRequests = options.saveRequests;
74
76
  this.onUnhandledRequest = options.onUnhandledRequest satisfies
75
77
  | UnhandledRequestStrategy
76
78
  | undefined as this['onUnhandledRequest'];
@@ -102,6 +104,9 @@ class HttpInterceptorClient<
102
104
  }
103
105
 
104
106
  get saveRequests() {
107
+ if (this._saveRequests === undefined) {
108
+ return isServerSide() ? process.env.NODE_ENV === 'test' : false;
109
+ }
105
110
  return this._saveRequests;
106
111
  }
107
112
 
@@ -246,7 +251,7 @@ class HttpInterceptorClient<
246
251
  const responseDeclaration = await matchedHandler.applyResponseDeclaration(parsedRequest);
247
252
  const response = HttpInterceptorWorker.createResponseFromDeclaration(request, responseDeclaration);
248
253
 
249
- if (this._saveRequests) {
254
+ if (this.saveRequests) {
250
255
  const responseClone = response.clone();
251
256
 
252
257
  const parsedResponse = await HttpInterceptorWorker.parseRawResponse<
@@ -29,7 +29,7 @@ export interface HttpInterceptor<_Schema extends HttpSchema> {
29
29
  * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorclear `interceptor.clear()`}
30
30
  * after each test.
31
31
  *
32
- * @default false
32
+ * @default process.env.NODE_ENV === 'test'
33
33
  * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests Saving intercepted requests}
34
34
  * @see {@link https://github.com/zimicjs/zimic/wiki/guides‐testing‐interceptor Testing}
35
35
  */