Skip to content

Commit

Permalink
Fix cypress tests for ts-node
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasdotcom committed Sep 15, 2023
1 parent 39455f5 commit ef041b9
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 43 deletions.
24 changes: 18 additions & 6 deletions cypress/e2e/invite.cy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
describe("Invite User into league and change some league Settings and run through a matchday.", () => {
before(() => {
cy.exec("export APP_ENV=test; node cypress/e2e/invite1.js");
cy.exec(
"export APP_ENV=test; ts-node --project=./tsconfig2.json cypress/e2e/invite1.ts",
);
});
// Used to signup change username and password and login again
it("invite", () => {
Expand Down Expand Up @@ -227,7 +229,9 @@ describe("Invite User into league and change some league Settings and run throug
.click();
cy.contains("Buying");
// Starts the matchday
cy.exec("export APP_ENV=test; node cypress/e2e/invite2.js").then(() => {
cy.exec(
"export APP_ENV=test; ts-node --project=./tsconfig2.json cypress/e2e/invite2.ts",
).then(() => {
cy.contains("Transfers").click();
});
cy.contains("Transfer Market closed");
Expand Down Expand Up @@ -283,7 +287,9 @@ describe("Invite User into league and change some league Settings and run throug
);
cy.contains("Erling Haaland").parent().parent().parent().contains("0");
// Sims matchday until all players have played
cy.exec("export APP_ENV=test; node cypress/e2e/invite3.js");
cy.exec(
"export APP_ENV=test; ts-node --project=./tsconfig2.json cypress/e2e/invite3.ts",
);
// Checks that the user points are correct
cy.contains("Standings").click();
cy.get(".MuiTableBody-root > :nth-child(1) > :nth-child(2)").contains("44");
Expand Down Expand Up @@ -327,7 +333,9 @@ describe("Invite User into league and change some league Settings and run throug
.contains("Player has already played");
matchdays.push({ invite1: user1Money, invite2: user2Money });
// Starts the transfer period and sells Muller
cy.exec("export APP_ENV=test; node cypress/e2e/invite4.js");
cy.exec(
"export APP_ENV=test; ts-node --project=./tsconfig2.json cypress/e2e/invite4.ts",
);
cy.intercept("/api/player/Bundesliga/ef5112a9f971a1e40966").as(
"loadRobert",
);
Expand Down Expand Up @@ -444,7 +452,9 @@ describe("Invite User into league and change some league Settings and run throug
cy.contains("19.7 M");
matchdays.push({ invite1: user1Money, invite2: user2Money });
// Simulates an empty matchday
cy.exec("export APP_ENV=test; node cypress/e2e/invite5.js");
cy.exec(
"export APP_ENV=test; ts-node --project=./tsconfig2.json cypress/e2e/invite5.ts",
);
// Adds a third user that joins late
cy.clearCookies();
cy.get("#logout").click();
Expand Down Expand Up @@ -478,7 +488,9 @@ describe("Invite User into league and change some league Settings and run throug
cy.get("#confirmation").type("New Sample League");
cy.contains("Save admin settings").click();
// Simulates an empty matchday
cy.exec("export APP_ENV=test; node cypress/e2e/invite5.js");
cy.exec(
"export APP_ENV=test; ts-node --project=./tsconfig2.json cypress/e2e/invite5.ts",
);
// Makes sure that the matchday does not exist
cy.go("back").then(() => {
cy.get(".MuiPagination-ul > :nth-child(4) > .MuiButtonBase-root")
Expand Down
7 changes: 4 additions & 3 deletions cypress/e2e/invite1.js → cypress/e2e/invite1.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import connect from "#database";
import { updateData } from "#scripts/update";

run();
// Used to reset the users and invites for the user test
async function run() {
const database = require("../../Modules/database");
const updateData = require("../../scripts/update.js").updateData;
const connection = await database.default();
const connection = await connect();
await connection.query("DELETE FROM users WHERE username like 'Invite%'");
await connection.query("DELETE FROM invite WHERE inviteID='invite1'");
await connection.query("DELETE FROM data WHERE value1='locked'");
Expand Down
3 changes: 2 additions & 1 deletion cypress/e2e/invite2.js → cypress/e2e/invite2.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { updateData } from "#scripts/update";

run();
// Starts the matchday
async function run() {
const updateData = require("../../scripts/update.js").updateData;
await updateData("", "./sample/data2.json");
}
3 changes: 2 additions & 1 deletion cypress/e2e/invite3.js → cypress/e2e/invite3.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { updateData } from "#scripts/update";

run();
// Simulates all the games
async function run() {
const updateData = require("../../scripts/update.js").updateData;
await updateData("", "./sample/data3.json");
}
3 changes: 2 additions & 1 deletion cypress/e2e/invite4.js → cypress/e2e/invite4.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { updateData } from "#scripts/update";

run();
// Checks if the data after the games have changed gets updated and ends the matchday
async function run() {
const updateData = require("../../scripts/update.js").updateData;
await updateData("", "./sample/data4.json");
await updateData("", "./sample/data5.json");
}
3 changes: 2 additions & 1 deletion cypress/e2e/invite5.js → cypress/e2e/invite5.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { updateData } from "#scripts/update";

run();
// Simulates a matchday
async function run() {
const updateData = require("../../scripts/update.js").updateData;
await updateData("", "./sample/data6.json");
await updateData("", "./sample/data5.json");
}
4 changes: 3 additions & 1 deletion cypress/e2e/user.cy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
describe("User", () => {
before(() => {
cy.exec("export APP_ENV=test; node cypress/e2e/user.js");
cy.exec(
"export APP_ENV=test; ts-node --project=./tsconfig2.json cypress/e2e/user.ts",
);
});
// Used to signup change username and password and login again
it("signup", () => {
Expand Down
5 changes: 3 additions & 2 deletions cypress/e2e/user.js → cypress/e2e/user.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import connect from "#database";

run();
// Used to reset the users for the user test
async function run() {
const database = require("../../Modules/database");
const connection = await database.default();
const connection = await connect();
connection.query(
"DELETE FROM users WHERE username='Sample User' or username='New Sample Username'",
);
Expand Down
27 changes: 0 additions & 27 deletions tsconfig3.json

This file was deleted.

0 comments on commit ef041b9

Please sign in to comment.