Gitlab CI/CD Cypress tests in parallel

Hi everyone,

I’m trying to run Cypress tests in parallel using the npx cypress-parallel command in my GitLab CI/CD pipeline configuration file. However, I’m running into some issues and the command is failing.

Here’s the command I’m using:

npx cypress-parallel -s test -t 1 -d 'cypress/e2e/**/*.cy.ts' -a '--headless --config baseUrl=http://localhost:8081/ --reporter mocha-junit-reporter --reporter-options mochaFile=junit/test-results-[hash].xml --spec "cypress/e2e/**/*.cy.ts'

config file:

before_script:
  - npm install --save-dev cypress
  - npm install --save-dev junit-merge
  - npm install --save-dev cypress-split
  - npm install mocha-junit-reporter --save-dev
  - npm install cypress-multi-reporters --save-dev
  - npm install --prefer-offline --legacy-peer-deps
  - npm run dev &
  - Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
  - export DISPLAY=:99
  - |
    while ! curl -s http://localhost:8081/queue >/dev/null; do
      echo "Waiting for site to be up..."
      sleep 5
    done

test:
  stage: test
  image: cypress/browsers:node18.12.0-chrome107
  variables:
    npm_config_cache: "$CI_PROJECT_DIR/.npm"
    CYPRESS_CACHE_FOLDER: "$CI_PROJECT_DIR/cache/Cypress"
    MAX_BROWSERS: "3"
  cache:
    key: ${CI_COMMIT_REF_SLUG}
    paths:
      - .npm
      - cache/Cypress
      - node_modules
  script:
npx cypress-parallel -s test -t 1 -d 'cypress/e2e/**/*.cy.ts' -a '--headless --config baseUrl=http://localhost:8081/ --reporter mocha-junit-reporter --reporter-options mochaFile=junit/test-results-[hash].xml --spec "cypress/e2e/**/*.cy.ts'

#  - npx cypress run --headless --config baseUrl=http://localhost:8081/ --reporter mocha-junit-reporter --reporter-options mochaFile=junit/test-results-[hash].xml --spec "cypress/e2e/**/*.cy.ts"
  artifacts:
    paths:
      - cypress/videos/
      - cypress/screenshots/
      - junit/test-results-*.xml
      - junit/test-results.html
      - cypress/e2e/screenshots
      - cypress/results/
    reports:
      junit: junit/test-results-*.xml
    expire_in: 2 days
    when: always
  after_script:
    - junit-merge junit/test-results-*.xml junit/test-results-merged.xml

I’ve checked my configuration file and everything seems to be in order. I’m able to runt the tests using normal cypress run command. I have issues with parallel run. Also i noticed that even normal cypress run fails at random.

Any help or suggestions would be greatly appreciated. Thank you in advance