Skip to content

Commit 8434721

Browse files
fix: failing auth-react tests [0.41] (#893)
* fix: awaits `setupST` calls * fix: factorChooser issues and tenant interactions race condition * update: remove `enabledRecipes` config * Skip thirdpartyemailpassword if not enabled in backend * fix: `after` hook page close failures * update: moves variable to correct block --------- Co-authored-by: Deepjyoti Barman <deepjyoti@supertokens.com>
1 parent 69437a1 commit 8434721

10 files changed

+61
-24
lines changed

test/end-to-end/generalerror.test.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ let consoleLogs;
6363

6464
describe("General error rendering", function () {
6565
let coreUrl;
66-
let enabledRecipes = undefined;
6766
before(async function () {
6867
const _isGeneralErrorSupported = await isGeneralErrorSupported();
6968
if (!_isGeneralErrorSupported) {
@@ -77,7 +76,7 @@ describe("General error rendering", function () {
7776
beforeEach(async function () {
7877
await backendHook("beforeEach");
7978
coreUrl = await setupCoreApp();
80-
await setupST({ coreUrl, enabledRecipes });
79+
await setupST({ coreUrl });
8180
page = await browser.newPage();
8281

8382
consoleLogs = [];
@@ -210,18 +209,11 @@ describe("General error rendering", function () {
210209
});
211210

212211
describe("ThirdPartyEmailPassword", function () {
213-
before(async function () {
214-
enabledRecipes = ["thirdpartyemailpassword", "session"];
215-
});
216-
217212
getEmailPasswordTests("thirdpartyemailpassword", "THIRD_PARTY_EMAIL_PASSWORD");
218213
getThirdPartyTests("thirdpartyemailpassword", "THIRD_PARTY_EMAIL_PASSWORD");
219214
});
220215

221216
describe("ThirdPartyPasswordless", function () {
222-
before(async function () {
223-
enabledRecipes = ["thirdpartypasswordless", "session"];
224-
});
225217
getThirdPartyTests("thirdpartypasswordless", "THIRD_PARTY_PASSWORDLESS");
226218
});
227219

test/end-to-end/getRedirectionURL.test.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { TEST_CLIENT_BASE_URL, SIGN_IN_UP_API } from "../constants";
2323

2424
describe("getRedirectionURL Tests", function () {
2525
let browser;
26-
let page;
2726

2827
before(async function () {
2928
await backendHook("before");
@@ -46,6 +45,8 @@ describe("getRedirectionURL Tests", function () {
4645

4746
describe("Test that isNewRecipeUser is passed correctly", function () {
4847
describe("Email Password Recipe", function () {
48+
let page;
49+
4950
beforeEach(async function () {
5051
page = await browser.newPage();
5152
const coreUrl = await setupCoreApp();
@@ -72,6 +73,8 @@ describe("getRedirectionURL Tests", function () {
7273
});
7374

7475
describe("Third party recipe", function () {
76+
let page;
77+
7578
before(async function () {
7679
const coreUrl = await setupCoreApp();
7780
await setupST({ coreUrl });
@@ -105,6 +108,8 @@ describe("getRedirectionURL Tests", function () {
105108
});
106109

107110
describe("Thirdpartyemailpassword recipe", function () {
111+
let page;
112+
108113
before(async function () {
109114
const coreUrl = await setupCoreApp();
110115
await setupST({ coreUrl });
@@ -145,6 +150,7 @@ describe("getRedirectionURL Tests", function () {
145150

146151
describe("Passwordless recipe", function () {
147152
const exampleEmail = "test@example.com";
153+
let page;
148154

149155
before(async function () {
150156
let _isPasswordlessSupported = await isPasswordlessSupported();
@@ -207,6 +213,7 @@ describe("getRedirectionURL Tests", function () {
207213

208214
describe("ThirdPartyPasswordless recipe", function () {
209215
const exampleEmail = "test@example.com";
216+
let page;
210217

211218
before(async function () {
212219
let _isThirdPartyPasswordlessSupported = await isThirdPartyPasswordlessSupported();
@@ -283,6 +290,8 @@ describe("getRedirectionURL Tests", function () {
283290

284291
describe("No Redirection", function () {
285292
describe("Email Password Recipe", function () {
293+
let page;
294+
286295
before(async function () {
287296
const coreUrl = await setupCoreApp();
288297
await setupST({ coreUrl });
@@ -320,6 +329,7 @@ describe("getRedirectionURL Tests", function () {
320329

321330
describe("Passwordless recipe", function () {
322331
const exampleEmail = "test@example.com";
332+
let page;
323333

324334
before(async function () {
325335
let _isPasswordlessSupported = await isPasswordlessSupported();
@@ -387,6 +397,7 @@ describe("getRedirectionURL Tests", function () {
387397

388398
describe("ThirdPartyPasswordless recipe: Magic Link", function () {
389399
const exampleEmail = "test@example.com";
400+
let page;
390401

391402
before(async function () {
392403
let _isThirdPartyPasswordlessSupported = await isThirdPartyPasswordlessSupported();
@@ -453,6 +464,7 @@ describe("getRedirectionURL Tests", function () {
453464
});
454465

455466
describe("ThirdParty Recipe", function () {
467+
let page;
456468
before(async function () {
457469
const coreUrl = await setupCoreApp();
458470
await setupST({ coreUrl });

test/end-to-end/mfa.chooserscreen.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ describe("SuperTokens SignIn w/ MFA", function () {
256256
await chooseFactor(page, "otp-phone");
257257
await completeOTP(page);
258258

259-
await goToFactorChooser(page);
259+
await goToFactorChooser(page, true, false);
260260

261261
await waitForSTElement(page, "[data-supertokens~=backButton]");
262262
});

test/end-to-end/mfa.helpers.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,16 @@ export async function tryPasswordlessSignInUp(page, contactInfo, queryParams) {
191191
await submitForm(page);
192192
await new Promise((res) => setTimeout(res, 1000));
193193
}
194-
export async function goToFactorChooser(page, waitForList = true) {
194+
export async function goToFactorChooser(page, waitForList = true, waitForNetworkIdle = true) {
195195
const ele = await page.waitForSelector(".goToFactorChooser");
196-
await waitFor(100);
197-
await Promise.all([page.waitForNavigation({ waitUntil: "networkidle0" }), ele.click()]);
196+
await waitFor(waitForNetworkIdle ? 100 : 1000);
197+
const steps = [ele.click()];
198+
if (waitForNetworkIdle) {
199+
// Insert at the start of the array
200+
steps.unshift(page.waitForNavigation({ waitUntil: "networkidle0" }));
201+
}
202+
203+
await Promise.all(steps);
198204
if (waitForList) {
199205
await waitForSTElement(page, "[data-supertokens~=factorChooserList]");
200206
}

test/end-to-end/mfa.requirement_handling.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ describe("SuperTokens SignIn w/ MFA", function () {
124124

125125
await tryEmailPasswordSignUp(page, email);
126126
await waitForDashboard(page);
127-
await goToFactorChooser(page);
127+
await goToFactorChooser(page, true, false);
128128
await chooseFactor(page, "otp-email");
129129
await completeOTP(page);
130130
await setupOTP(page, "PHONE", phoneNumber);

test/end-to-end/mfa.signin.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ describe("SuperTokens SignIn w/ MFA", function () {
113113
it("sign in with email-otp (auto-setup)", async function () {
114114
const email = await getTestEmail();
115115

116-
setupST({
116+
await setupST({
117117
...appConfig,
118118
mfaInfo: {
119119
requirements: ["otp-email"],
@@ -139,7 +139,7 @@ describe("SuperTokens SignIn w/ MFA", function () {
139139
const email = await getTestEmail();
140140
const phoneNumber = getTestPhoneNumber();
141141

142-
setupST({
142+
await setupST({
143143
...appConfig,
144144
mfaInfo: {
145145
requirements: [{ oneOf: ["otp-email", "otp-phone"] }],
@@ -163,7 +163,7 @@ describe("SuperTokens SignIn w/ MFA", function () {
163163
});
164164

165165
it("set up otp-email and sign-in", async function () {
166-
setupST({
166+
await setupST({
167167
...appConfig,
168168
mfaInfo: {
169169
requirements: [],
@@ -179,7 +179,7 @@ describe("SuperTokens SignIn w/ MFA", function () {
179179

180180
await logout(page);
181181

182-
setupST({
182+
await setupST({
183183
...appConfig,
184184
mfaInfo: {
185185
requirements: [{ oneOf: ["otp-email"] }],
@@ -203,15 +203,15 @@ describe("SuperTokens SignIn w/ MFA", function () {
203203
});
204204

205205
it("set up totp and sign-in", async function () {
206-
setupST({
206+
await setupST({
207207
...appConfig,
208208
mfaInfo: {
209209
requirements: [],
210210
},
211211
});
212212
const email = await getTestEmail();
213213

214-
setupST({
214+
await setupST({
215215
...appConfig,
216216
mfaInfo: {
217217
requirements: [{ oneOf: ["otp-email", "totp"] }],
@@ -245,7 +245,7 @@ describe("SuperTokens SignIn w/ MFA", function () {
245245

246246
it("should show access denied if the only next option is an unknown factor id", async () => {
247247
const email = await getTestEmail();
248-
setupST({
248+
await setupST({
249249
...appConfig,
250250
mfaInfo: {
251251
requirements: ["unknown"],

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,11 @@ describe("SuperTokens Multitenancy tenant interactions", function () {
647647

648648
await removeTenant("customer1");
649649

650+
// We need to wait for a while so that the login_methods
651+
// endpoint doesn't crash. Essentially, it seems like the core
652+
// take a few seconds to update.
653+
await page.waitForTimeout(3000);
654+
650655
let getDynamicLoginMethodsCalled = false;
651656
await page.setRequestInterception(true);
652657
const requestHandler = (request) => {

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe
112112
await backendHook("before");
113113
({ browser, page } = await initBrowser(contactMethod, consoleLogs, authRecipe));
114114
const coreUrl = await setupCoreApp();
115-
await setupST({ coreUrl, passwordlessFlowType: "USER_INPUT_CODE", passwordlessContactMethod: contactMethod });
115+
await setupST({
116+
coreUrl,
117+
passwordlessFlowType: "USER_INPUT_CODE",
118+
passwordlessContactMethod: contactMethod,
119+
});
116120
});
117121

118122
after(async function () {
@@ -463,7 +467,11 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe
463467
disablePhoneGuess: true,
464468
}));
465469
const coreUrl = await setupCoreApp();
466-
await setupST({ coreUrl, passwordlessFlowType: "USER_INPUT_CODE", passwordlessContactMethod: contactMethod });
470+
await setupST({
471+
coreUrl,
472+
passwordlessFlowType: "USER_INPUT_CODE",
473+
passwordlessContactMethod: contactMethod,
474+
});
467475
});
468476

469477
after(async function () {

test/end-to-end/thirdpartyemailpassword.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import {
4949
backendHook,
5050
setupCoreApp,
5151
setupST,
52+
isThirdPartyEmailPasswordSupported,
5253
} from "../helpers";
5354
import {
5455
TEST_CLIENT_BASE_URL,
@@ -71,6 +72,10 @@ describe("SuperTokens Third Party Email Password", function () {
7172
const appConfig = {};
7273

7374
before(async function () {
75+
if (!(await isThirdPartyEmailPasswordSupported())) {
76+
this.skip();
77+
}
78+
7479
await backendHook("before");
7580
const coreUrl = await setupCoreApp();
7681
appConfig.coreUrl = coreUrl;

test/helpers.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,15 @@ export async function isThirdPartyPasswordlessSupported() {
10031003
return false;
10041004
}
10051005

1006+
export async function isThirdPartyEmailPasswordSupported() {
1007+
const features = await getFeatureFlags();
1008+
if (features.includes("thirdpartyemailpassword")) {
1009+
return true;
1010+
}
1011+
1012+
return false;
1013+
}
1014+
10061015
export async function isUserRolesSupported() {
10071016
const features = await getFeatureFlags();
10081017
if (!features.includes("userroles")) {

0 commit comments

Comments
 (0)