From 96060d35aa3dd8d2f297ce8dbb5b6d6c0772eefe Mon Sep 17 00:00:00 2001 From: Mihaly Lengyel Date: Wed, 29 May 2024 00:32:29 +0200 Subject: [PATCH] test: more test stability fixes --- test/end-to-end/passwordless.test.js | 40 +++++++------------ .../end-to-end/thirdpartypasswordless.test.js | 4 +- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/test/end-to-end/passwordless.test.js b/test/end-to-end/passwordless.test.js index fdd73c9af..87e998482 100644 --- a/test/end-to-end/passwordless.test.js +++ b/test/end-to-end/passwordless.test.js @@ -37,6 +37,7 @@ import { getInputField, isAccountLinkingSupported, backendBeforeEach, + waitForUrl, } from "../helpers"; import { @@ -693,8 +694,7 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe await page.waitForNavigation({ waitUntil: "networkidle0" }); - const pathname = await page.evaluate(() => window.location.pathname); - assert.deepStrictEqual(pathname, "/redirect-here"); + await waitForUrl(page, "/redirect-here"); assert.deepStrictEqual(consoleLogs, [ "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", @@ -1250,8 +1250,7 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe await page.goto(device.codes[0].urlWithLinkCode); await page.waitForNavigation({ waitUntil: "networkidle0" }); - const pathname = await page.evaluate(() => window.location.pathname); - assert.deepStrictEqual(pathname, "/redirect-here"); + await waitForUrl(page, "/redirect-here"); assert.deepStrictEqual(consoleLogs, [ "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", @@ -1294,8 +1293,7 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe await page.goto(device.codes[0].urlWithLinkCode); await page.waitForNavigation({ waitUntil: "networkidle0" }); - const pathname = await page.evaluate(() => window.location.pathname); - assert.deepStrictEqual(pathname, "/redirect-here"); + await waitForUrl(page, "/redirect-here"); assert.deepStrictEqual(consoleLogs, [ "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", @@ -1416,8 +1414,7 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe // We have been redirected to linkSent await waitForSTElement(page, "[data-supertokens~=sendCodeIcon]"); - const pathname = await page.evaluate(() => window.location.pathname); - assert.deepStrictEqual(pathname, "/auth/"); + await waitForUrl(page, "/auth/"); const error = await waitForSTElement(page, "[data-supertokens~='generalError']"); assert.strictEqual(await error.evaluate((e) => e.textContent), "general error from API consume code"); @@ -1452,8 +1449,7 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe // We have been redirected to linkSent await waitForSTElement(page, "[data-supertokens~=sendCodeIcon]"); - const pathname = await page.evaluate(() => window.location.pathname); - assert.deepStrictEqual(pathname, "/auth/"); + await waitForUrl(page, "/auth/"); const error = await waitForSTElement(page, "[data-supertokens~='generalError']"); assert.strictEqual(await error.evaluate((e) => e.textContent), SOMETHING_WENT_WRONG_ERROR); @@ -1468,8 +1464,7 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe page.waitForNavigation({ waitUntil: "networkidle0" }), ]); - const pathname = await page.evaluate(() => window.location.pathname); - assert.deepStrictEqual(pathname, "/auth/"); + await waitForUrl(page, "/auth/"); assert.deepStrictEqual(consoleLogs, [ "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", @@ -1487,8 +1482,7 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe const btn = await waitForSTElement(page, "[data-supertokens='button']"); await btn.click(); await waitForSTElement(page, "[data-supertokens='generalError']"); - const pathname = await page.evaluate(() => window.location.pathname); - assert.deepStrictEqual(pathname, "/auth/"); + await waitForUrl(page, "/auth/"); assert.deepStrictEqual(consoleLogs, [ "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", @@ -1514,8 +1508,7 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe await btn.click(); await waitForSTElement(page, "[data-supertokens='generalError']"); - const pathname = await page.evaluate(() => window.location.pathname); - assert.deepStrictEqual(pathname, "/auth/"); + await waitForUrl(page, "/auth/"); assert.deepStrictEqual(consoleLogs, [ "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", @@ -1541,8 +1534,7 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe await btn.click(); await waitForSTElement(page, "[data-supertokens='generalError']"); - const pathname = await page.evaluate(() => window.location.pathname); - assert.deepStrictEqual(pathname, "/auth/"); + await waitForUrl(page, "/auth/"); assert.deepStrictEqual(consoleLogs, [ "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", @@ -1564,8 +1556,7 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe page.waitForNavigation({ waitUntil: "networkidle0" }), ]); - const pathname = await page.evaluate(() => window.location.pathname); - assert.deepStrictEqual(pathname, "/auth/"); + await waitForUrl(page, "/auth/"); assert.deepStrictEqual(consoleLogs, [ "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", @@ -1583,8 +1574,7 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe page.waitForNavigation({ waitUntil: "networkidle0" }), ]); - const pathname = await page.evaluate(() => window.location.pathname); - assert.deepStrictEqual(pathname, "/auth/"); + await waitForUrl(page, "/auth/"); assert.deepStrictEqual(consoleLogs, [ "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", @@ -1756,8 +1746,7 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe await submitForm(page); await page.waitForNavigation({ waitUntil: "networkidle0" }); - const pathname = await page.evaluate(() => window.location.pathname); - assert.deepStrictEqual(pathname, "/redirect-here"); + await waitForUrl(page, "/redirect-here"); assert.deepStrictEqual(consoleLogs, [ "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", @@ -1856,8 +1845,7 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe await btn.click(); await waitForSTElement(page, "[data-supertokens='generalError']"); - const pathname = await page.evaluate(() => window.location.pathname); - assert.deepStrictEqual(pathname, "/auth/"); + await waitForUrl(page, "/auth/"); assert.deepStrictEqual( [ diff --git a/test/end-to-end/thirdpartypasswordless.test.js b/test/end-to-end/thirdpartypasswordless.test.js index 1b3e6f600..7838302e0 100644 --- a/test/end-to-end/thirdpartypasswordless.test.js +++ b/test/end-to-end/thirdpartypasswordless.test.js @@ -37,6 +37,7 @@ import { clickOnProviderButtonWithoutWaiting, getGeneralError, backendBeforeEach, + waitForUrl, } from "../helpers"; import { TEST_CLIENT_BASE_URL, TEST_SERVER_BASE_URL, SIGN_IN_UP_API, GET_AUTH_URL_API } from "../constants"; import { getThirdPartyTestCases } from "./thirdparty.test"; @@ -177,8 +178,7 @@ describe("SuperTokens Third Party Passwordless", function () { await submitForm(page); await Promise.all([page.waitForSelector(".sessionInfo-user-id"), page.waitForNetworkIdle()]); - const pathname = await page.evaluate(() => window.location.pathname); - assert.deepStrictEqual(pathname, "/dashboard"); + await waitForUrl(page, "/dashboard"); assert.deepStrictEqual(consoleLogs, [ "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH",