1818 */
1919
2020import assert from "assert" ;
21- import puppeteer from "puppeteer" ;
2221import {
2322 clearBrowserCookiesWithoutAffectingConsole ,
2423 clickOnProviderButton ,
@@ -29,18 +28,19 @@ import {
2928 submitForm ,
3029 waitForSTElement ,
3130 getPasswordlessDevice ,
32- setPasswordlessFlowType ,
3331 getFeatureFlags ,
34- isReact16 ,
3532 assertProviders ,
3633 setEnabledRecipes ,
3734 clickOnProviderButtonWithoutWaiting ,
3835 getGeneralError ,
39- backendBeforeEach ,
4036 waitForUrl ,
4137 setupBrowser ,
38+ backendHook ,
39+ setupCoreApp ,
40+ setupST ,
41+ screenshotOnFailure
4242} from "../helpers" ;
43- import { TEST_CLIENT_BASE_URL , TEST_SERVER_BASE_URL , SIGN_IN_UP_API , GET_AUTH_URL_API } from "../constants" ;
43+ import { TEST_CLIENT_BASE_URL , SIGN_IN_UP_API , GET_AUTH_URL_API } from "../constants" ;
4444
4545/*
4646 * Tests.
@@ -57,7 +57,10 @@ describe("SuperTokens Third Party Passwordless", function () {
5757 "ST_LOGS PASSWORDLESS OVERRIDE GET_LOGIN_ATTEMPT_INFO" ,
5858 ] ;
5959
60+ const appConfig = { } ;
61+
6062 before ( async function ( ) {
63+ backendHook ( "before" ) ;
6164 const features = await getFeatureFlags ( ) ;
6265 if ( ! features . includes ( "passwordless" ) ) {
6366 this . skip ( ) ;
@@ -66,11 +69,9 @@ describe("SuperTokens Third Party Passwordless", function () {
6669
6770 describe ( "Recipe combination tests" , ( ) => {
6871 before ( async function ( ) {
69- await backendBeforeEach ( ) ;
70-
71- await fetch ( `${ TEST_SERVER_BASE_URL } /startst` , {
72- method : "POST" ,
73- } ) . catch ( console . error ) ;
72+ const coreUrl = await setupCoreApp ( ) ;
73+ appConfig . coreUrl = coreUrl ;
74+ await setupST ( appConfig ) ;
7475
7576 browser = await setupBrowser ( ) ;
7677 page = await browser . newPage ( ) ;
@@ -82,21 +83,15 @@ describe("SuperTokens Third Party Passwordless", function () {
8283 } ) ;
8384 } ) ;
8485
85- after ( async function ( ) {
86- await browser . close ( ) ;
87- await fetch ( `${ TEST_SERVER_BASE_URL } /after` , {
88- method : "POST" ,
89- } ) . catch ( console . error ) ;
90-
91- await fetch ( `${ TEST_SERVER_BASE_URL } /stopst` , {
92- method : "POST" ,
93- } ) . catch ( console . error ) ;
94- } ) ;
95-
9686 beforeEach ( async function ( ) {
87+ await backendHook ( "beforeEach" ) ;
9788 consoleLogs = [ ] ;
9889 consoleLogs = await clearBrowserCookiesWithoutAffectingConsole ( page , consoleLogs ) ;
99- await setPasswordlessFlowType ( "EMAIL_OR_PHONE" , "USER_INPUT_CODE_AND_MAGIC_LINK" ) ;
90+ await setupST ( {
91+ ...appConfig ,
92+ passwordlessContactMethod : "EMAIL_OR_PHONE" ,
93+ passwordlessFlowType : "USER_INPUT_CODE_AND_MAGIC_LINK" ,
94+ } ) ;
10095 await Promise . all ( [
10196 page . goto (
10297 `${ TEST_CLIENT_BASE_URL } /auth?authRecipe=thirdpartypasswordless&passwordlessContactMethodType=EMAIL_OR_PHONE`
@@ -107,11 +102,23 @@ describe("SuperTokens Third Party Passwordless", function () {
107102
108103 afterEach ( async function ( ) {
109104 await page . evaluate ( ( ) => localStorage . removeItem ( "supertokens-passwordless-loginAttemptInfo" ) ) ;
105+ await screenshotOnFailure ( this , browser ) ;
106+ await backendHook ( "afterEach" ) ;
107+ } ) ;
108+
109+ after ( async function ( ) {
110+ await page ?. close ( ) ;
111+ await browser ?. close ( ) ;
112+ await backendHook ( "after" ) ;
110113 } ) ;
111114
112115 it ( "No account consolidation" , async function ( ) {
113116 // 1. Sign up with credentials
114- await setPasswordlessFlowType ( "EMAIL_OR_PHONE" , "USER_INPUT_CODE" ) ;
117+ await setupST ( {
118+ ...appConfig ,
119+ passwordlessContactMethod : "EMAIL_OR_PHONE" ,
120+ passwordlessFlowType : "USER_INPUT_CODE" ,
121+ } ) ;
115122 await page . evaluate ( ( ) => localStorage . removeItem ( "supertokens-passwordless-loginAttemptInfo" ) ) ;
116123 await Promise . all ( [
117124 page . goto ( `${ TEST_CLIENT_BASE_URL } /auth` ) ,
@@ -153,7 +160,11 @@ describe("SuperTokens Third Party Passwordless", function () {
153160 } ) ;
154161
155162 it ( "Successful signin with passwordless w/ required email verification" , async function ( ) {
156- await setPasswordlessFlowType ( "EMAIL_OR_PHONE" , "USER_INPUT_CODE" ) ;
163+ await setupST ( {
164+ ...appConfig ,
165+ passwordlessContactMethod : "EMAIL_OR_PHONE" ,
166+ passwordlessFlowType : "USER_INPUT_CODE" ,
167+ } ) ;
157168 await page . evaluate ( ( ) => localStorage . removeItem ( "supertokens-passwordless-loginAttemptInfo" ) ) ;
158169
159170 await Promise . all ( [
@@ -207,6 +218,11 @@ describe("SuperTokens Third Party Passwordless", function () {
207218 this . skip ( ) ;
208219 }
209220 await assertProviders ( page ) ;
221+ await setupST ( {
222+ ...appConfig ,
223+ enabledRecipes : [ "thirdparty" ] ,
224+ enabledProviders : [ ] ,
225+ } ) ;
210226 await setEnabledRecipes ( [ "thirdparty" ] , [ ] ) ;
211227
212228 await Promise . all ( [
0 commit comments