Skip to content

Commit cfa1bb4

Browse files
committed
test: stability fixes for python e2e tests
1 parent cf88b37 commit cfa1bb4

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

test/end-to-end/emailverification.test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,12 @@ describe("SuperTokens Email Verification", function () {
425425
await page.waitForSelector(".sessionInfo-user-id");
426426
await waitForUrl(page, "/dashboard");
427427

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

431436
await waitForUrl(page, "/auth/verify-email");

test/helpers.js

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -514,23 +514,15 @@ export async function submitFormReturnRequestAndResponse(page, URL) {
514514
};
515515
}
516516

517-
export async function hasMethodBeenCalled(page, URL, method = "GET", timeout = 1000) {
518-
let methodCalled = false;
519-
520-
const onRequestVerifyMatch = (request) => {
521-
// If method called before hasMethodBeenCalled timeouts, update methodCalled.
522-
if (request.url() === URL && request.method() === method) {
523-
methodCalled = true;
524-
}
525-
request.continue();
526-
};
527-
528-
await page.setRequestInterception(true);
529-
page.on("request", onRequestVerifyMatch);
530-
await new Promise((r) => setTimeout(r, timeout));
531-
await page.setRequestInterception(false);
532-
page.off("request", onRequestVerifyMatch);
533-
return methodCalled;
517+
export async function hasMethodBeenCalled(page, URL, method = "GET", timeout = 2000) {
518+
try {
519+
await page.waitForResponse((response) => response.url() === URL && response.request().method() === method, {
520+
timeout,
521+
});
522+
return true;
523+
} catch (e) {
524+
return false;
525+
}
534526
}
535527

536528
export async function assertFormFieldsEqual(actual, expected, values) {

0 commit comments

Comments
 (0)