|
| 1 | +import { FetchRequest } from '@mswjs/interceptors' |
1 | 2 | import { http } from '#http/http' |
2 | 3 | import { graphql } from '../../../graphql' |
3 | 4 | import { ws } from '../../../ws' |
@@ -169,6 +170,54 @@ test('resolves a non-matching request', async () => { |
169 | 170 | ]) |
170 | 171 | }) |
171 | 172 |
|
| 173 | +/** |
| 174 | + * @todo Revisit the `http.all()` handler below once `http.connect()` |
| 175 | + * is supported: a matching CONNECT handler must take precedence. |
| 176 | + */ |
| 177 | +test('passes through an unhandled CONNECT request without applying the unhandled frame strategy', async () => { |
| 178 | + class HttpFrame extends HttpNetworkFrame { |
| 179 | + respondWith = vi.fn() |
| 180 | + passthrough = vi.fn() |
| 181 | + errorWith = vi.fn() |
| 182 | + } |
| 183 | + |
| 184 | + const frame = new HttpFrame({ |
| 185 | + request: new FetchRequest('http://localhost/127.0.0.1:443', { |
| 186 | + method: 'CONNECT', |
| 187 | + }), |
| 188 | + }) |
| 189 | + const { events } = spyOnNetworkFrame(frame) |
| 190 | + const unhandledFrameCallback = vi.fn() |
| 191 | + |
| 192 | + const matches = await frame.resolve( |
| 193 | + [ |
| 194 | + http.all('*', () => { |
| 195 | + return new Response(null, { status: 204 }) |
| 196 | + }), |
| 197 | + ], |
| 198 | + unhandledFrameCallback, |
| 199 | + { quiet: true }, |
| 200 | + ) |
| 201 | + |
| 202 | + expect.soft(matches).toBe(null) |
| 203 | + expect.soft(frame.passthrough).toHaveBeenCalledOnce() |
| 204 | + expect.soft(frame.respondWith).not.toHaveBeenCalled() |
| 205 | + expect.soft(frame.errorWith).not.toHaveBeenCalled() |
| 206 | + expect.soft(unhandledFrameCallback).not.toHaveBeenCalled() |
| 207 | + expect.soft(events).toEqual([ |
| 208 | + expect.objectContaining({ |
| 209 | + type: 'request:start', |
| 210 | + requestId: frame.data.id, |
| 211 | + request: frame.data.request, |
| 212 | + }), |
| 213 | + expect.objectContaining({ |
| 214 | + type: 'request:end', |
| 215 | + requestId: frame.data.id, |
| 216 | + request: frame.data.request, |
| 217 | + }), |
| 218 | + ]) |
| 219 | +}) |
| 220 | + |
172 | 221 | test('resolves a matched passthrough', async () => { |
173 | 222 | class HttpFrame extends HttpNetworkFrame { |
174 | 223 | respondWith = vi.fn() |
|
0 commit comments