1818 */
1919
2020import assert from "assert" ;
21- import puppeteer from "puppeteer" ;
22- import fetch from "isomorphic-fetch" ;
2321import {
2422 EMAIL_EXISTS_API ,
2523 RESET_PASSWORD_API ,
2624 RESET_PASSWORD_TOKEN_API ,
2725 TEST_CLIENT_BASE_URL ,
28- TEST_SERVER_BASE_URL ,
2926} from "../constants" ;
3027import {
3128 clearBrowserCookiesWithoutAffectingConsole ,
@@ -48,14 +45,14 @@ import {
4845 toggleSignInSignUp ,
4946 defaultSignUp ,
5047 screenshotOnFailure ,
51- getAuthPageHeaderText ,
5248 getTitleBackButton ,
53- waitForSTElement ,
5449 getResetPasswordSuccessBackToSignInButton ,
55- backendBeforeEach ,
5650 waitForText ,
5751 waitForUrl ,
5852 setupBrowser ,
53+ backendHook ,
54+ setupCoreApp ,
55+ setupST ,
5956} from "../helpers" ;
6057
6158/*
@@ -67,52 +64,48 @@ describe("SuperTokens Reset password", function () {
6764 let consoleLogs ;
6865
6966 before ( async function ( ) {
70- await backendBeforeEach ( ) ;
71-
72- await fetch ( `${ TEST_SERVER_BASE_URL } /startst` , {
73- method : "POST" ,
74- } ) . catch ( console . error ) ;
75-
67+ await backendHook ( "before" ) ;
7668 browser = await setupBrowser ( ) ;
77-
78- page = await browser . newPage ( ) ;
69+ const coreUrl = await setupCoreApp ( ) ;
70+ await setupST ( { coreUrl } ) ;
7971
8072 // Sign Up first.
73+ page = await browser . newPage ( ) ;
8174 await Promise . all ( [
8275 page . goto ( `${ TEST_CLIENT_BASE_URL } /auth` ) ,
8376 page . waitForNavigation ( { waitUntil : "networkidle0" } ) ,
8477 ] ) ;
8578 await toggleSignInSignUp ( page ) ;
8679 await defaultSignUp ( page ) ;
80+ page . close ( ) ;
8781 } ) ;
8882
89- after ( async function ( ) {
90- await browser . close ( ) ;
91-
92- await fetch ( `${ TEST_SERVER_BASE_URL } /after` , {
93- method : "POST" ,
94- } ) . catch ( console . error ) ;
83+ beforeEach ( async function ( ) {
84+ await backendHook ( "beforeEach" ) ;
85+ page = await browser . newPage ( ) ;
86+ page . on ( "console" , ( consoleObj ) => {
87+ const log = consoleObj . text ( ) ;
88+ // console.log(log);
89+ if ( log . startsWith ( "ST_LOGS" ) ) {
90+ consoleLogs . push ( log ) ;
91+ }
92+ } ) ;
93+ consoleLogs = await clearBrowserCookiesWithoutAffectingConsole ( page , [ ] ) ;
94+ } ) ;
9595
96- await fetch ( `${ TEST_SERVER_BASE_URL } /stopst` , {
97- method : "POST" ,
98- } ) . catch ( console . error ) ;
96+ afterEach ( async function ( ) {
97+ await screenshotOnFailure ( this , browser ) ;
98+ await page ?. close ( ) ;
99+ await backendHook ( "afterEach" ) ;
99100 } ) ;
100101
101- afterEach ( function ( ) {
102- return screenshotOnFailure ( this , browser ) ;
102+ after ( async function ( ) {
103+ await browser ?. close ( ) ;
104+ await backendHook ( "after" ) ;
103105 } ) ;
104106
105107 describe ( "Reset password enter email form test" , function ( ) {
106108 beforeEach ( async function ( ) {
107- page = await browser . newPage ( ) ;
108- consoleLogs = [ ] ;
109- consoleLogs = await clearBrowserCookiesWithoutAffectingConsole ( page , consoleLogs ) ;
110- page . on ( "console" , ( consoleObj ) => {
111- const log = consoleObj . text ( ) ;
112- if ( log . startsWith ( "ST_LOGS" ) ) {
113- consoleLogs . push ( log ) ;
114- }
115- } ) ;
116109 await Promise . all ( [
117110 page . goto ( `${ TEST_CLIENT_BASE_URL } /auth/reset-password` ) ,
118111 page . waitForNavigation ( { waitUntil : "networkidle0" } ) ,
@@ -236,16 +229,6 @@ describe("SuperTokens Reset password", function () {
236229
237230 describe ( "Reset password new password form test" , function ( ) {
238231 beforeEach ( async function ( ) {
239- page = await browser . newPage ( ) ;
240- // Catch console.log sent from PRE API HOOKS.
241- consoleLogs = [ ] ;
242- page . on ( "console" , ( consoleObj ) => {
243- const log = consoleObj . text ( ) ;
244- if ( log . startsWith ( "ST_LOGS" ) ) {
245- consoleLogs . push ( log ) ;
246- }
247- } ) ;
248- consoleLogs = await clearBrowserCookiesWithoutAffectingConsole ( page , consoleLogs ) ;
249232 await page . goto ( `${ TEST_CLIENT_BASE_URL } /auth/reset-password?token=TOKEN` ) ;
250233 } ) ;
251234
0 commit comments