Skip to content

Commit

Permalink
test: make tests wait for redirection (#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
porcellus authored May 24, 2024
1 parent 3bdf7f3 commit 415a1ac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
14 changes: 6 additions & 8 deletions test/end-to-end/passwordless.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
getInputField,
isAccountLinkingSupported,
backendBeforeEach,
waitForUrl,
} from "../helpers";

import { TEST_CLIENT_BASE_URL, TEST_SERVER_BASE_URL, SOMETHING_WENT_WRONG_ERROR } from "../constants";
Expand Down Expand Up @@ -490,8 +491,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",
Expand Down Expand Up @@ -1032,8 +1032,8 @@ 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",
Expand Down Expand Up @@ -1074,8 +1074,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",
Expand Down Expand Up @@ -1534,8 +1533,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",
Expand Down
10 changes: 10 additions & 0 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ export async function waitForSTElement(page, selector, inverted = false) {
return res;
}

export function waitForUrl(page, pathname) {
return page.waitForFunction(
(pathname) => {
return window.location.pathname === pathname;
},
{ polling: 50 },
pathname
);
}

export async function waitForText(page, selector, text, timeout = 10000, pollDelay = 50) {
const start = new Date().getTime();

Expand Down

0 comments on commit 415a1ac

Please sign in to comment.