Skip to content

Commit 968757d

Browse files
committed
refactor: split app creation and ST setup utils
1 parent c4268dc commit 968757d

File tree

9 files changed

+140
-77
lines changed

9 files changed

+140
-77
lines changed

test/end-to-end/accountlinking.test.js

Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ import {
3939
getTextByDataSupertokens,
4040
sendEmailResetPasswordSuccessMessage,
4141
setupBrowser,
42-
createCoreApp,
42+
setupCoreApp,
43+
setupST,
4344
backendHook,
4445
screenshotOnFailure,
4546
} from "../helpers";
@@ -53,6 +54,7 @@ describe("SuperTokens Account linking", function () {
5354
let browser;
5455
let page;
5556
let consoleLogs;
57+
let coreUrl;
5658

5759
const passwordlessFlowType = "USER_INPUT_CODE_AND_MAGIC_LINK";
5860
const passwordlessContactMethod = "EMAIL_OR_PHONE";
@@ -62,6 +64,9 @@ describe("SuperTokens Account linking", function () {
6264
if (!features.includes("accountlinking")) {
6365
this.skip();
6466
}
67+
68+
coreUrl = await setupCoreApp();
69+
await setupST({ coreUrl });
6570
});
6671

6772
describe("Recipe combination tests", () => {
@@ -118,7 +123,8 @@ describe("SuperTokens Account linking", function () {
118123
const doLogin2 = login2[1];
119124

120125
it(`should work for ${login1[0]} - ${login2[0]} w/ email verification not required`, async () => {
121-
await createCoreApp({
126+
await setupST({
127+
coreUrl,
122128
passwordlessFlowType,
123129
passwordlessContactMethod,
124130
accountLinkingConfig: {
@@ -158,7 +164,8 @@ describe("SuperTokens Account linking", function () {
158164

159165
if (login2[0] !== "emailpassword") {
160166
it(`should work for ${login1[0]} - ${login2[0]} w/ email verification required`, async () => {
161-
await createCoreApp({
167+
await setupST({
168+
coreUrl,
162169
passwordlessFlowType,
163170
passwordlessContactMethod,
164171
accountLinkingConfig: {
@@ -212,7 +219,8 @@ describe("SuperTokens Account linking", function () {
212219
});
213220
} else {
214221
it(`should work for ${login1[0]} - password reset (invite link flow) w/ email verification required`, async () => {
215-
await createCoreApp({
222+
await setupST({
223+
coreUrl,
216224
passwordlessFlowType,
217225
passwordlessContactMethod,
218226
accountLinkingConfig: {
@@ -272,7 +280,8 @@ describe("SuperTokens Account linking", function () {
272280

273281
describe("conflicting accounts", () => {
274282
it("should not allow sign up w/ emailpassword in case of conflict", async function () {
275-
await createCoreApp({
283+
await setupST({
284+
coreUrl,
276285
passwordlessFlowType,
277286
passwordlessContactMethod,
278287
accountLinkingConfig: {
@@ -314,8 +323,9 @@ describe("SuperTokens Account linking", function () {
314323
it("should not allow sign in w/ an unverified emailpassword user in case of conflict", async function () {
315324
// Use a common appId over the test to allow re-inits
316325
const appId = randomUUID();
317-
await createCoreApp({
318-
appId,
326+
const coreUrl = await setupCoreApp({ appId });
327+
await setupST({
328+
coreUrl,
319329
passwordlessFlowType,
320330
passwordlessContactMethod,
321331
accountLinkingConfig: {
@@ -338,8 +348,8 @@ describe("SuperTokens Account linking", function () {
338348
await Promise.all([page.waitForSelector(".sessionInfo-user-id"), page.waitForNetworkIdle()]);
339349
await logOut(page);
340350

341-
await createCoreApp({
342-
appId,
351+
await setupST({
352+
coreUrl,
343353
passwordlessFlowType,
344354
passwordlessContactMethod,
345355
accountLinkingConfig: {
@@ -360,8 +370,8 @@ describe("SuperTokens Account linking", function () {
360370

361371
await waitForSTElement(page, `input[name=email]`);
362372

363-
await createCoreApp({
364-
appId,
373+
await setupST({
374+
coreUrl,
365375
passwordlessFlowType,
366376
passwordlessContactMethod,
367377
accountLinkingConfig: {
@@ -392,7 +402,8 @@ describe("SuperTokens Account linking", function () {
392402
});
393403

394404
it("should not allow sign up w/ an unverified thirdparty user in case of conflict", async function () {
395-
await createCoreApp({
405+
await setupST({
406+
coreUrl,
396407
passwordlessFlowType,
397408
passwordlessContactMethod,
398409
accountLinkingConfig: {
@@ -426,7 +437,8 @@ describe("SuperTokens Account linking", function () {
426437
});
427438

428439
it("should not allow using thirdparty sign in with changed email in case of conflict", async function () {
429-
await createCoreApp({
440+
await setupST({
441+
coreUrl,
430442
passwordlessFlowType,
431443
passwordlessContactMethod,
432444
accountLinkingConfig: {
@@ -480,8 +492,9 @@ describe("SuperTokens Account linking", function () {
480492
it("should not allow sign in w/ an unverified thirdparty user in case of conflict", async function () {
481493
// Use a common appId over the test to allow re-inits
482494
const appId = randomUUID();
483-
await createCoreApp({
484-
appId,
495+
const coreUrl = await setupCoreApp({ appId });
496+
await setupST({
497+
coreUrl,
485498
passwordlessFlowType,
486499
passwordlessContactMethod,
487500
accountLinkingConfig: {
@@ -500,8 +513,8 @@ describe("SuperTokens Account linking", function () {
500513
await tryThirdPartySignInUp(page, email, false);
501514
await logOut(page);
502515

503-
await createCoreApp({
504-
appId,
516+
await setupST({
517+
coreUrl,
505518
passwordlessFlowType,
506519
passwordlessContactMethod,
507520
accountLinkingConfig: {
@@ -522,8 +535,8 @@ describe("SuperTokens Account linking", function () {
522535

523536
await waitForSTElement(page, `input[name=email]`);
524537

525-
await createCoreApp({
526-
appId,
538+
await setupST({
539+
coreUrl,
527540
passwordlessFlowType,
528541
passwordlessContactMethod,
529542
accountLinkingConfig: {
@@ -549,8 +562,9 @@ describe("SuperTokens Account linking", function () {
549562

550563
// Use a common appId over the test to allow re-inits
551564
const appId = randomUUID();
552-
await createCoreApp({
553-
appId,
565+
const coreUrl = await setupCoreApp({ appId });
566+
await setupST({
567+
coreUrl,
554568
passwordlessFlowType,
555569
passwordlessContactMethod,
556570
accountLinkingConfig: {
@@ -565,8 +579,8 @@ describe("SuperTokens Account linking", function () {
565579
await tryEmailPasswordSignUp(page, email);
566580
await logOut(page);
567581

568-
await createCoreApp({
569-
appId,
582+
await setupST({
583+
coreUrl,
570584
passwordlessFlowType,
571585
passwordlessContactMethod,
572586
accountLinkingConfig: {
@@ -598,8 +612,9 @@ describe("SuperTokens Account linking", function () {
598612
const email = `test-user+${Date.now()}@supertokens.com`;
599613
// Use a common appId over the test to allow re-inits
600614
const appId = randomUUID();
601-
await createCoreApp({
602-
appId,
615+
const coreUrl = await setupCoreApp({ appId });
616+
await setupST({
617+
coreUrl,
603618
passwordlessFlowType,
604619
passwordlessContactMethod,
605620
accountLinkingConfig: {
@@ -614,8 +629,8 @@ describe("SuperTokens Account linking", function () {
614629
await tryEmailPasswordSignUp(page, email);
615630
await logOut(page);
616631

617-
await createCoreApp({
618-
appId,
632+
await setupST({
633+
coreUrl,
619634
passwordlessFlowType,
620635
passwordlessContactMethod,
621636
accountLinkingConfig: {
@@ -649,8 +664,9 @@ describe("SuperTokens Account linking", function () {
649664

650665
// Use a common appId over the test to allow re-inits
651666
const appId = randomUUID();
652-
await createCoreApp({
653-
appId,
667+
const coreUrl = await setupCoreApp({ appId });
668+
await setupST({
669+
coreUrl,
654670
passwordlessFlowType,
655671
passwordlessContactMethod,
656672
accountLinkingConfig: {
@@ -673,8 +689,8 @@ describe("SuperTokens Account linking", function () {
673689
await tryThirdPartySignInUp(page, email, false, email2);
674690
await logOut(page);
675691

676-
await createCoreApp({
677-
appId,
692+
await setupST({
693+
coreUrl,
678694
passwordlessFlowType,
679695
passwordlessContactMethod,
680696
accountLinkingConfig: {
@@ -689,8 +705,8 @@ describe("SuperTokens Account linking", function () {
689705
await tryEmailPasswordSignUp(page, email);
690706
await logOut(page);
691707

692-
await createCoreApp({
693-
appId,
708+
await setupST({
709+
coreUrl,
694710
passwordlessFlowType,
695711
passwordlessContactMethod,
696712
accountLinkingConfig: {
@@ -724,8 +740,9 @@ describe("SuperTokens Account linking", function () {
724740

725741
// Use a common appId over the test to allow re-inits
726742
const appId = randomUUID();
727-
await createCoreApp({
728-
appId,
743+
const coreUrl = await setupCoreApp({ appId });
744+
await setupST({
745+
coreUrl,
729746
passwordlessFlowType,
730747
passwordlessContactMethod,
731748
accountLinkingConfig: {
@@ -750,8 +767,8 @@ describe("SuperTokens Account linking", function () {
750767

751768
await logOut(page);
752769

753-
await createCoreApp({
754-
appId,
770+
await setupST({
771+
coreUrl,
755772
passwordlessFlowType,
756773
passwordlessContactMethod,
757774
accountLinkingConfig: {
@@ -772,8 +789,8 @@ describe("SuperTokens Account linking", function () {
772789

773790
await waitForSTElement(page, `input[name=email]`);
774791

775-
await createCoreApp({
776-
appId,
792+
await setupST({
793+
coreUrl,
777794
passwordlessFlowType,
778795
passwordlessContactMethod,
779796
accountLinkingConfig: {

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919

2020
import assert from "assert";
21-
import puppeteer from "puppeteer";
2221
import fetch from "isomorphic-fetch";
2322
import {
2423
SEND_VERIFY_EMAIL_API,
@@ -55,8 +54,9 @@ import {
5554
waitForUrl,
5655
setupBrowser,
5756
backendHook,
58-
createCoreApp,
57+
setupCoreApp,
5958
getLogoutButton,
59+
setupST,
6060
} from "../helpers";
6161

6262
describe("Email Verification", () => {
@@ -72,7 +72,10 @@ describe("Email Verification", () => {
7272

7373
beforeEach(async function () {
7474
await backendHook("beforeEach");
75-
await createCoreApp();
75+
76+
const coreUrl = await setupCoreApp();
77+
await setupST({ coreUrl });
78+
7679
page = await browser.newPage();
7780

7881
consoleLogs = [];
@@ -615,6 +618,8 @@ describe("Email Verification", () => {
615618
const title = await getTextByDataSupertokens(page, "headerTitle");
616619
assert.deepStrictEqual(title, "Email verification successful!");
617620
await submitForm(page);
621+
// Make sure to wait for status to update. Flakes in headless.
622+
await new Promise((r) => setTimeout(r, 500));
618623
const logoutButton = await getLogoutButton(page);
619624
await Promise.all([logoutButton.click(), page.waitForNavigation({ waitUntil: "networkidle0" })]);
620625

@@ -826,11 +831,12 @@ describe("Email Verification", () => {
826831

827832
describe("Claim refresh with clock skew", function () {
828833
it("should not go into an infinite loop during claim refresh with adjusted clock skew", async function () {
829-
await createCoreApp({
834+
const coreUrl = await setupCoreApp({
830835
coreConfig: {
831836
access_token_validity: 2 * 60 * 60, // 2 hours
832837
},
833838
});
839+
await setupST({ coreUrl });
834840
await toggleSignInSignUp(page);
835841

836842
// Override Date.now() to simulate a clock skew of 1 hour

test/end-to-end/embed.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
screenshotOnFailure,
88
setupBrowser,
99
backendHook,
10-
createCoreApp,
10+
setupCoreApp,
11+
setupST,
1112
logoutFromEmailVerification,
1213
} from "../helpers";
1314

@@ -23,7 +24,8 @@ describe("Embed components", async () => {
2324

2425
beforeEach(async function () {
2526
await backendHook("beforeEach");
26-
await createCoreApp();
27+
const coreUrl = await setupCoreApp();
28+
await setupST({ coreUrl });
2729
page = await browser.newPage();
2830

2931
consoleLogs = [];

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ import {
4141
isGeneralErrorSupported,
4242
setGeneralErrorToLocalStorage,
4343
backendHook,
44-
createCoreApp,
44+
setupCoreApp,
4545
waitForUrl,
4646
setupBrowser,
47+
setupST,
4748
} from "../helpers";
4849

4950
import {
@@ -75,7 +76,8 @@ describe("General error rendering", function () {
7576

7677
beforeEach(async function () {
7778
await backendHook("beforeEach");
78-
await createCoreApp();
79+
const coreUrl = await setupCoreApp();
80+
await setupST({ coreUrl });
7981
page = await browser.newPage();
8082

8183
consoleLogs = [];

0 commit comments

Comments
 (0)