Skip to content

Commit 837a381

Browse files
committed
test: update snapshots for Proxy-based Response wrapper
All snapshot tests updated to reflect the new Proxy implementation. The generated code now uses Proxy for dynamic property delegation instead of static property copying. All 133 tests passing with updated snapshots.
1 parent 59bb4c7 commit 837a381

File tree

28 files changed

+4662
-2508
lines changed

28 files changed

+4662
-2508
lines changed

tests/__snapshots__/extended.test.ts.snap

Lines changed: 1804 additions & 968 deletions
Large diffs are not rendered by default.

tests/__snapshots__/simple.test.ts.snap

Lines changed: 1804 additions & 968 deletions
Large diffs are not rendered by default.

tests/spec/another-query-params/__snapshots__/basic.test.ts.snap

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -265,29 +265,48 @@ export class HttpClient<SecurityDataType = unknown> {
265265
: payloadFormatter(body),
266266
},
267267
).then(async (response) => {
268-
// Create a wrapper object that doesn't mutate the Response
268+
// Create a Proxy that wraps the Response without mutating it
269269
// This ensures compatibility with ESM environments where Response is read-only
270-
const r = {
271-
data: null as unknown as T,
272-
error: null as unknown as E,
273-
// Delegate Response properties
274-
ok: response.ok,
275-
status: response.status,
276-
statusText: response.statusText,
277-
headers: response.headers,
278-
url: response.url,
279-
redirected: response.redirected,
280-
type: response.type,
281-
body: response.body,
282-
bodyUsed: response.bodyUsed,
283-
// Delegate Response methods
284-
arrayBuffer: () => response.arrayBuffer(),
285-
blob: () => response.blob(),
286-
clone: () => response.clone(),
287-
formData: () => response.formData(),
288-
json: () => response.json(),
289-
text: () => response.text(),
290-
} as HttpResponse<T, E>;
270+
// while maintaining all Response properties and methods as live/dynamic values
271+
const r = new Proxy(response, {
272+
get(target, prop) {
273+
// Custom properties for our API wrapper
274+
if (prop === "data") {
275+
return target._data !== undefined
276+
? target._data
277+
: (null as unknown as T);
278+
}
279+
if (prop === "error") {
280+
return target._error !== undefined
281+
? target._error
282+
: (null as unknown as E);
283+
}
284+
285+
// Delegate everything else to the actual Response object
286+
const value = target[prop];
287+
288+
// Bind methods to the original response to maintain correct 'this' context
289+
if (typeof value === "function") {
290+
return value.bind(target);
291+
}
292+
293+
return value;
294+
},
295+
set(target, prop, value) {
296+
// Allow setting data and error properties
297+
if (prop === "data") {
298+
target._data = value;
299+
return true;
300+
}
301+
if (prop === "error") {
302+
target._error = value;
303+
return true;
304+
}
305+
306+
// Prevent mutation of Response properties (ESM safety)
307+
return false;
308+
},
309+
}) as HttpResponse<T, E>;
291310
292311
const responseToParse = responseFormat ? response.clone() : response;
293312
const data = !responseFormat

tests/spec/custom-extensions/__snapshots__/basic.test.ts.snap

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -237,29 +237,48 @@ export class HttpClient<SecurityDataType = unknown> {
237237
: payloadFormatter(body),
238238
},
239239
).then(async (response) => {
240-
// Create a wrapper object that doesn't mutate the Response
240+
// Create a Proxy that wraps the Response without mutating it
241241
// This ensures compatibility with ESM environments where Response is read-only
242-
const r = {
243-
data: null as unknown as T,
244-
error: null as unknown as E,
245-
// Delegate Response properties
246-
ok: response.ok,
247-
status: response.status,
248-
statusText: response.statusText,
249-
headers: response.headers,
250-
url: response.url,
251-
redirected: response.redirected,
252-
type: response.type,
253-
body: response.body,
254-
bodyUsed: response.bodyUsed,
255-
// Delegate Response methods
256-
arrayBuffer: () => response.arrayBuffer(),
257-
blob: () => response.blob(),
258-
clone: () => response.clone(),
259-
formData: () => response.formData(),
260-
json: () => response.json(),
261-
text: () => response.text(),
262-
} as HttpResponse<T, E>;
242+
// while maintaining all Response properties and methods as live/dynamic values
243+
const r = new Proxy(response, {
244+
get(target, prop) {
245+
// Custom properties for our API wrapper
246+
if (prop === "data") {
247+
return target._data !== undefined
248+
? target._data
249+
: (null as unknown as T);
250+
}
251+
if (prop === "error") {
252+
return target._error !== undefined
253+
? target._error
254+
: (null as unknown as E);
255+
}
256+
257+
// Delegate everything else to the actual Response object
258+
const value = target[prop];
259+
260+
// Bind methods to the original response to maintain correct 'this' context
261+
if (typeof value === "function") {
262+
return value.bind(target);
263+
}
264+
265+
return value;
266+
},
267+
set(target, prop, value) {
268+
// Allow setting data and error properties
269+
if (prop === "data") {
270+
target._data = value;
271+
return true;
272+
}
273+
if (prop === "error") {
274+
target._error = value;
275+
return true;
276+
}
277+
278+
// Prevent mutation of Response properties (ESM safety)
279+
return false;
280+
},
281+
}) as HttpResponse<T, E>;
263282
264283
const responseToParse = responseFormat ? response.clone() : response;
265284
const data = !responseFormat

tests/spec/defaultAsSuccess/__snapshots__/basic.test.ts.snap

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -277,29 +277,48 @@ export class HttpClient<SecurityDataType = unknown> {
277277
: payloadFormatter(body),
278278
},
279279
).then(async (response) => {
280-
// Create a wrapper object that doesn't mutate the Response
280+
// Create a Proxy that wraps the Response without mutating it
281281
// This ensures compatibility with ESM environments where Response is read-only
282-
const r = {
283-
data: null as unknown as T,
284-
error: null as unknown as E,
285-
// Delegate Response properties
286-
ok: response.ok,
287-
status: response.status,
288-
statusText: response.statusText,
289-
headers: response.headers,
290-
url: response.url,
291-
redirected: response.redirected,
292-
type: response.type,
293-
body: response.body,
294-
bodyUsed: response.bodyUsed,
295-
// Delegate Response methods
296-
arrayBuffer: () => response.arrayBuffer(),
297-
blob: () => response.blob(),
298-
clone: () => response.clone(),
299-
formData: () => response.formData(),
300-
json: () => response.json(),
301-
text: () => response.text(),
302-
} as HttpResponse<T, E>;
282+
// while maintaining all Response properties and methods as live/dynamic values
283+
const r = new Proxy(response, {
284+
get(target, prop) {
285+
// Custom properties for our API wrapper
286+
if (prop === "data") {
287+
return target._data !== undefined
288+
? target._data
289+
: (null as unknown as T);
290+
}
291+
if (prop === "error") {
292+
return target._error !== undefined
293+
? target._error
294+
: (null as unknown as E);
295+
}
296+
297+
// Delegate everything else to the actual Response object
298+
const value = target[prop];
299+
300+
// Bind methods to the original response to maintain correct 'this' context
301+
if (typeof value === "function") {
302+
return value.bind(target);
303+
}
304+
305+
return value;
306+
},
307+
set(target, prop, value) {
308+
// Allow setting data and error properties
309+
if (prop === "data") {
310+
target._data = value;
311+
return true;
312+
}
313+
if (prop === "error") {
314+
target._error = value;
315+
return true;
316+
}
317+
318+
// Prevent mutation of Response properties (ESM safety)
319+
return false;
320+
},
321+
}) as HttpResponse<T, E>;
303322
304323
const responseToParse = responseFormat ? response.clone() : response;
305324
const data = !responseFormat

tests/spec/defaultResponse/__snapshots__/basic.test.ts.snap

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -237,29 +237,48 @@ export class HttpClient<SecurityDataType = unknown> {
237237
: payloadFormatter(body),
238238
},
239239
).then(async (response) => {
240-
// Create a wrapper object that doesn't mutate the Response
240+
// Create a Proxy that wraps the Response without mutating it
241241
// This ensures compatibility with ESM environments where Response is read-only
242-
const r = {
243-
data: null as unknown as T,
244-
error: null as unknown as E,
245-
// Delegate Response properties
246-
ok: response.ok,
247-
status: response.status,
248-
statusText: response.statusText,
249-
headers: response.headers,
250-
url: response.url,
251-
redirected: response.redirected,
252-
type: response.type,
253-
body: response.body,
254-
bodyUsed: response.bodyUsed,
255-
// Delegate Response methods
256-
arrayBuffer: () => response.arrayBuffer(),
257-
blob: () => response.blob(),
258-
clone: () => response.clone(),
259-
formData: () => response.formData(),
260-
json: () => response.json(),
261-
text: () => response.text(),
262-
} as HttpResponse<T, E>;
242+
// while maintaining all Response properties and methods as live/dynamic values
243+
const r = new Proxy(response, {
244+
get(target, prop) {
245+
// Custom properties for our API wrapper
246+
if (prop === "data") {
247+
return target._data !== undefined
248+
? target._data
249+
: (null as unknown as T);
250+
}
251+
if (prop === "error") {
252+
return target._error !== undefined
253+
? target._error
254+
: (null as unknown as E);
255+
}
256+
257+
// Delegate everything else to the actual Response object
258+
const value = target[prop];
259+
260+
// Bind methods to the original response to maintain correct 'this' context
261+
if (typeof value === "function") {
262+
return value.bind(target);
263+
}
264+
265+
return value;
266+
},
267+
set(target, prop, value) {
268+
// Allow setting data and error properties
269+
if (prop === "data") {
270+
target._data = value;
271+
return true;
272+
}
273+
if (prop === "error") {
274+
target._error = value;
275+
return true;
276+
}
277+
278+
// Prevent mutation of Response properties (ESM safety)
279+
return false;
280+
},
281+
}) as HttpResponse<T, E>;
263282
264283
const responseToParse = responseFormat ? response.clone() : response;
265284
const data = !responseFormat

tests/spec/deprecated/__snapshots__/basic.test.ts.snap

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -237,29 +237,48 @@ export class HttpClient<SecurityDataType = unknown> {
237237
: payloadFormatter(body),
238238
},
239239
).then(async (response) => {
240-
// Create a wrapper object that doesn't mutate the Response
240+
// Create a Proxy that wraps the Response without mutating it
241241
// This ensures compatibility with ESM environments where Response is read-only
242-
const r = {
243-
data: null as unknown as T,
244-
error: null as unknown as E,
245-
// Delegate Response properties
246-
ok: response.ok,
247-
status: response.status,
248-
statusText: response.statusText,
249-
headers: response.headers,
250-
url: response.url,
251-
redirected: response.redirected,
252-
type: response.type,
253-
body: response.body,
254-
bodyUsed: response.bodyUsed,
255-
// Delegate Response methods
256-
arrayBuffer: () => response.arrayBuffer(),
257-
blob: () => response.blob(),
258-
clone: () => response.clone(),
259-
formData: () => response.formData(),
260-
json: () => response.json(),
261-
text: () => response.text(),
262-
} as HttpResponse<T, E>;
242+
// while maintaining all Response properties and methods as live/dynamic values
243+
const r = new Proxy(response, {
244+
get(target, prop) {
245+
// Custom properties for our API wrapper
246+
if (prop === "data") {
247+
return target._data !== undefined
248+
? target._data
249+
: (null as unknown as T);
250+
}
251+
if (prop === "error") {
252+
return target._error !== undefined
253+
? target._error
254+
: (null as unknown as E);
255+
}
256+
257+
// Delegate everything else to the actual Response object
258+
const value = target[prop];
259+
260+
// Bind methods to the original response to maintain correct 'this' context
261+
if (typeof value === "function") {
262+
return value.bind(target);
263+
}
264+
265+
return value;
266+
},
267+
set(target, prop, value) {
268+
// Allow setting data and error properties
269+
if (prop === "data") {
270+
target._data = value;
271+
return true;
272+
}
273+
if (prop === "error") {
274+
target._error = value;
275+
return true;
276+
}
277+
278+
// Prevent mutation of Response properties (ESM safety)
279+
return false;
280+
},
281+
}) as HttpResponse<T, E>;
263282
264283
const responseToParse = responseFormat ? response.clone() : response;
265284
const data = !responseFormat

0 commit comments

Comments
 (0)