Skip to content

Commit 054b9a6

Browse files
authored
refactor(ci): dont use dev server for e2e tests (#6150)
1 parent cb7c125 commit 054b9a6

File tree

284 files changed

+574
-676
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

284 files changed

+574
-676
lines changed

.github/workflows/scripts/build-example-chunks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const isExampleAffected = (example, changedPackages) => {
4545

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

.github/workflows/scripts/e2e-examples.js

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,34 +45,26 @@ const getProjectInfo = (path) => {
4545
const dependencies = Object.keys(packageJson.dependencies || {});
4646
const devDependencies = Object.keys(packageJson.devDependencies || {});
4747

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

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

56-
if (dependencies.includes("@refinedev/devtools")) {
57-
additionalParams = "-- --devtools false";
58-
}
52+
let port;
53+
54+
if (allDependencies.includes("vite")) {
55+
port = 4173;
5956
}
6057

61-
// check for next and remix
6258
if (
63-
dependencies.includes("next") ||
64-
devDependencies.includes("next") ||
65-
dependencies.includes("@remix-run/node") ||
66-
devDependencies.includes("@remix-run/node")
59+
allDependencies.includes("next") ||
60+
allDependencies.includes("@remix-run/node")
6761
) {
6862
port = 3000;
69-
command = `pnpm build --scope ${projectName} && pnpm run --filter ${projectName} start:prod`;
7063
}
7164

7265
return {
7366
port,
7467
command,
75-
additionalParams,
7668
};
7769
};
7870

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

180-
const { port, command, additionalParams } = getProjectInfo(
181-
`${EXAMPLES_DIR}/${path}`,
182-
);
172+
const { port, command } = getProjectInfo(`${EXAMPLES_DIR}/${path}`);
183173
console.log("port", port);
184174
console.log("command", command);
185-
console.log("additionalParams", additionalParams);
186175

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

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

193182
let failed = false;
194183

195-
// starting the dev server
184+
// build and start example
196185
try {
197-
start = exec(`${command} ${additionalParams}`);
186+
start = exec(command);
198187

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

226215
try {
227216
if (!failed) {
228-
const params = `--record --group ${path}`;
229-
const runner = `pnpm cypress:run --spec cypress/e2e/${path} ${params}`;
217+
const additionalParams = [
218+
`--record --group ${path}`,
219+
`--spec cypress/e2e/${path}`,
220+
`--config baseUrl=http://localhost:${port}`,
221+
];
222+
223+
const runCommand = `pnpm cypress:run ${additionalParams.join(" ")} `;
230224

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

233-
const { promise } = execPromise(runner);
227+
const { promise } = execPromise(runCommand);
234228

235229
await promise;
236230

cypress/cypress.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default defineConfig({
1111
viewportWidth: 1920,
1212
viewportHeight: 1080,
1313
e2e: {
14+
baseUrl: "http://localhost:5173",
1415
setupNodeEvents(on, config) {
1516
// implement node event listeners here
1617
},

cypress/e2e/auth-antd/all.cy.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
/// <reference types="../../cypress/support" />
33

44
describe("auth-antd", () => {
5-
const BASE_URL = "http://localhost:5173";
6-
75
beforeEach(() => {
86
cy.clearAllCookies();
97
cy.clearAllLocalStorage();
108
cy.clearAllSessionStorage();
11-
cy.visit(BASE_URL);
9+
cy.visit("/");
1210
});
1311

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

3331
cy.location("pathname").should("eq", "/");
3432
cy.getAllLocalStorage().then((ls) => {
35-
expect(ls[BASE_URL]).to.have.property("email");
33+
expect(ls[Cypress.config("baseUrl")!]).to.have.property("email");
3634
});
3735
});
3836

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

51-
cy.visit(`${BASE_URL}/test`);
49+
cy.visit("/test");
5250
cy.location("pathname").should("eq", "/test");
5351
cy.clearAllLocalStorage();
5452
cy.reload();
@@ -60,7 +58,7 @@ describe("auth-antd", () => {
6058
});
6159

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

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

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

108106
describe("update password", () => {
109107
it("should throw error if update password is wrong", () => {
110-
cy.visit(`${BASE_URL}/update-password`);
108+
cy.visit("/update-password");
111109
cy.get("#password").clear().type("123456");
112110
cy.get("#confirmPassword").clear().type("123456");
113111
submitAuthForm();

cypress/e2e/auth-auth0/all.cy.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
/// <reference types="../../cypress/support" />
33

44
describe("auth-auth0", () => {
5-
const BASE_URL = "http://localhost:5173";
6-
75
const login = () => {
86
cy.get("button")
97
.contains(/sign in/i)
@@ -23,7 +21,7 @@ describe("auth-auth0", () => {
2321
cy.clearAllCookies();
2422
cy.clearAllLocalStorage();
2523
cy.clearAllSessionStorage();
26-
cy.visit(BASE_URL);
24+
cy.visit("/");
2725
});
2826

2927
describe("login", () => {
@@ -36,7 +34,7 @@ describe("auth-auth0", () => {
3634
cy.location("pathname").should("eq", "/login");
3735
login();
3836
cy.location("pathname").should("eq", "/posts");
39-
cy.visit(`${BASE_URL}/test-route`);
37+
cy.visit("/test-route");
4038
cy.get(".ant-result-404").should("exist");
4139
cy.clearAllCookies();
4240
cy.clearAllSessionStorage();

cypress/e2e/auth-chakra-ui/all.cy.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
/// <reference types="../../cypress/support" />
33

44
describe("auth-chakra-ui", () => {
5-
const BASE_URL = "http://localhost:5173";
6-
75
const submitAuthForm = () => {
86
return cy.get("button[type=submit]").click();
97
};
@@ -22,15 +20,15 @@ describe("auth-chakra-ui", () => {
2220
cy.clearAllCookies();
2321
cy.clearAllLocalStorage();
2422
cy.clearAllSessionStorage();
25-
cy.visit(BASE_URL);
23+
cy.visit("/");
2624
});
2725

2826
describe("login", () => {
2927
it("should login", () => {
3028
login();
3129
cy.location("pathname").should("eq", "/posts");
3230
cy.getAllLocalStorage().then((ls) => {
33-
expect(ls[BASE_URL]).to.have.property("email");
31+
expect(ls[Cypress.config("baseUrl")!]).to.have.property("email");
3432
});
3533
});
3634

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

49-
cy.visit(`${BASE_URL}/test`);
47+
cy.visit("/test");
5048
cy.location("pathname").should("eq", "/test");
5149
cy.clearAllLocalStorage();
5250
cy.reload();
@@ -58,7 +56,7 @@ describe("auth-chakra-ui", () => {
5856
});
5957

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

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

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

104102
describe("update password", () => {
105103
it("should throw error if update password is wrong", () => {
106-
cy.visit(`${BASE_URL}/update-password`);
104+
cy.visit("/update-password");
107105
cy.get("#password").clear().type("123456");
108106
cy.get("#confirmPassword").clear().type("123456");
109107
submitAuthForm();

cypress/e2e/auth-google-login/all.cy.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
/// <reference types="../../cypress/support" />
33

44
describe("auth-google-login", () => {
5-
const BASE_URL = "http://localhost:5173";
6-
75
beforeEach(() => {
86
cy.clearAllCookies();
97
cy.clearAllLocalStorage();
108
cy.clearAllSessionStorage();
11-
cy.visit(BASE_URL);
9+
cy.visit("/");
1210
});
1311

1412
it("has google button", () => {

cypress/e2e/auth-headless/all.cy.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
/// <reference types="../../cypress/support" />
33

44
describe("auth-headless", () => {
5-
const BASE_URL = "http://localhost:5173";
6-
75
const submitAuthForm = () => {
86
return cy.get("[type=submit]").click();
97
};
@@ -22,23 +20,23 @@ describe("auth-headless", () => {
2220
cy.clearAllCookies();
2321
cy.clearAllLocalStorage();
2422
cy.clearAllSessionStorage();
25-
cy.visit(BASE_URL);
23+
cy.visit("/");
2624
});
2725

2826
describe("login", () => {
2927
it("should login", () => {
3028
login();
3129
cy.location("pathname").should("eq", "/posts");
3230
cy.getAllLocalStorage().then((ls) => {
33-
expect(ls[BASE_URL]).to.have.property("email");
31+
expect(ls[Cypress.config("baseUrl")!]).to.have.property("email");
3432
});
3533
});
3634

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

41-
cy.visit(`${BASE_URL}/test`);
39+
cy.visit("/test");
4240
cy.location("pathname").should("eq", "/test");
4341
cy.clearAllLocalStorage();
4442
cy.reload();
@@ -47,7 +45,7 @@ describe("auth-headless", () => {
4745
});
4846

4947
it("should redirect to /login?to= if user not authenticated", () => {
50-
cy.visit(`${BASE_URL}/test-route`);
48+
cy.visit("/test-route");
5149
cy.get("h1").contains(/sign in to your account/i);
5250
cy.location("search").should("contains", "to=%2Ftest");
5351
cy.location("pathname").should("eq", "/login");
@@ -63,7 +61,7 @@ describe("auth-headless", () => {
6361
login();
6462
cy.location("pathname").should("eq", "/posts");
6563
cy.getAllLocalStorage().then((ls) => {
66-
expect(ls[BASE_URL]).to.have.property("email");
64+
expect(ls[Cypress.config("baseUrl")!]).to.have.property("email");
6765
});
6866
});
6967
});

cypress/e2e/auth-keycloak/all.cy.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
/// <reference types="../../cypress/support" />
33

44
describe("auth-keycloak", () => {
5-
const BASE_URL = "http://localhost:5173";
6-
75
const login = () => {
86
cy.get("button")
97
.contains(/sign in/i)
@@ -25,7 +23,7 @@ describe("auth-keycloak", () => {
2523
cy.interceptGETPosts();
2624
cy.interceptGETCategories();
2725

28-
cy.visit(BASE_URL);
26+
cy.visit("/");
2927
});
3028

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

3735
it("should redirect to /login if user not authenticated", () => {
3836
login();
39-
cy.visit(`${BASE_URL}/test-route`);
37+
cy.visit("/test-route");
4038
cy.clearAllCookies();
4139
cy.reload();
4240
cy.location("pathname").should("eq", "/login");

0 commit comments

Comments
 (0)