Skip to content

Commit b041d46

Browse files
committed
test: use readable browser response fixtures
1 parent ee9422d commit b041d46

2 files changed

Lines changed: 23 additions & 19 deletions

File tree

extensions/browser/src/browser/pw-session.get-page-for-targetid.extension-fallback.test.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,15 @@ describe("pw-session getPageForTargetId", () => {
146146
urls: ["https://alpha.example", "https://beta.example"],
147147
}).pages;
148148

149-
const fetchSpy = vi.spyOn(globalThis, "fetch").mockResolvedValue({
150-
ok: true,
151-
json: async () => [
152-
{ id: "TARGET_A", url: "https://alpha.example" },
153-
{ id: "TARGET_B", url: "https://beta.example" },
154-
],
155-
} as Response);
149+
const fetchSpy = vi.spyOn(globalThis, "fetch").mockResolvedValue(
150+
new Response(
151+
JSON.stringify([
152+
{ id: "TARGET_A", url: "https://alpha.example" },
153+
{ id: "TARGET_B", url: "https://beta.example" },
154+
]),
155+
{ headers: { "content-type": "application/json" } },
156+
),
157+
);
156158

157159
try {
158160
const resolved = await getPageForTargetId({
@@ -180,13 +182,15 @@ describe("pw-session getPageForTargetId", () => {
180182
});
181183
const [, pageB] = pages;
182184

183-
const fetchSpy = vi.spyOn(globalThis, "fetch").mockResolvedValue({
184-
ok: true,
185-
json: async () => [
186-
{ id: "TARGET_A", url: "https://alpha.example" },
187-
{ id: "TARGET_B", url: "https://beta.example" },
188-
],
189-
} as Response);
185+
const fetchSpy = vi.spyOn(globalThis, "fetch").mockResolvedValue(
186+
new Response(
187+
JSON.stringify([
188+
{ id: "TARGET_A", url: "https://alpha.example" },
189+
{ id: "TARGET_B", url: "https://beta.example" },
190+
]),
191+
{ headers: { "content-type": "application/json" } },
192+
),
193+
);
190194

191195
try {
192196
const resolved = await getPageForTargetId({

extensions/browser/src/browser/routes/tabs.attach-only.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ describe("browser tab routes attachOnly loopback profiles", () => {
3939

4040
const fetchMock = vi.fn(async (url: unknown) => {
4141
expect(String(url)).toBe("http://127.0.0.1:9222/json/list");
42-
return {
43-
ok: true,
44-
json: async () => [
42+
return new Response(
43+
JSON.stringify([
4544
{
4645
id: "PAGE-1",
4746
title: "WordPress",
4847
url: "https://example.com/wp-login.php",
4948
webSocketDebuggerUrl: "ws://127.0.0.1:9222/devtools/page/PAGE-1",
5049
type: "page",
5150
},
52-
],
53-
} as unknown as Response;
51+
]),
52+
{ headers: { "content-type": "application/json" } },
53+
);
5454
});
5555
vi.stubGlobal("fetch", fetchMock);
5656

0 commit comments

Comments
 (0)