Skip to content

Commit

Permalink
week 1 - Upgrade/cypress workflow (#16)
Browse files Browse the repository at this point in the history
* chore: Remove test workflow file

* chore: Add Cypress test recording configuration

* chore: Update cypress dependency to version 13.0.0

* Implement Cypress-recommended workflow by replacing test.yml with cypress.yml for enhanced E2E testing setup
  • Loading branch information
lokeshwar777 authored Jun 8, 2024
1 parent 3b0952c commit aa70cbe
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 66 deletions.
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
VITE_APP_FIREBASE_FCM_VAPID_KEY=<FIREBASE_VAPID_KEY>
VITE_APP_USE_EMULATOR=<USE_EMULATOR>
CYPRESS_PROJECT_ID=<CYPRESS_PROJECT_ID>
CYPRESS_RECORD_KEY=<CYPRESS_RECORD_KEY>
112 changes: 112 additions & 0 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: Cypress End-to-End Tests

on: push

jobs:
cypress-tests:
name: Run Cypress Tests
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
node: [18]
containers: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

env:
CI: false

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup Node.js Environment
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}

- name: Cache Node.js modules
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-${{ matrix.node }}-
- name: Create .env File
run: |
echo "VITE_APP_FIREBASE_API_KEY=${{ secrets.VITE_APP_FIREBASE_API_KEY }}" >> .env
echo "VITE_APP_FIREBASE_PROJECT_ID=${{ secrets.VITE_APP_FIREBASE_PROJECT_ID }}" >> .env
echo "VITE_APP_FIREBASE_MESSAGING_SENDER_ID=${{ secrets.VITE_APP_FIREBASE_MESSAGING_SENDER_ID }}" >> .env
echo "VITE_APP_FIREBASE_APP_ID=${{ secrets.VITE_APP_FIREBASE_APP_ID }}" >> .env
echo "VITE_APP_FIREBASE_MEASUREMENTID=${{ secrets.VITE_APP_FIREBASE_MEASUREMENTID }}" >> .env
echo "VITE_APP_FIREBASE_FCM_VAPID_KEY=${{ secrets.VITE_APP_FIREBASE_FCM_VAPID_KEY }}" >> .env
echo "VITE_APP_AUTH_DOMAIN=${{ secrets.VITE_APP_AUTH_DOMAIN }}" >> .env
echo "VITE_APP_DATABASE_URL=${{ secrets.VITE_APP_DATABASE_URL }}" >> .env
echo "VITE_APP_USE_EMULATOR=true" >> .env
echo "SKIP_PREFLIGHT_CHECK=true" >> .env
echo "CI=false" >> .env
echo "CYPRESS_PROJECT_ID=${{ secrets.CYPRESS_PROJECT_ID }}" >> .env
- name: Prepare Firebase Service Account
run: |
mkdir -p functions/private
echo "${{ secrets.FIREBASE_SERVICE_ACCOUNT }}" > functions/private/cl-dev-pk.json
- name: Install Functions Dependencies
run: cd functions && npm install --legacy-peer-deps

- name: Install Firebase CLI
run: npm install -g firebase-tools

- name: Start Firebase Emulators
run: |
firebase emulators:start --import=./testdata --project ${{ secrets.VITE_APP_FIREBASE_PROJECT_ID }} &
sleep 15
- name: Run Cypress Tests
uses: cypress-io/github-action@v6
with:
browser: chrome
record: true
tag: node-${{ matrix.node }}
parallel: true
config-file: cypress.config.js
group: "GitHub Actions"
install-command: npm install --legacy-peer-deps
build: npm run build
start: npm run dev
wait-on: "http://localhost:5173"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
CYPRESS_PROJECT_ID: ${{ secrets.CYPRESS_PROJECT_ID }}
COMMIT_INFO_BRANCH: ${{ github.ref_name }}

print-results:
name: Print Cypress Cloud URL
needs: cypress-tests
runs-on: ubuntu-latest
if: always()
steps:
- name: Print Cypress Cloud URL
run: |
echo Cypress finished with: ${{ needs.cypress-tests.outcome }}
echo See results at ${{ needs.cypress-tests.outputs.resultsUrl }}
handle-failure:
name: Handle Failure
if: ${{ failure() }}
runs-on: ubuntu-latest
steps:
- name: Upload Cypress Artifacts
uses: actions/upload-artifact@v4
with:
name: Cypress Artifacts
path: |
cypress/screenshots
cypress/videos
if-no-files-found: ignore

- name: Notify on Failure
run: echo "The workflow has failed!"
64 changes: 0 additions & 64 deletions .github/workflows/test.yml

This file was deleted.

4 changes: 3 additions & 1 deletion cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ export default defineConfig({
baseUrl: "http://localhost:5173",
testIsolation: false
},
projectId: process.env.CYPRESS_PROJECT_ID
projectId: import.meta.env.CYPRESS_PROJECT_ID,
record: true, // Enable test recording
key: import.meta.env.CYPRESS_RECORD_KEY // Cypress record key
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"@types/react-dom": "^18.0.9",
"@vitejs/plugin-react-swc": "^3.0.0",
"common-tags": "^1.8.2",
"cypress": "^12.3.0",
"cypress": "^13.0.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-react": "^7.33.2",
"husky": "^8.0.0",
Expand Down

0 comments on commit aa70cbe

Please sign in to comment.