Skip to content

Reduce Cypress Execution Time with Github Actions Parallel Jobs #3932

Reduce Cypress Execution Time with Github Actions Parallel Jobs

Reduce Cypress Execution Time with Github Actions Parallel Jobs #3932

Workflow file for this run

name: Test
on: [push, pull_request]
jobs:
CypressMockTests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
container: [1, 2, 3, 4, 5] # Creates 5 parallel executions for Cypress tests.
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/[email protected]
with:
node-version: '18.x'
- name: Install Node.js packages for Cypress
run: npm install
- name: Get test files
id: test-files
run: |
echo "Current working directory:"
pwd
TEST_DIR="frontend/src/__tests__/cypress/cypress/tests/mocked"
echo "Listing contents of the current directory:"
ls -la
echo "Checking for test files in $TEST_DIR"
echo "Listing contents of frontend/src/__tests__/cypress/cypress/tests:"
ls -la frontend/src/__tests__/cypress/cypress/tests/
if [ -d "$TEST_DIR" ]; then
echo "Listing contents of mocked directory:"
ls -la "$TEST_DIR"
TEST_FILES=$(find "$TEST_DIR" -name "*.cy.ts" | tr '\n' ',')
echo "Found test files: $TEST_FILES"
echo "files=$TEST_FILES" >> $GITHUB_OUTPUT
else
echo "Directory does not exist. No test files found." >> $GITHUB_OUTPUT
echo "files=" >> $GITHUB_OUTPUT # Set empty output if no files found
fi
- name: Run Cypress Mock Tests in Parallel
env:
CONTAINER_INDEX: ${{ matrix.container }}
TEST_FILES: ${{ steps.test-files.outputs.files }}
run: |
echo "Running Cypress tests for container $CONTAINER_INDEX..."
echo "Test Files: $TEST_FILES"
# Generate the list of spec files for this container and trim trailing comma
SPEC_FILES=$(echo "$TEST_FILES" | tr ',' '\n' | awk -v container="$CONTAINER_INDEX" 'NR % 5 == container - 1' | sed 's|^frontend/||' | tr '\n' ',' | sed 's/,$//')
# Check if SPEC_FILES is empty
if [ -z "$SPEC_FILES" ]; then
echo "No spec files found for container $CONTAINER_INDEX. Skipping Cypress tests."
exit 0
else
echo "Spec files for this container: $SPEC_FILES"
export SPEC_PATTERN="$SPEC_FILES"
echo "Running Cypress with spec pattern: ${SPEC_PATTERN}"
cd frontend && npm run test:cypress-ci
fi