Skip to content

Commit 08861ac

Browse files
committed
test: stability fixes for python e2e tests
1 parent 57f5b75 commit 08861ac

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,12 @@ describe("SuperTokens Email Verification", function () {
427427
await page.waitForSelector(".sessionInfo-user-id");
428428
await waitForUrl(page, "/dashboard");
429429

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

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

test/helpers.js

+9-17
Original file line numberDiff line numberDiff line change
@@ -516,23 +516,15 @@ export async function submitFormReturnRequestAndResponse(page, URL) {
516516
};
517517
}
518518

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

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

0 commit comments

Comments
 (0)