Skip to content

Commit 44e44c7

Browse files
Use different strategy
1 parent 08357d5 commit 44e44c7

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"branches": 80,
3-
"functions": 90.06,
2+
"branches": 80.27,
3+
"functions": 90.13,
44
"lines": 90.77,
55
"statements": 90.15
66
}

packages/snaps-execution-environments/src/common/endowments/network.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,14 @@ describe('Network endowments', () => {
180180
const RESULT = 'OK';
181181
fetchMock.mockOnce(async () => Promise.resolve(RESULT));
182182

183-
const { fetch } = network.factory(factoryOptions);
183+
const { fetch, Response } = network.factory(factoryOptions);
184184
const result = await fetch('foo.com');
185185

186186
expect(result.bodyUsed).toBe(false);
187187
const clonedResult = result.clone();
188188
expect(clonedResult).toBeDefined();
189189
expect(await clonedResult.text()).toBe(RESULT);
190+
expect(clonedResult).toBeInstanceOf(Response);
190191
expect(clonedResult).toBeInstanceOf(ResponseWrapper);
191192
});
192193

packages/snaps-execution-environments/src/common/endowments/network.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { EndowmentFactoryOptions } from './commonEndowmentFactory';
77
* This class wraps a Response object.
88
* That way, a teardown process can stop any processes left.
99
*/
10-
export class ResponseWrapper extends Response {
10+
export class ResponseWrapper {
1111
readonly #teardownRef: { lastTeardown: number };
1212

1313
#ogResponse: Response;
@@ -22,7 +22,6 @@ export class ResponseWrapper extends Response {
2222
onStart: () => Promise<void>,
2323
onFinish: () => Promise<void>,
2424
) {
25-
super();
2625
this.#ogResponse = ogResponse;
2726
this.#teardownRef = teardownRef;
2827
this.#onStart = onStart;
@@ -146,6 +145,12 @@ export class ResponseWrapper extends Response {
146145
}
147146
}
148147

148+
class AlteredResponse extends Response {
149+
static [Symbol.hasInstance](instance: any) {
150+
return instance instanceof Response || instance instanceof ResponseWrapper;
151+
}
152+
}
153+
149154
/**
150155
* Create a network endowment, consisting of a `fetch` function.
151156
* This allows us to provide a teardown function, so that we can cancel
@@ -298,7 +303,7 @@ const createNetwork = ({ notify }: EndowmentFactoryOptions = {}) => {
298303
// These endowments are not (and should never be) available by default.
299304
Request: harden(Request),
300305
Headers: harden(Headers),
301-
Response: harden(Response),
306+
Response: harden(AlteredResponse),
302307
teardownFunction,
303308
};
304309
};

0 commit comments

Comments
 (0)