@zimic/interceptor 0.14.0-canary.24 → 0.14.0-canary.26
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/LICENSE.md +1 -1
- package/README.md +218 -171
- package/dist/{chunk-BJLJWEVE.js → chunk-3623PRKE.js} +20 -20
- package/dist/chunk-3623PRKE.js.map +1 -0
- package/dist/{chunk-QSY6YMZ7.mjs → chunk-FEGMEAEO.mjs} +20 -20
- package/dist/chunk-FEGMEAEO.mjs.map +1 -0
- package/dist/cli.js +16 -16
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +11 -11
- package/dist/cli.mjs.map +1 -1
- package/dist/http.d.ts +3 -3
- package/dist/http.js +35 -31
- package/dist/http.js.map +1 -1
- package/dist/http.mjs +35 -31
- package/dist/http.mjs.map +1 -1
- package/dist/server.js +5 -5
- package/dist/server.mjs +1 -1
- package/package.json +14 -15
- package/src/http/interceptor/types/options.ts +1 -1
- package/src/http/interceptor/types/schema.ts +1 -1
- package/src/http/interceptorWorker/LocalHttpInterceptorWorker.ts +3 -3
- package/src/http/interceptorWorker/RemoteHttpInterceptorWorker.ts +3 -6
- package/src/utils/environment.ts +5 -1
- package/dist/chunk-BJLJWEVE.js.map +0 -1
- package/dist/chunk-QSY6YMZ7.mjs.map +0 -1
package/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2023
|
|
3
|
+
Copyright (c) 2023-Present Zimic Team
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
6
6
|
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
package/README.md
CHANGED
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
5
|
<h1 align="center">
|
|
6
|
-
|
|
6
|
+
@zimic/interceptor
|
|
7
7
|
</h1>
|
|
8
8
|
|
|
9
9
|
<p align="center">
|
|
10
|
-
TypeScript-first HTTP
|
|
10
|
+
TypeScript-first HTTP intercepting and mocking
|
|
11
11
|
</p>
|
|
12
12
|
|
|
13
13
|
<p align="center">
|
|
14
|
-
<a href="https://www.npmjs.com/package/
|
|
14
|
+
<a href="https://www.npmjs.com/package/@zimic/interceptor">npm</a>
|
|
15
15
|
<span> • </span>
|
|
16
16
|
<a href="https://github.com/zimicjs/zimic/wiki">Docs</a>
|
|
17
17
|
<span> • </span>
|
|
@@ -26,196 +26,243 @@
|
|
|
26
26
|
|
|
27
27
|
[](https://github.com/zimicjs/zimic/actions/workflows/ci.yaml)
|
|
28
28
|
[](https://github.com/zimicjs/zimic/actions)
|
|
29
|
-
[](https://github.com/zimicjs/zimic/blob/canary/LICENSE.md)
|
|
30
|
-
[](https://github.com/zimicjs/zimic/blob/canary/LICENSE.md)
|
|
30
|
+
[](https://github.com/zimicjs/zimic)
|
|
31
|
+
|
|
32
|
+
[](https://www.npmjs.com/package/@zimic/interceptor)
|
|
33
|
+
[](https://bundlephobia.com/package/@zimic/interceptor)
|
|
32
34
|
|
|
33
35
|
</div>
|
|
34
36
|
|
|
35
37
|
---
|
|
36
38
|
|
|
37
|
-
|
|
38
|
-
[
|
|
39
|
+
- [Features](#features)
|
|
40
|
+
- [Getting started](#getting-started)
|
|
41
|
+
- [Installation](#installation)
|
|
42
|
+
- [Basic usage](#basic-usage)
|
|
43
|
+
- [Documentation](#documentation)
|
|
44
|
+
- [Examples](#examples)
|
|
45
|
+
- [Changelog](#changelog)
|
|
46
|
+
- [Contributing](#contributing)
|
|
39
47
|
|
|
40
|
-
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
`@zimic/interceptor` provides a flexible and type-safe way to intercept and mock HTTP requests.
|
|
51
|
+
|
|
52
|
+
> [!NOTE]
|
|
53
|
+
>
|
|
54
|
+
> :seedling: This library is in **beta**.
|
|
41
55
|
|
|
42
|
-
|
|
56
|
+
## Features
|
|
43
57
|
|
|
44
|
-
- :
|
|
45
|
-
[
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
58
|
+
- :globe_with_meridians: **HTTP interceptors**: Intercept HTTP requests and return mock responses. Use
|
|
59
|
+
[local](https://github.com/zimicjs/zimic/wiki/getting‐started#local-http-interceptors) or
|
|
60
|
+
[remote](https://github.com/zimicjs/zimic/wiki/getting‐started#remote-http-interceptors) interceptors to adapt your
|
|
61
|
+
mocks to your development and testing workflow.
|
|
62
|
+
- :zap: **Fully typed mocks**: Use your
|
|
63
|
+
[`@zimic/http` schema](https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas) and create type-safe mocks for
|
|
64
|
+
your HTTP requests.
|
|
65
|
+
- :link: **Network-level interceptor**: `@zimic/interceptor` combines [MSW](https://github.com/mswjs/msw) and
|
|
66
|
+
[interceptor servers](https://github.com/zimicjs/zimic/wiki/cli‐zimic‐server) to handle real HTTP requests. From you
|
|
51
67
|
application's point of view, the mocked responses are indistinguishable from the real ones.
|
|
52
68
|
- :wrench: **Flexibility**: Mock external services and reliably test how your application behaves. Simulate success,
|
|
53
69
|
loading, and error states with ease using [standard web APIs](https://developer.mozilla.org/docs/Web/API).
|
|
54
|
-
- :bulb: **Simplicity**:
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
70
|
+
- :bulb: **Simplicity**: `@zimic/interceptor` was designed to encourage clarity, simplicity, and robustness in your
|
|
71
|
+
mocks.
|
|
72
|
+
|
|
73
|
+
## Getting started
|
|
74
|
+
|
|
75
|
+
Check our [getting started guide](https://github.com/zimicjs/zimic/wiki/getting‐started‐interceptor).
|
|
76
|
+
|
|
77
|
+
### Installation
|
|
78
|
+
|
|
79
|
+
| Manager | Command |
|
|
80
|
+
| :-----: | ------------------------------------------------------- |
|
|
81
|
+
| npm | `npm install @zimic/http @zimic/interceptor --save-dev` |
|
|
82
|
+
| yarn | `yarn add @zimic/http @zimic/interceptor --dev` |
|
|
83
|
+
| pnpm | `pnpm add @zimic/http @zimic/interceptor --dev` |
|
|
84
|
+
|
|
85
|
+
## Basic usage
|
|
86
|
+
|
|
87
|
+
1. Declare your HTTP schema using [`@zimic/http`](https://github.com/zimicjs/zimic/wiki/api‐zimic‐http):
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
import { type HttpSchema } from '@zimic/http';
|
|
91
|
+
|
|
92
|
+
interface User {
|
|
93
|
+
username: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
interface RequestError {
|
|
97
|
+
code: string;
|
|
98
|
+
message: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
type Schema = HttpSchema<{
|
|
102
|
+
'/users': {
|
|
103
|
+
POST: {
|
|
104
|
+
request: { body: User };
|
|
105
|
+
response: {
|
|
106
|
+
201: { body: User };
|
|
107
|
+
400: { body: RequestError };
|
|
108
|
+
409: { body: RequestError };
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
GET: {
|
|
113
|
+
request: {
|
|
114
|
+
headers: { authorization: string };
|
|
115
|
+
searchParams: { query?: string; limit?: `${number}` };
|
|
116
|
+
};
|
|
117
|
+
response: {
|
|
118
|
+
200: { body: User[] };
|
|
119
|
+
400: { body: RequestError };
|
|
120
|
+
401: { body: RequestError };
|
|
121
|
+
};
|
|
90
122
|
};
|
|
91
123
|
};
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
body: Partial<User>;
|
|
105
|
-
};
|
|
106
|
-
response: {
|
|
107
|
-
204: {};
|
|
108
|
-
400: { body: RequestError };
|
|
124
|
+
|
|
125
|
+
'/users/:userId': {
|
|
126
|
+
PATCH: {
|
|
127
|
+
request: {
|
|
128
|
+
headers: { authorization: string };
|
|
129
|
+
body: Partial<User>;
|
|
130
|
+
};
|
|
131
|
+
response: {
|
|
132
|
+
204: {};
|
|
133
|
+
400: { body: RequestError };
|
|
134
|
+
};
|
|
135
|
+
};
|
|
109
136
|
};
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
}>;
|
|
113
|
-
|
|
114
|
-
// 3. Create your interceptor:
|
|
115
|
-
// https://bit.ly/zimic-interceptor-http#httpinterceptorcreateoptions
|
|
116
|
-
const myInterceptor = httpInterceptor.create<MySchema>({
|
|
117
|
-
type: 'local',
|
|
118
|
-
baseURL: 'http://localhost:3000',
|
|
119
|
-
saveRequests: true, // Allow access to `handler.requests()`
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
// 4. Manage your interceptor lifecycle:
|
|
123
|
-
// https://bit.ly/zimic-guides-testing
|
|
124
|
-
beforeAll(async () => {
|
|
125
|
-
// 4.1. Start intercepting requests:
|
|
126
|
-
// https://bit.ly/zimic-interceptor-http#http-interceptorstart
|
|
127
|
-
await myInterceptor.start();
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
beforeEach(() => {
|
|
131
|
-
// 4.2. Clear interceptors so that no tests affect each other:
|
|
132
|
-
// https://bit.ly/zimic-interceptor-http#http-interceptorclear
|
|
133
|
-
myInterceptor.clear();
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
afterEach(() => {
|
|
137
|
-
// 4.3. Check that all expected requests were made:
|
|
138
|
-
// https://bit.ly/zimic-interceptor-http#http-interceptorchecktimes
|
|
139
|
-
myInterceptor.checkTimes();
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
afterAll(async () => {
|
|
143
|
-
// 4.4. Stop intercepting requests:
|
|
144
|
-
// https://bit.ly/zimic-interceptor-http#http-interceptorstop
|
|
145
|
-
await myInterceptor.stop();
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
// Enjoy mocking!
|
|
149
|
-
test('example', async () => {
|
|
150
|
-
const users: User[] = [{ username: 'my-user' }];
|
|
151
|
-
|
|
152
|
-
// 5. Declare your mocks:
|
|
153
|
-
// https://bit.ly/zimic-interceptor-http#http-interceptormethodpath
|
|
154
|
-
const myHandler = myInterceptor
|
|
155
|
-
.get('/users')
|
|
156
|
-
// 5.1. Use restrictions to make declarative assertions and narrow down your mocks:
|
|
157
|
-
// https://bit.ly/zimic-interceptor-http#http-handlerwithrestriction
|
|
158
|
-
.with({
|
|
159
|
-
headers: { authorization: 'Bearer my-token' },
|
|
160
|
-
searchParams: { username: 'my' },
|
|
161
|
-
})
|
|
162
|
-
// 5.2. Respond with your mock data:
|
|
163
|
-
// https://bit.ly/zimic-interceptor-http#http-handlerresponddeclaration
|
|
164
|
-
.respond({
|
|
165
|
-
status: 200,
|
|
166
|
-
body: users,
|
|
167
|
-
})
|
|
168
|
-
// 5.3. Define how many requests you expect your application to make:
|
|
169
|
-
// https://bit.ly/zimic-interceptor-http#http-handlertimes
|
|
170
|
-
.times(1);
|
|
171
|
-
|
|
172
|
-
// 6. Run your application and make requests:
|
|
173
|
-
// ...
|
|
174
|
-
|
|
175
|
-
// 7. Check the requests you expect:
|
|
176
|
-
// https://bit.ly/zimic-interceptor-http#http-handlerrequests
|
|
177
|
-
//
|
|
178
|
-
// NOTE: The code below checks the requests manually. This is optional in this
|
|
179
|
-
// example because the `with` and `times` calls act as a declarative validation,
|
|
180
|
-
// meaning that exactly one request is expected with specific data. If fewer or
|
|
181
|
-
// more requests are received, the test will fail when `myInterceptor.checkTimes()`
|
|
182
|
-
// is called in the `afterEach` hook.
|
|
183
|
-
const requests = myHandler.requests();
|
|
184
|
-
expect(requests).toHaveLength(1);
|
|
185
|
-
|
|
186
|
-
expect(requests[0].headers.get('authorization')).toBe('Bearer my-token');
|
|
187
|
-
|
|
188
|
-
expect(requests[0].searchParams.size).toBe(1);
|
|
189
|
-
expect(requests[0].searchParams.get('username')).toBe('my');
|
|
190
|
-
|
|
191
|
-
expect(requests[0].body).toBe(null);
|
|
192
|
-
});
|
|
193
|
-
```
|
|
137
|
+
}>;
|
|
138
|
+
```
|
|
194
139
|
|
|
195
|
-
|
|
140
|
+
You can also use [`zimic-http typegen`](https://github.com/zimicjs/zimic/wiki/cli‐zimic‐typegen) to automatically
|
|
141
|
+
generate types for your HTTP schema.
|
|
196
142
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
143
|
+
2. Create your
|
|
144
|
+
[interceptor](https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httpinterceptorcreateoptions):
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
import { httpInterceptor } from '@zimic/interceptor/http';
|
|
148
|
+
|
|
149
|
+
const interceptor = httpInterceptor.create<Schema>({
|
|
150
|
+
type: 'local',
|
|
151
|
+
baseURL: 'http://localhost:3000',
|
|
152
|
+
saveRequests: true, // Allow access to `handler.requests()`
|
|
153
|
+
});
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
3. Manage your [interceptor lifecycle](https://github.com/zimicjs/zimic/wiki/guides‐testing‐interceptor):
|
|
157
|
+
|
|
158
|
+
4.1.
|
|
159
|
+
[Start intercepting requests](https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorstart):
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
beforeAll(async () => {
|
|
163
|
+
await interceptor.start();
|
|
164
|
+
});
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
4.2.
|
|
168
|
+
[Clear your interceptors](https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorclear) so
|
|
169
|
+
that no tests affect each other:
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
beforeEach(() => {
|
|
173
|
+
interceptor.clear();
|
|
174
|
+
});
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
4.3.
|
|
178
|
+
[Check that all expected requests were made](https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorchecktimes):
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
afterEach(() => {
|
|
182
|
+
interceptor.checkTimes();
|
|
183
|
+
});
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
4.4.
|
|
187
|
+
[Stop intercepting requests](https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorstop):
|
|
188
|
+
|
|
189
|
+
```ts
|
|
190
|
+
afterAll(async () => {
|
|
191
|
+
await interceptor.stop();
|
|
192
|
+
});
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
4. Enjoy mocking!
|
|
196
|
+
|
|
197
|
+
5.1. Mock a response:
|
|
198
|
+
|
|
199
|
+
```ts
|
|
200
|
+
test('example', async () => {
|
|
201
|
+
const users: User[] = [{ username: 'me' }];
|
|
202
|
+
|
|
203
|
+
const handler = interceptor
|
|
204
|
+
.get('/users')
|
|
205
|
+
.with({
|
|
206
|
+
headers: { authorization: 'Bearer my-token' },
|
|
207
|
+
searchParams: { query: 'u' },
|
|
208
|
+
})
|
|
209
|
+
.respond({
|
|
210
|
+
status: 200,
|
|
211
|
+
body: users,
|
|
212
|
+
})
|
|
213
|
+
.times(1);
|
|
214
|
+
|
|
215
|
+
/// ...
|
|
216
|
+
});
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Learn more about
|
|
220
|
+
[`with(restrictions)`](https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction),
|
|
221
|
+
[`respond(declaration)`](https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerresponddeclaration),
|
|
222
|
+
and [`times(times)`](https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlertimes).
|
|
223
|
+
|
|
224
|
+
5.2. After your application made requests, check if they are as you expect:
|
|
225
|
+
|
|
226
|
+
```ts
|
|
227
|
+
test('example', async () => {
|
|
228
|
+
// Your application makes requests...
|
|
229
|
+
|
|
230
|
+
const requests = handler.requests();
|
|
231
|
+
expect(requests).toHaveLength(1);
|
|
232
|
+
|
|
233
|
+
expect(requests[0].headers.get('authorization')).toBe('Bearer my-token');
|
|
234
|
+
|
|
235
|
+
expect(requests[0].searchParams.size).toBe(1);
|
|
236
|
+
expect(requests[0].searchParams.get('username')).toBe('my');
|
|
237
|
+
|
|
238
|
+
expect(requests[0].body).toBe(null);
|
|
239
|
+
});
|
|
240
|
+
```
|
|
203
241
|
|
|
204
242
|
> [!NOTE]
|
|
205
243
|
>
|
|
206
|
-
>
|
|
207
|
-
>
|
|
208
|
-
>
|
|
209
|
-
>
|
|
210
|
-
>
|
|
211
|
-
>
|
|
212
|
-
>
|
|
213
|
-
|
|
214
|
-
|
|
244
|
+
> The 5.2 checks the application requests manually. This is optional in this example because the
|
|
245
|
+
> [`with`](https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction) and
|
|
246
|
+
> [`times`](https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlertimes) calls (step 5.1) already
|
|
247
|
+
> act as a declarative validation, expressing that exactly one request is expected with specific data. If fewer or more
|
|
248
|
+
> requests are received, the test will fail when
|
|
249
|
+
> [`interceptor.checkTimes()`](https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorchecktimes)
|
|
250
|
+
> is called in the `afterEach` hook.
|
|
251
|
+
|
|
252
|
+
## Documentation
|
|
253
|
+
|
|
254
|
+
- [Getting started](https://github.com/zimicjs/zimic/wiki/getting‐started‐interceptor)
|
|
255
|
+
- [API reference](https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http)
|
|
256
|
+
- CLI reference
|
|
257
|
+
- [Browser](https://github.com/zimicjs/zimic/wiki/cli‐zimic‐interceptor‐browser)
|
|
258
|
+
- [Server](https://github.com/zimicjs/zimic/wiki/cli‐zimic‐interceptor‐server)
|
|
259
|
+
- Guides
|
|
260
|
+
- [Testing](https://github.com/zimicjs/zimic/wiki/guides‐testing‐interceptor)
|
|
215
261
|
|
|
216
262
|
## Examples
|
|
217
263
|
|
|
218
|
-
Visit our [examples](../../examples/README.md) to see how to use Zimic with popular frameworks, libraries, and use
|
|
264
|
+
Visit our [examples](../../examples/README.md) to see how to use Zimic with popular frameworks, libraries, and use
|
|
265
|
+
cases.
|
|
219
266
|
|
|
220
267
|
## Changelog
|
|
221
268
|
|
|
@@ -16,12 +16,12 @@ var ClientSocket__default = /*#__PURE__*/_interopDefault(ClientSocket);
|
|
|
16
16
|
var __defProp = Object.defineProperty;
|
|
17
17
|
var __name2 = /* @__PURE__ */ chunkWCQVDF3K_js.__name((target, value) => __defProp(target, "name", { value, configurable: true }), "__name");
|
|
18
18
|
|
|
19
|
-
// ../zimic-utils/dist/chunk-
|
|
19
|
+
// ../zimic-utils/dist/chunk-RIVHLEFF.mjs
|
|
20
20
|
var URL_PATH_PARAM_REGEX = /\/:([^/]+)/g;
|
|
21
21
|
function createRegExpFromURL(url) {
|
|
22
22
|
URL_PATH_PARAM_REGEX.lastIndex = 0;
|
|
23
|
-
const urlWithReplacedPathParams = encodeURI(url).replace(/([.()*?+$\\])/g, "\\$1").replace(URL_PATH_PARAM_REGEX, "/(?<$1>[^/]+)").replace(
|
|
24
|
-
return new RegExp(
|
|
23
|
+
const urlWithReplacedPathParams = encodeURI(url).replace(/([.()*?+$\\])/g, "\\$1").replace(URL_PATH_PARAM_REGEX, "/(?<$1>[^/]+)").replace(/^(\/)|(\/)$/g, "");
|
|
24
|
+
return new RegExp(`^(?:/)?${urlWithReplacedPathParams}(?:/)?$`);
|
|
25
25
|
}
|
|
26
26
|
chunkWCQVDF3K_js.__name(createRegExpFromURL, "createRegExpFromURL");
|
|
27
27
|
__name2(createRegExpFromURL, "createRegExpFromURL");
|
|
@@ -41,7 +41,7 @@ var excludeURLParams_default = excludeURLParams;
|
|
|
41
41
|
|
|
42
42
|
// ../zimic-utils/dist/chunk-3O5CS47X.mjs
|
|
43
43
|
function isDefined(value) {
|
|
44
|
-
return value !==
|
|
44
|
+
return value !== void 0 && value !== null;
|
|
45
45
|
}
|
|
46
46
|
chunkWCQVDF3K_js.__name(isDefined, "isDefined");
|
|
47
47
|
__name2(isDefined, "isDefined");
|
|
@@ -65,7 +65,7 @@ chunkWCQVDF3K_js.__name(removeArrayElement, "removeArrayElement");
|
|
|
65
65
|
function createCachedDynamicImport(importModuleDynamically) {
|
|
66
66
|
let cachedImportResult;
|
|
67
67
|
return /* @__PURE__ */ __name2(/* @__PURE__ */ chunkWCQVDF3K_js.__name(async function importModuleDynamicallyWithCache() {
|
|
68
|
-
if (cachedImportResult ===
|
|
68
|
+
if (cachedImportResult === void 0) {
|
|
69
69
|
cachedImportResult = await importModuleDynamically();
|
|
70
70
|
}
|
|
71
71
|
return cachedImportResult;
|
|
@@ -77,7 +77,7 @@ var createCachedDynamicImport_default = createCachedDynamicImport;
|
|
|
77
77
|
|
|
78
78
|
// src/utils/environment.ts
|
|
79
79
|
function isClientSide() {
|
|
80
|
-
return typeof window !== "undefined";
|
|
80
|
+
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
81
81
|
}
|
|
82
82
|
chunkWCQVDF3K_js.__name(isClientSide, "isClientSide");
|
|
83
83
|
|
|
@@ -186,7 +186,7 @@ chunkWCQVDF3K_js.__name(stopHttpServer, "stopHttpServer");
|
|
|
186
186
|
function getHttpServerPort(server) {
|
|
187
187
|
const address = server.address();
|
|
188
188
|
if (typeof address === "string") {
|
|
189
|
-
return
|
|
189
|
+
return void 0;
|
|
190
190
|
} else {
|
|
191
191
|
return address?.port;
|
|
192
192
|
}
|
|
@@ -329,7 +329,7 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
|
|
|
329
329
|
this.stoppingPromise = stoppingResult;
|
|
330
330
|
await this.stoppingPromise;
|
|
331
331
|
}
|
|
332
|
-
this.stoppingPromise =
|
|
332
|
+
this.stoppingPromise = void 0;
|
|
333
333
|
}
|
|
334
334
|
async logUnhandledRequestIfNecessary(request, strategy) {
|
|
335
335
|
if (strategy?.log) {
|
|
@@ -414,7 +414,7 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
|
|
|
414
414
|
if (!canHaveBody) {
|
|
415
415
|
return new Response(null, { headers, status });
|
|
416
416
|
}
|
|
417
|
-
if (typeof declaration.body === "string" || declaration.body ===
|
|
417
|
+
if (typeof declaration.body === "string" || declaration.body === void 0 || declaration.body instanceof FormData || declaration.body instanceof URLSearchParams || declaration.body instanceof Blob || declaration.body instanceof ArrayBuffer) {
|
|
418
418
|
return new Response(declaration.body ?? null, { headers, status });
|
|
419
419
|
}
|
|
420
420
|
return Response.json(declaration.body, { headers, status });
|
|
@@ -441,7 +441,7 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
|
|
|
441
441
|
},
|
|
442
442
|
get(target, property) {
|
|
443
443
|
if (_HttpInterceptorWorker.isHiddenRequestProperty(property)) {
|
|
444
|
-
return
|
|
444
|
+
return void 0;
|
|
445
445
|
}
|
|
446
446
|
return Reflect.get(target, property, target);
|
|
447
447
|
}
|
|
@@ -495,7 +495,7 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
|
|
|
495
495
|
},
|
|
496
496
|
get(target, property) {
|
|
497
497
|
if (_HttpInterceptorWorker.isHiddenResponseProperty(property)) {
|
|
498
|
-
return
|
|
498
|
+
return void 0;
|
|
499
499
|
}
|
|
500
500
|
return Reflect.get(target, property, target);
|
|
501
501
|
}
|
|
@@ -1101,7 +1101,7 @@ var WebSocketServer = class extends WebSocketHandler_default {
|
|
|
1101
1101
|
this.httpServer = options.httpServer;
|
|
1102
1102
|
}
|
|
1103
1103
|
isRunning() {
|
|
1104
|
-
return this.webSocketServer !==
|
|
1104
|
+
return this.webSocketServer !== void 0;
|
|
1105
1105
|
}
|
|
1106
1106
|
start() {
|
|
1107
1107
|
if (this.isRunning()) {
|
|
@@ -1129,7 +1129,7 @@ var WebSocketServer = class extends WebSocketHandler_default {
|
|
|
1129
1129
|
await super.closeClientSockets();
|
|
1130
1130
|
await closeServerSocket(this.webSocketServer, { timeout: this.socketTimeout() });
|
|
1131
1131
|
this.webSocketServer.removeAllListeners();
|
|
1132
|
-
this.webSocketServer =
|
|
1132
|
+
this.webSocketServer = void 0;
|
|
1133
1133
|
}
|
|
1134
1134
|
};
|
|
1135
1135
|
var WebSocketServer_default = WebSocketServer;
|
|
@@ -1219,8 +1219,8 @@ var InterceptorServer = class {
|
|
|
1219
1219
|
return this._logUnhandledRequests;
|
|
1220
1220
|
}
|
|
1221
1221
|
httpURL() {
|
|
1222
|
-
if (this._port ===
|
|
1223
|
-
return
|
|
1222
|
+
if (this._port === void 0) {
|
|
1223
|
+
return void 0;
|
|
1224
1224
|
}
|
|
1225
1225
|
return `http://${this._hostname}:${this._port}`;
|
|
1226
1226
|
}
|
|
@@ -1277,7 +1277,7 @@ var InterceptorServer = class {
|
|
|
1277
1277
|
resetWorker = /* @__PURE__ */ chunkWCQVDF3K_js.__name((message, socket) => {
|
|
1278
1278
|
this.removeHttpHandlersBySocket(socket);
|
|
1279
1279
|
const handlersToResetTo = message.data;
|
|
1280
|
-
const isWorkerNoLongerCommitted = handlersToResetTo ===
|
|
1280
|
+
const isWorkerNoLongerCommitted = handlersToResetTo === void 0;
|
|
1281
1281
|
if (isWorkerNoLongerCommitted) {
|
|
1282
1282
|
this.webSocketServer().abortSocketMessages([socket]);
|
|
1283
1283
|
} else {
|
|
@@ -1328,14 +1328,14 @@ var InterceptorServer = class {
|
|
|
1328
1328
|
const httpServer = this.httpServer();
|
|
1329
1329
|
await stopHttpServer(httpServer);
|
|
1330
1330
|
httpServer.removeAllListeners();
|
|
1331
|
-
this._httpServer =
|
|
1331
|
+
this._httpServer = void 0;
|
|
1332
1332
|
}
|
|
1333
1333
|
async stopWebSocketServer() {
|
|
1334
1334
|
const webSocketServer = this.webSocketServer();
|
|
1335
1335
|
webSocketServer.offEvent("interceptors/workers/use/commit", this.commitWorker);
|
|
1336
1336
|
webSocketServer.offEvent("interceptors/workers/use/reset", this.resetWorker);
|
|
1337
1337
|
await webSocketServer.stop();
|
|
1338
|
-
this._webSocketServer =
|
|
1338
|
+
this._webSocketServer = void 0;
|
|
1339
1339
|
}
|
|
1340
1340
|
handleHttpRequest = /* @__PURE__ */ chunkWCQVDF3K_js.__name(async (nodeRequest, nodeResponse) => {
|
|
1341
1341
|
const request = server.normalizeNodeRequest(nodeRequest, await getFetchAPI());
|
|
@@ -1494,5 +1494,5 @@ exports.NotStartedInterceptorServerError_default = NotStartedInterceptorServerEr
|
|
|
1494
1494
|
exports.createCachedDynamicImport_default = createCachedDynamicImport_default;
|
|
1495
1495
|
exports.interceptorServer = interceptorServer;
|
|
1496
1496
|
exports.logWithPrefix = logWithPrefix;
|
|
1497
|
-
//# sourceMappingURL=chunk-
|
|
1498
|
-
//# sourceMappingURL=chunk-
|
|
1497
|
+
//# sourceMappingURL=chunk-3623PRKE.js.map
|
|
1498
|
+
//# sourceMappingURL=chunk-3623PRKE.js.map
|