Skip to content

Commit

Permalink
Merge branch 'master' into releases/august
Browse files Browse the repository at this point in the history
  • Loading branch information
BatuhanW authored Jul 18, 2024
2 parents 788c7d0 + 054b9a6 commit 7fe07ed
Show file tree
Hide file tree
Showing 286 changed files with 2,289 additions and 677 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/scripts/build-example-chunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const isExampleAffected = (example, changedPackages) => {

const isExampleModified = (example) => {
const output = execSync(
`git diff --quiet HEAD origin/${BASE_REF} -- ${EXAMPLES_DIR}/${example} || echo changed`,
`git diff --quiet HEAD origin/${BASE_REF} -- ${EXAMPLES_DIR}/${example} cypress/e2e/${example} || echo changed`,
{ stdio: "pipe" },
);

Expand Down
44 changes: 19 additions & 25 deletions .github/workflows/scripts/e2e-examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,34 +45,26 @@ const getProjectInfo = (path) => {
const dependencies = Object.keys(packageJson.dependencies || {});
const devDependencies = Object.keys(packageJson.devDependencies || {});

let port = 3000;
let command = `pnpm dev --scope ${projectName}`;
let additionalParams = "";
const allDependencies = [...dependencies, ...devDependencies];

// check for vite
if (dependencies.includes("vite") || devDependencies.includes("vite")) {
port = 5173;
const command = `pnpm start --scope ${projectName}`;

if (dependencies.includes("@refinedev/devtools")) {
additionalParams = "-- --devtools false";
}
let port;

if (allDependencies.includes("vite")) {
port = 4173;
}

// check for next and remix
if (
dependencies.includes("next") ||
devDependencies.includes("next") ||
dependencies.includes("@remix-run/node") ||
devDependencies.includes("@remix-run/node")
allDependencies.includes("next") ||
allDependencies.includes("@remix-run/node")
) {
port = 3000;
command = `pnpm build --scope ${projectName} && pnpm run --filter ${projectName} start:prod`;
}

return {
port,
command,
additionalParams,
};
};

Expand Down Expand Up @@ -177,12 +169,9 @@ const runTests = async () => {
for await (const path of examplesToRun) {
console.log(`::group::Example ${path}`);

const { port, command, additionalParams } = getProjectInfo(
`${EXAMPLES_DIR}/${path}`,
);
const { port, command } = getProjectInfo(`${EXAMPLES_DIR}/${path}`);
console.log("port", port);
console.log("command", command);
console.log("additionalParams", additionalParams);

prettyLog("blue", `Running for ${path} at port ${port}`);

Expand All @@ -192,9 +181,9 @@ const runTests = async () => {

let failed = false;

// starting the dev server
// build and start example
try {
start = exec(`${command} ${additionalParams}`);
start = exec(command);

start.stdout.on("data", console.log);
start.stderr.on("data", console.error);
Expand Down Expand Up @@ -225,12 +214,17 @@ const runTests = async () => {

try {
if (!failed) {
const params = `--record --group ${path}`;
const runner = `pnpm cypress:run --spec cypress/e2e/${path} ${params}`;
const additionalParams = [
`--record --group ${path}`,
`--spec cypress/e2e/${path}`,
`--config baseUrl=http://localhost:${port}`,
];

const runCommand = `pnpm cypress:run ${additionalParams.join(" ")} `;

prettyLog("blue", `Running tests for ${path}`);

const { promise } = execPromise(runner);
const { promise } = execPromise(runCommand);

await promise;

Expand Down
1 change: 1 addition & 0 deletions cypress/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default defineConfig({
viewportWidth: 1920,
viewportHeight: 1080,
e2e: {
baseUrl: "http://localhost:5173",
setupNodeEvents(on, config) {
// implement node event listeners here
},
Expand Down
16 changes: 7 additions & 9 deletions cypress/e2e/auth-antd/all.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
/// <reference types="../../cypress/support" />

describe("auth-antd", () => {
const BASE_URL = "http://localhost:5173";

beforeEach(() => {
cy.clearAllCookies();
cy.clearAllLocalStorage();
cy.clearAllSessionStorage();
cy.visit(BASE_URL);
cy.visit("/");
});

const submitAuthForm = () => {
Expand All @@ -32,7 +30,7 @@ describe("auth-antd", () => {

cy.location("pathname").should("eq", "/");
cy.getAllLocalStorage().then((ls) => {
expect(ls[BASE_URL]).to.have.property("email");
expect(ls[Cypress.config("baseUrl")!]).to.have.property("email");
});
});

Expand All @@ -48,7 +46,7 @@ describe("auth-antd", () => {
login();
cy.location("pathname").should("eq", "/");

cy.visit(`${BASE_URL}/test`);
cy.visit("/test");
cy.location("pathname").should("eq", "/test");
cy.clearAllLocalStorage();
cy.reload();
Expand All @@ -60,7 +58,7 @@ describe("auth-antd", () => {
});

it("should redirect to /login?to= if user not authenticated", () => {
cy.visit(`${BASE_URL}/test-route`);
cy.visit("/test-route");
cy.get(".ant-card-head-title > .ant-typography").contains(
/sign in to your account/i,
);
Expand All @@ -78,7 +76,7 @@ describe("auth-antd", () => {
login();
cy.location("pathname").should("eq", "/");
cy.getAllLocalStorage().then((ls) => {
expect(ls[BASE_URL]).to.have.property("email");
expect(ls[Cypress.config("baseUrl")!]).to.have.property("email");
});
});

Expand All @@ -97,7 +95,7 @@ describe("auth-antd", () => {

describe("forgot password", () => {
it("should throw error if forgot password email is wrong", () => {
cy.visit(`${BASE_URL}/forgot-password`);
cy.visit("/forgot-password");
cy.get("#email").clear().type("[email protected]");
submitAuthForm();
cy.getAntdNotification().contains(/invalid email/i);
Expand All @@ -107,7 +105,7 @@ describe("auth-antd", () => {

describe("update password", () => {
it("should throw error if update password is wrong", () => {
cy.visit(`${BASE_URL}/update-password`);
cy.visit("/update-password");
cy.get("#password").clear().type("123456");
cy.get("#confirmPassword").clear().type("123456");
submitAuthForm();
Expand Down
6 changes: 2 additions & 4 deletions cypress/e2e/auth-auth0/all.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
/// <reference types="../../cypress/support" />

describe("auth-auth0", () => {
const BASE_URL = "http://localhost:5173";

const login = () => {
cy.get("button")
.contains(/sign in/i)
Expand All @@ -23,7 +21,7 @@ describe("auth-auth0", () => {
cy.clearAllCookies();
cy.clearAllLocalStorage();
cy.clearAllSessionStorage();
cy.visit(BASE_URL);
cy.visit("/");
});

describe("login", () => {
Expand All @@ -36,7 +34,7 @@ describe("auth-auth0", () => {
cy.location("pathname").should("eq", "/login");
login();
cy.location("pathname").should("eq", "/posts");
cy.visit(`${BASE_URL}/test-route`);
cy.visit("/test-route");
cy.get(".ant-result-404").should("exist");
cy.clearAllCookies();
cy.clearAllSessionStorage();
Expand Down
16 changes: 7 additions & 9 deletions cypress/e2e/auth-chakra-ui/all.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
/// <reference types="../../cypress/support" />

describe("auth-chakra-ui", () => {
const BASE_URL = "http://localhost:5173";

const submitAuthForm = () => {
return cy.get("button[type=submit]").click();
};
Expand All @@ -22,15 +20,15 @@ describe("auth-chakra-ui", () => {
cy.clearAllCookies();
cy.clearAllLocalStorage();
cy.clearAllSessionStorage();
cy.visit(BASE_URL);
cy.visit("/");
});

describe("login", () => {
it("should login", () => {
login();
cy.location("pathname").should("eq", "/posts");
cy.getAllLocalStorage().then((ls) => {
expect(ls[BASE_URL]).to.have.property("email");
expect(ls[Cypress.config("baseUrl")!]).to.have.property("email");
});
});

Expand All @@ -46,7 +44,7 @@ describe("auth-chakra-ui", () => {
login();
cy.location("pathname").should("eq", "/posts");

cy.visit(`${BASE_URL}/test`);
cy.visit("/test");
cy.location("pathname").should("eq", "/test");
cy.clearAllLocalStorage();
cy.reload();
Expand All @@ -58,7 +56,7 @@ describe("auth-chakra-ui", () => {
});

it("should redirect to /login?to= if user not authenticated", () => {
cy.visit(`${BASE_URL}/test-route`);
cy.visit("/test-route");
cy.get(".chakra-heading").contains(/sign in to your account/i);
cy.location("search").should("contains", "to=%2Ftest");
cy.location("pathname").should("eq", "/login");
Expand All @@ -74,7 +72,7 @@ describe("auth-chakra-ui", () => {
login();
cy.location("pathname").should("eq", "/posts");
cy.getAllLocalStorage().then((ls) => {
expect(ls[BASE_URL]).to.have.property("email");
expect(ls[Cypress.config("baseUrl")!]).to.have.property("email");
});
});

Expand All @@ -93,7 +91,7 @@ describe("auth-chakra-ui", () => {

describe("forgot password", () => {
it("should throw error if forgot password email is wrong", () => {
cy.visit(`${BASE_URL}/forgot-password`);
cy.visit("/forgot-password");
cy.get("#email").clear().type("[email protected]");
submitAuthForm();
cy.getChakraUINotification().contains(/invalid email/i);
Expand All @@ -103,7 +101,7 @@ describe("auth-chakra-ui", () => {

describe("update password", () => {
it("should throw error if update password is wrong", () => {
cy.visit(`${BASE_URL}/update-password`);
cy.visit("/update-password");
cy.get("#password").clear().type("123456");
cy.get("#confirmPassword").clear().type("123456");
submitAuthForm();
Expand Down
4 changes: 1 addition & 3 deletions cypress/e2e/auth-google-login/all.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
/// <reference types="../../cypress/support" />

describe("auth-google-login", () => {
const BASE_URL = "http://localhost:5173";

beforeEach(() => {
cy.clearAllCookies();
cy.clearAllLocalStorage();
cy.clearAllSessionStorage();
cy.visit(BASE_URL);
cy.visit("/");
});

it("has google button", () => {
Expand Down
12 changes: 5 additions & 7 deletions cypress/e2e/auth-headless/all.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
/// <reference types="../../cypress/support" />

describe("auth-headless", () => {
const BASE_URL = "http://localhost:5173";

const submitAuthForm = () => {
return cy.get("[type=submit]").click();
};
Expand All @@ -22,23 +20,23 @@ describe("auth-headless", () => {
cy.clearAllCookies();
cy.clearAllLocalStorage();
cy.clearAllSessionStorage();
cy.visit(BASE_URL);
cy.visit("/");
});

describe("login", () => {
it("should login", () => {
login();
cy.location("pathname").should("eq", "/posts");
cy.getAllLocalStorage().then((ls) => {
expect(ls[BASE_URL]).to.have.property("email");
expect(ls[Cypress.config("baseUrl")!]).to.have.property("email");
});
});

it("should has 'to' param on URL after redirected to /login", () => {
login();
cy.location("pathname").should("eq", "/posts");

cy.visit(`${BASE_URL}/test`);
cy.visit("/test");
cy.location("pathname").should("eq", "/test");
cy.clearAllLocalStorage();
cy.reload();
Expand All @@ -47,7 +45,7 @@ describe("auth-headless", () => {
});

it("should redirect to /login?to= if user not authenticated", () => {
cy.visit(`${BASE_URL}/test-route`);
cy.visit("/test-route");
cy.get("h1").contains(/sign in to your account/i);
cy.location("search").should("contains", "to=%2Ftest");
cy.location("pathname").should("eq", "/login");
Expand All @@ -63,7 +61,7 @@ describe("auth-headless", () => {
login();
cy.location("pathname").should("eq", "/posts");
cy.getAllLocalStorage().then((ls) => {
expect(ls[BASE_URL]).to.have.property("email");
expect(ls[Cypress.config("baseUrl")!]).to.have.property("email");
});
});
});
Expand Down
6 changes: 2 additions & 4 deletions cypress/e2e/auth-keycloak/all.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
/// <reference types="../../cypress/support" />

describe("auth-keycloak", () => {
const BASE_URL = "http://localhost:5173";

const login = () => {
cy.get("button")
.contains(/sign in/i)
Expand All @@ -25,7 +23,7 @@ describe("auth-keycloak", () => {
cy.interceptGETPosts();
cy.interceptGETCategories();

cy.visit(BASE_URL);
cy.visit("/");
});

describe("login", () => {
Expand All @@ -36,7 +34,7 @@ describe("auth-keycloak", () => {

it("should redirect to /login if user not authenticated", () => {
login();
cy.visit(`${BASE_URL}/test-route`);
cy.visit("/test-route");
cy.clearAllCookies();
cy.reload();
cy.location("pathname").should("eq", "/login");
Expand Down
Loading

0 comments on commit 7fe07ed

Please sign in to comment.