Skip to content

Commit

Permalink
test: stability fixes for python e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
porcellus committed Nov 27, 2024
1 parent be15381 commit 8e15196
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
7 changes: 6 additions & 1 deletion test/end-to-end/emailverification.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,12 @@ describe("SuperTokens Email Verification", function () {
await page.waitForSelector(".sessionInfo-user-id");
await waitForUrl(page, "/dashboard");

await page.evaluate((url) => window.fetch(url), `${TEST_APPLICATION_SERVER_BASE_URL}/unverifyEmail`);
await Promise.all([
page.waitForResponse(
(response) => response.url() === SEND_VERIFY_EMAIL_API && response.status() === 200
),
page.evaluate((url) => window.fetch(url), `${TEST_APPLICATION_SERVER_BASE_URL}/unverifyEmail`),
]);
await waitForSTElement(page, "[data-supertokens~='sendVerifyEmailIcon']");

await waitForUrl(page, "/auth/verify-email");
Expand Down
26 changes: 9 additions & 17 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,23 +514,15 @@ export async function submitFormReturnRequestAndResponse(page, URL) {
};
}

export async function hasMethodBeenCalled(page, URL, method = "GET", timeout = 1000) {
let methodCalled = false;

const onRequestVerifyMatch = (request) => {
// If method called before hasMethodBeenCalled timeouts, update methodCalled.
if (request.url() === URL && request.method() === method) {
methodCalled = true;
}
request.continue();
};

await page.setRequestInterception(true);
page.on("request", onRequestVerifyMatch);
await new Promise((r) => setTimeout(r, timeout));
await page.setRequestInterception(false);
page.off("request", onRequestVerifyMatch);
return methodCalled;
export async function hasMethodBeenCalled(page, URL, method = "GET", timeout = 2000) {
try {
await page.waitForResponse((response) => response.url() === URL && response.request().method() === method, {
timeout,
});
return true;
} catch (e) {
return false;
}
}

export async function assertFormFieldsEqual(actual, expected, values) {
Expand Down

0 comments on commit 8e15196

Please sign in to comment.