Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the cypress-parallel #9178

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 19 additions & 55 deletions .github/workflows/cypress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ jobs:
permissions: write-all
if: github.repository == 'ohcnetwork/care_fe'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
containers: [1, 2, 3, 4]
env:
REACT_CARE_API_URL: http://localhost:9000
REACT_ENABLED_APPS: "ohcnetwork/care_hcx_fe@main"
Expand Down Expand Up @@ -59,11 +55,11 @@ jobs:
max_attempts: 5
command: curl -o /dev/null -s -w "%{http_code}\n" http://localhost:9000
on_retry_command: sleep 5

- name: Determine PR Origin
id: pr_origin
- name: Determine PR Origin
id: pr_origin
run: echo "::set-output name=is_forked::$( echo ${{ github.event.pull_request.head.repo.fork }})"
sainak marked this conversation as resolved.
Show resolved Hide resolved

sainak marked this conversation as resolved.
Show resolved Hide resolved
- name: Set up Node.js
uses: actions/setup-node@v4
with:
Expand All @@ -81,58 +77,26 @@ jobs:
sudo wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt-get install ./google-chrome-stable_current_amd64.deb

- name: Cypress run for Non-Forked PRs 🥬
if: steps.pr_origin.outputs.is_forked == 'false'
uses: cypress-io/github-action@v5
with:
env: SKIP_PREFLIGHT_CHECK=true
install: false
start: "npx vite preview --host"
wait-on: "http://localhost:4000"
wait-on-timeout: 300
browser: chrome
record: true
parallel: true
group: "UI-Chrome"
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_OPTIONS: --max_old_space_size=4096
COMMIT_INFO_MESSAGE: ${{github.event.pull_request.title}}
COMMIT_INFO_SHA: ${{github.event.pull_request.head.sha}}
- name: Start Frontend Application
run: npm run dev &
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Enhance frontend application startup reliability

The current implementation lacks proper process management and error handling.

Apply this diff to improve the implementation:

       - name: Start Frontend Application
-        run: npm run dev &
+        run: |
+          npm run dev > frontend.log 2>&1 &
+          echo $! > .frontend-pid
+          
+          # Give the process a moment to fail fast if there are immediate issues
+          sleep 5
+          if ! kill -0 $(cat .frontend-pid) 2>/dev/null; then
+            echo "Frontend failed to start. Last few lines of log:"
+            tail -n 20 frontend.log
+            exit 1
+          fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Start Frontend Application
run: npm run dev &
- name: Start Frontend Application
run: |
npm run dev > frontend.log 2>&1 &
echo $! > .frontend-pid
# Give the process a moment to fail fast if there are immediate issues
sleep 5
if ! kill -0 $(cat .frontend-pid) 2>/dev/null; then
echo "Frontend failed to start. Last few lines of log:"
tail -n 20 frontend.log
exit 1
fi


- name: Cypress run for Forked PRs 🥬
if: steps.pr_origin.outputs.is_forked == 'true'
uses: cypress-io/github-action@v5
with:
env: SKIP_PREFLIGHT_CHECK=true
install: false
start: "npx vite preview --host"
wait-on: "http://localhost:4000"
wait-on-timeout: 300
browser: chrome
record: true
parallel: true
group: "UI-Chrome"
env:
CYPRESS_SPLIT_TESTS: "true"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_OPTIONS: --max_old_space_size=4096
COMMIT_INFO_MESSAGE: ${{github.event.pull_request.title}}
COMMIT_INFO_SHA: ${{github.event.pull_request.head.sha}}
SPLIT: ${{ strategy.job-total }}
SPLIT_INDEX: ${{ strategy.job-index }}
- name: Wait for the Frontend Server to be Ready
run: npx wait-on http://localhost:4000
sainak marked this conversation as resolved.
Show resolved Hide resolved

- name: Upload cypress screenshots on failure 📸
uses: actions/upload-artifact@v3
if: failure()
with:
- name: Run Cypress Tests in Parallel
run: |
npm run cy:parallel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance Cypress test configuration and reliability

The parallel test execution configuration needs additional environment variables and reliability improvements.

