Skip to content

Commit 8df0cd9

Browse files
namsnathdeepjyoti30-st
authored andcommitted
update: userContext/userroles tests use core apps
1 parent f448882 commit 8df0cd9

File tree

2 files changed

+45
-52
lines changed

2 files changed

+45
-52
lines changed

test/end-to-end/userContext.test.js

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
* License for the specific language governing permissions and limitations
1313
* under the License.
1414
*/
15-
/* https://github.com/babel/babel/issues/9849#issuecomment-487040428 */
16-
import regeneratorRuntime from "regenerator-runtime";
17-
import puppeteer from "puppeteer";
1815
import {
1916
clearBrowserCookiesWithoutAffectingConsole,
2017
getLatestURLWithToken,
@@ -24,11 +21,18 @@ import {
2421
submitFormReturnRequestAndResponse,
2522
assertProviders,
2623
clickOnProviderButton,
24+
waitForUrl,
2725
loginWithAuth0,
26+
loginWithAuth0,
27+
waitForUrl,
28+
setupBrowser,
29+
backendHook,
30+
setupCoreApp,
31+
setupST,
32+
screenshotOnFailure,
2833
} from "../helpers";
2934
import {
3035
TEST_CLIENT_BASE_URL,
31-
TEST_SERVER_BASE_URL,
3236
RESET_PASSWORD_TOKEN_API,
3337
RESET_PASSWORD_API,
3438
SIGN_IN_UP_API,
@@ -44,13 +48,9 @@ describe("SuperTokens userContext with UI components test", function () {
4448
let consoleLogs = [];
4549

4650
before(async function () {
47-
await fetch(`${TEST_SERVER_BASE_URL}/beforeeach`, {
48-
method: "POST",
49-
}).catch(console.error);
50-
51-
await fetch(`${TEST_SERVER_BASE_URL}/startst`, {
52-
method: "POST",
53-
}).catch(console.error);
51+
backendHook("before");
52+
const coreUrl = await setupCoreApp();
53+
await setupST({ coreUrl });
5454

5555
browser = await puppeteer.launch({
5656
args: ["--no-sandbox", "--disable-setuid-sandbox"],
@@ -65,18 +65,8 @@ describe("SuperTokens userContext with UI components test", function () {
6565
});
6666
});
6767

68-
after(async function () {
69-
await browser.close();
70-
await fetch(`${TEST_SERVER_BASE_URL}/after`, {
71-
method: "POST",
72-
}).catch(console.error);
73-
74-
await fetch(`${TEST_SERVER_BASE_URL}/stopst`, {
75-
method: "POST",
76-
}).catch(console.error);
77-
});
78-
7968
beforeEach(async function () {
69+
await backendHook("beforeEach");
8070
consoleLogs = [];
8171
consoleLogs = await clearBrowserCookiesWithoutAffectingConsole(page, consoleLogs);
8272
await Promise.all([
@@ -85,6 +75,17 @@ describe("SuperTokens userContext with UI components test", function () {
8575
]);
8676
});
8777

78+
afterEach(async function () {
79+
await screenshotOnFailure(this, browser);
80+
await backendHook("afterEach");
81+
});
82+
83+
after(async function () {
84+
await page?.close();
85+
await browser?.close();
86+
await backendHook("after");
87+
});
88+
8889
it("Test that user context gets passed correctly when resetting password", async function () {
8990
await Promise.all([
9091
page.goto(`${TEST_CLIENT_BASE_URL}/auth?authRecipe=thirdpartyemailpassword&mode=OFF&forUserContext=true`),

test/end-to-end/userroles.test.js

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
* Imports
1818
*/
1919
import assert from "assert";
20-
import puppeteer from "puppeteer";
21-
import fetch from "isomorphic-fetch";
2220
import {
2321
clearBrowserCookiesWithoutAffectingConsole,
2422
screenshotOnFailure,
@@ -29,14 +27,18 @@ import {
2927
submitForm,
3028
getInvalidClaimsJSON as getInvalidClaims,
3129
waitFor,
30+
waitForText,
31+
waitForUrl,
32+
setupBrowser,
33+
backendHook,
34+
setupCoreApp,
35+
setupST,
3236
} from "../helpers";
33-
34-
// Run the tests in a DOM environment.
35-
require("jsdom-global")();
36-
import { TEST_APPLICATION_SERVER_BASE_URL, TEST_CLIENT_BASE_URL, TEST_SERVER_BASE_URL } from "../constants";
37+
import { TEST_APPLICATION_SERVER_BASE_URL, TEST_CLIENT_BASE_URL } from "../constants";
3738

3839
describe("User Roles in the frontend", function () {
3940
before(async function () {
41+
backendHook("before");
4042
const isRolesSupported = await isUserRolesSupported();
4143
if (!isRolesSupported) {
4244
this.skip();
@@ -47,13 +49,8 @@ describe("User Roles in the frontend", function () {
4749
let browser;
4850
let page;
4951
before(async function () {
50-
await fetch(`${TEST_SERVER_BASE_URL}/beforeeach`, {
51-
method: "POST",
52-
}).catch(console.error);
53-
54-
await fetch(`${TEST_SERVER_BASE_URL}/startst`, {
55-
method: "POST",
56-
}).catch(console.error);
52+
const coreUrl = await setupCoreApp();
53+
await setupST({ coreUrl });
5754

5855
browser = await puppeteer.launch({
5956
args: ["--no-sandbox", "--disable-setuid-sandbox"],
@@ -69,24 +66,8 @@ describe("User Roles in the frontend", function () {
6966
await page.close();
7067
});
7168

72-
after(async function () {
73-
await browser.close();
74-
await fetch(`${TEST_SERVER_BASE_URL}/after`, {
75-
method: "POST",
76-
}).catch(console.error);
77-
await fetch(`${TEST_SERVER_BASE_URL}/stopst`, {
78-
method: "POST",
79-
}).catch(console.error);
80-
});
81-
82-
afterEach(async function () {
83-
await screenshotOnFailure(this, browser);
84-
if (page) {
85-
page.close();
86-
}
87-
});
88-
8969
beforeEach(async function () {
70+
backendHook("beforeEach");
9071
page = await browser.newPage();
9172
await clearBrowserCookiesWithoutAffectingConsole(page, []);
9273

@@ -103,6 +84,17 @@ describe("User Roles in the frontend", function () {
10384
await page.waitForSelector(".sessionInfo-user-id");
10485
});
10586

87+
afterEach(async function () {
88+
await screenshotOnFailure(this, browser);
89+
await page?.close();
90+
await backendHook("afterEach");
91+
});
92+
93+
after(async function () {
94+
await browser?.close();
95+
await backendHook("after");
96+
});
97+
10698
it("should be able to read in the frontend", async () => {
10799
assert.deepStrictEqual(
108100
await page.evaluate(() =>

0 commit comments

Comments
 (0)