Skip to content

Commit ccded94

Browse files
Get rid of using timeout in tests
1 parent 8319755 commit ccded94

File tree

7 files changed

+236
-231
lines changed

7 files changed

+236
-231
lines changed

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

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ describe("SuperTokens Email Verification", function () {
174174
rid: "emailpassword",
175175
}),
176176
});
177-
await new Promise((r) => setTimeout(r, 11000));
178177

179178
consoleLogs = [];
180179
await page.reload({ waitUntil: ["networkidle0"] });
@@ -255,16 +254,22 @@ describe("SuperTokens Email Verification", function () {
255254
await new Promise((r) => setTimeout(r, 2000));
256255
let pathname = await page.evaluate(() => window.location.pathname);
257256
assert.deepStrictEqual(pathname, "/auth/verify-email");
257+
await waitForUrl(page, "/auth/verify-email");
258+
await waitForSTElement(page, "[data-supertokens~='sendVerifyEmailResend']");
259+
258260
// Click on resend email should show "Email Resent" success message
259261
await sendVerifyEmail(page);
260262
await page.waitForResponse(
261263
(response) => response.url() === SEND_VERIFY_EMAIL_API && response.status() === 200
262264
);
263265
const generalSuccess = await getGeneralSuccess(page);
264266
assert.deepStrictEqual(generalSuccess, "Email resent");
265-
267+
266268
// Click on Logout should remove session and redirect to login page
267-
await Promise.all([clickLinkWithRightArrow(page), page.waitForNavigation({ waitUntil: "networkidle0" })]);
269+
await Promise.all([
270+
clickLinkWithRightArrow(page),
271+
page.waitForNavigation({ waitUntil: "networkidle0" }),
272+
]);
268273
pathname = await page.evaluate(() => window.location.pathname);
269274
assert.deepStrictEqual(pathname, "/auth/");
270275
assert.deepStrictEqual(consoleLogs, [
@@ -289,10 +294,10 @@ describe("SuperTokens Email Verification", function () {
289294
"ST_LOGS SESSION OVERRIDE GET_JWT_PAYLOAD_SECURELY",
290295
"ST_LOGS EMAIL_VERIFICATION OVERRIDE SEND_VERIFICATION_EMAIL",
291296
"ST_LOGS EMAIL_VERIFICATION PRE_API_HOOKS SEND_VERIFY_EMAIL",
292-
"ST_LOGS EMAIL_VERIFICATION ON_HANDLE_EVENT VERIFY_EMAIL_SENT",
293297
"ST_LOGS EMAIL_VERIFICATION OVERRIDE SEND_VERIFICATION_EMAIL",
294298
"ST_LOGS EMAIL_VERIFICATION PRE_API_HOOKS SEND_VERIFY_EMAIL",
295299
"ST_LOGS EMAIL_VERIFICATION ON_HANDLE_EVENT VERIFY_EMAIL_SENT",
300+
"ST_LOGS EMAIL_VERIFICATION ON_HANDLE_EVENT VERIFY_EMAIL_SENT",
296301
"ST_LOGS SESSION OVERRIDE SIGN_OUT",
297302
"ST_LOGS SESSION PRE_API_HOOKS SIGN_OUT",
298303
"ST_LOGS SESSION ON_HANDLE_EVENT SIGN_OUT",
@@ -305,24 +310,27 @@ describe("SuperTokens Email Verification", function () {
305310
page.goto(`${TEST_CLIENT_BASE_URL}/auth?mode=REQUIRED`),
306311
page.waitForNavigation({ waitUntil: "networkidle0" }),
307312
]);
308-
313+
309314
await toggleSignInSignUp(page);
310315
const { fieldValues, postValues } = getDefaultSignUpFieldValues();
311316
await signUp(page, fieldValues, postValues, "emailpassword");
312-
317+
313318
const latestURLWithToken_ = await getLatestURLWithToken();
314-
await Promise.all([page.waitForNavigation({ waitUntil: "networkidle0" }), page.goto(latestURLWithToken_)]);
319+
await Promise.all([
320+
page.waitForNavigation({ waitUntil: "networkidle0" }),
321+
page.goto(latestURLWithToken_),
322+
]);
315323
const title_ = await getTextByDataSupertokens(page, "headerTitle");
316324
assert.deepStrictEqual(title_, "Email verification successful!");
317-
325+
318326
await Promise.all([submitForm(page), page.waitForNavigation({ waitUntil: "networkidle0" })]);
319327
await page.waitForSelector(".sessionInfo-user-id");
320328
let pathname = await page.evaluate(() => window.location.pathname);
321329
assert.deepStrictEqual(pathname, "/dashboard");
322-
330+
323331
await page.evaluate((url) => window.fetch(url), `${TEST_APPLICATION_SERVER_BASE_URL}/unverifyEmail`);
324332
await waitForSTElement(page, "[data-supertokens~='sendVerifyEmailIcon']");
325-
333+
326334
pathname = await page.evaluate(() => window.location.pathname);
327335
assert.deepStrictEqual(pathname, "/auth/verify-email");
328336
});
@@ -367,7 +375,7 @@ describe("SuperTokens Email Verification", function () {
367375
const { fieldValues, postValues } = getDefaultSignUpFieldValues();
368376
await signUp(page, fieldValues, postValues, "emailpassword");
369377
await logoutFromEmailVerification(page);
370-
await new Promise((r) => setTimeout(r, 100));
378+
await waitForUrl(page, "/auth/");
371379
consoleLogs = [];
372380

373381
// Attempt verification without a session
@@ -476,7 +484,6 @@ describe("SuperTokens Email Verification", function () {
476484

477485
await waitForUrl(page, "/dashboard");
478486
});
479-
480487
});
481488
describe("Email Verified", function () {
482489
it("Should redirect to onSuccessfulRedirect when email is already verified", async function () {
@@ -1021,10 +1028,7 @@ describe("SuperTokens Email Verification", function () {
10211028
await signUp(page, fieldValues, postValues, "emailpassword");
10221029

10231030
const latestURLWithToken_ = await getLatestURLWithToken();
1024-
await Promise.all([
1025-
page.waitForNavigation({ waitUntil: "networkidle0" }),
1026-
page.goto(latestURLWithToken_),
1027-
]);
1031+
await Promise.all([page.waitForNavigation({ waitUntil: "networkidle0" }), page.goto(latestURLWithToken_)]);
10281032
const title_ = await getTextByDataSupertokens(page, "headerTitle");
10291033
assert.deepStrictEqual(title_, "Email verification successful!");
10301034

test/end-to-end/multitenancy.dynamic_login_methods.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe("SuperTokens Multitenancy dynamic login methods", function () {
6363

6464
before(async function () {
6565
await backendHook("before");
66-
const isSupported = (await isMultitenancySupported());
66+
const isSupported = await isMultitenancySupported();
6767
if (!isSupported) {
6868
this.skip();
6969
}

test/end-to-end/multitenancy.mock.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe("SuperTokens Multitenancy w/ mocked login methods", function () {
4949

5050
before(async function () {
5151
await backendHook("before");
52-
const isSupported = (await isMultitenancySupported());
52+
const isSupported = await isMultitenancySupported();
5353
if (!isSupported) {
5454
this.skip();
5555
}

test/end-to-end/multitenancy.tenant_interactions.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe("SuperTokens Multitenancy tenant interactions", function () {
7070

7171
before(async function () {
7272
await backendHook("before");
73-
const isSupported = (await isMultitenancySupported());
73+
const isSupported = await isMultitenancySupported();
7474
if (!isSupported) {
7575
this.skip();
7676
}
@@ -165,7 +165,6 @@ describe("SuperTokens Multitenancy tenant interactions", function () {
165165
});
166166

167167
it("should not allow sign into user created on custom tenant when using public", async function () {
168-
169168
await setupTenant("public", {
170169
emailPassword: { enabled: true },
171170
passwordless: { enabled: false },

test/end-to-end/passwordless.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import {
3939
setupCoreApp,
4040
setupST,
4141
waitForText,
42-
clickOnPasswordlessResendButton
42+
clickOnPasswordlessResendButton,
4343
} from "../helpers";
4444

4545
import { TEST_CLIENT_BASE_URL, SOMETHING_WENT_WRONG_ERROR } from "../constants";

test/helpers.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,6 @@ export async function signUp(page, fields, postValues = undefined, rid = "emailp
678678
await new Promise((r) => setTimeout(r, 500)); // Make sure to wait for navigation. TODO Make more robust.
679679
}
680680

681-
682681
export async function generateState(state, page) {
683682
await page.evaluate(
684683
({ state, SESSION_STORAGE_STATE_KEY }) => {

0 commit comments

Comments
 (0)