Apply this diff to enhance the implementation:

       - name: Run Cypress Tests in Parallel
         run: |
+          # Configure Cypress environment
+          export CYPRESS_RECORD_KEY=${{ secrets.CYPRESS_RECORD_KEY }}
+          export CYPRESS_BROWSER="chrome"
+          export CYPRESS_RETRIES=2
+
+          # Configure test reporting
+          echo "Running Cypress tests with following configuration:"
+          echo "Browser: $CYPRESS_BROWSER"
+          echo "Retries: $CYPRESS_RETRIES"
+
           npm run cy:parallel

Committable suggestion skipped: line range outside the PR's diff.


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Enhance Cypress test execution configuration and reporting

The current implementation lacks proper configuration, error handling, and result reporting.

Apply this diff to improve the implementation:

       - name: Run Cypress Tests in Parallel
         run: |
+          # Configure Cypress environment
+          export CYPRESS_BROWSER="chrome"
+          export CYPRESS_RETRIES=2
+          
+          # Run tests with proper error handling
+          mkdir -p results
+          if ! npm run cy:parallel 2>&1 | tee results/cypress.log; then
+            echo "Test Execution Summary (Failed Tests):"
+            grep -A 1 "FAILED" results/cypress.log || true
+            exit 1
+          fi
+          
+          echo "Test Execution Summary (Passed Tests):"
+          grep -A 1 "PASSED" results/cypress.log || true
-          npm run cy:parallel
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Run Cypress Tests in Parallel
run: |
npm run cy:parallel
- name: Run Cypress Tests in Parallel
run: |
# Configure Cypress environment
export CYPRESS_BROWSER="chrome"
export CYPRESS_RETRIES=2
# Run tests with proper error handling
mkdir -p results
if ! npm run cy:parallel 2>&1 | tee results/cypress.log; then
echo "Test Execution Summary (Failed Tests):"
grep -A 1 "FAILED" results/cypress.log || true
exit 1
fi
echo "Test Execution Summary (Passed Tests):"
grep -A 1 "PASSED" results/cypress.log || true

- name: Upload Cypress Screenshots
uses: actions/upload-artifact@v3
if: failure()
with:
name: cypress-screenshots
path: cypress/screenshots

- name: Upload cypress videos 📹
- name: Upload Cypress Videos
uses: actions/upload-artifact@v3
if: ${{ failure() && steps.pr_origin.outputs.is_forked == 'true' }}
if: failure()
with:
name: cypress-videos
path: cypress/videos
path: cypress/videos
6 changes: 3 additions & 3 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { defineConfig } from "cypress";
import cypressSplit from "cypress-split";
import * as dotenv from "dotenv";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Add .env and .env.docker to .gitignore

The verification revealed that while some .env patterns are properly ignored, there are two environment files (.env and .env.docker) that are currently tracked in version control. These files might contain sensitive information and should be excluded.

  • Add the following patterns to .gitignore:
    • .env
    • .env.docker
  • Consider moving sensitive values from these files to example templates (like .env.example)
🔗 Analysis chain

Verify .env file security

The addition of dotenv for environment variable management is good practice. However, we should ensure that .env files are properly excluded from version control.

Also applies to: 6-6

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify .env files are properly ignored

# Check if .env is in .gitignore
echo "=== Checking .gitignore for .env patterns ==="
if [ -f .gitignore ]; then
    grep -E "^\.env|^\.env\." .gitignore || echo "WARNING: .env patterns not found in .gitignore"
fi

# Check for any committed .env files
echo -e "\n=== Checking for committed .env files ==="
fd -H "^\.env" -E .env.example -E .env.sample

Length of output: 399

import fs from "fs";

dotenv.config();

export default defineConfig({
projectId: "wf7d2m",
defaultCommandTimeout: 10000,
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here

require("cypress-localstorage-commands/plugin")(on, config); // eslint-disable-line

on("task", {
readFileMaybe(filename) {
if (fs.existsSync(filename)) {
return fs.readFileSync(filename, "utf8");
}

return null;
},
});
Expand Down
Loading
Loading