Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/orange-suns-follow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cronn/playwright-utils": patch
---

Suspended routes will now fallback to other previously registered routes when they are released.
2 changes: 1 addition & 1 deletion src/api/route-interceptor/interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ async function withSuspendedRoute<T = void>(
return;
}

const suspendedRoute = barrier.promise.then(() => route.continue());
const suspendedRoute = barrier.promise.then(() => route.fallback());

suspendedRoutes.add(suspendedRoute);
try {
Expand Down
35 changes: 35 additions & 0 deletions tests/route-interceptor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,38 @@ customTest("Wait for request and response", async ({ page, intercept }) => {
await expect(response).rejects.toThrow(/Timeout 1000ms exceeded/);
});
});

customTest(
"Released suspended route falls back to surrounding interceptor",
async ({ page, intercept }) => {
const loadingIndicator = page.getByRole("progressbar");
const fetchUserButton = page.getByRole("button", { name: "Fetch user" });
const count = page.getByRole("textbox", { name: "Count" });
const responseStatus = page.locator("#api-response-status");

await test.step("Open page", async () => {
await page.goto(serverURL);
await openTestPage(page);
await expect(count).toHaveValue("0");
});

await intercept
.onGetUser()
.respondWith({
status: 500,
json: { error: "Internal Server Error" },
})
.during(async () => {
await intercept
.onGetUser()
.suspend()
.during(async () => {
await fetchUserButton.click();
await expect(loadingIndicator).toBeVisible();
});

await expect(count).toHaveValue("1");
await expect(responseStatus).toHaveText("500");
});
},
);
Loading