bahmutov / cypress-split

Split Cypress specs across parallel CI machines for speed
MIT License
212 stars 24 forks source link

All tests are running in each job instead of proper chunks (config returned in config.js file) #313

Closed piozaj closed 2 months ago

piozaj commented 2 months ago

Issue: While running tests on Github Actions I noticed that instead running tests for each chunk in each job it runs all of tests. Logs shows that chunks are properly divided and split index is different for each job. I'm returning config as in docs:

Screenshot 2024-08-02 at 7 16 17 PM

(return should be probably moved after all defined tasks, but anyway it should at least start testing chunks). Cypress version: 13.8.1

Part of log output:

Split 1

Screenshot 2024-08-02 at 1 21 06 PM

Split 2

Screenshot 2024-08-02 at 1 20 34 PM

Here's my yml file:

name: E2E Cypress Tests Develop - Parallel

on:
  workflow_dispatch:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  setup:
    environment:
      name: non-production
      url: ${{ steps.set_environment_related_parameters.outputs.url }}
    runs-on: ubuntu-latest
    steps:
      # Wait for new version of app to be up and running
      - name: Sleep for 1 minute
        run: sleep 60s
        shell: bash

      - name: Checkout code
        uses: actions/checkout@v4
        with:
          repository: "Sample repository name"
          token: ${{ secrets.ACCESS_TOKEN }}
          ref: main

      - name: Setup gmail tester credentials
        run: echo '${{ secrets.E2E_DEV_GMAIL_TESTER_CREDENTIALS_JSON }}' > credentials.json

      - name: Setup gmail tester token
        run: echo '${{ secrets.E2E_DEV_GMAIL_TESTER_TOKEN_JSON }}' > token.json

      - name: Setup nodemailer env
        run: echo "${{ secrets.E2E_DEV_NODEMAILER_ENV }}" >> .env

  prepare:
    environment:
      name: non-production
      url: ${{ steps.set_environment_related_parameters.outputs.url }}
    runs-on: ubuntu-latest
    # explicitly set the output of this job
    # so that other jobs can use it
    outputs:
      matrix: ${{ steps.prepare.outputs.matrix }}
    steps:
      # generate the list using a bash script
      - name: Create matrix ⊹
        id: prepare
        # for reusable workflow, must use the full action reference
        uses: bahmutov/gh-build-matrix@main
        with:
          n: 4 # number of containers to output

      - name: Print result 🖨
        run: echo '${{ steps.prepare.outputs.matrix }}'

  test-split:
    environment:
      name: non-production
      url: ${{ steps.set_environment_related_parameters.outputs.url }}
    needs: [setup, prepare]
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix: ${{ fromJSON(needs.prepare.outputs.matrix) }}
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        with:
          repository: "Sample repository name"
          token: ${{ secrets.ACCESS_TOKEN }}
          ref: main

      - name: Print GitHub variables 🖨
        run: npx @bahmutov/print-env GITHUB

      - name: Print GitHub strategy context 🖨
        run: echo '${{ toJSON(strategy) }}'

      - name: Run Cypress tests
        uses: cypress-io/github-action@v6
        with:
          config-file: cypress_config_CI.config.js
          browser: chrome
          record: false
        env:
          CYPRESS_PLAID_CLIENT_ID: ${{ secrets.E2E_DEV_PLAID_CLIENT_ID }}
          CYPRESS_PLAID_SECRET: ${{ secrets.E2E_DEV_PLAID_SECRET }}
          CYPRESS_AUTH0_USERNAME: ${{ secrets.E2E_DEV_AUTH0_USERNAME }}
          CYPRESS_AUTH0_PASSWORD: ${{ secrets.E2E_DEV_AUTH0_PASSWORD }}
          CYPRESS_AUTH0_AUDIENCE: ${{ secrets.E2E_DEV_AUTH0_AUDIENCE }}
          CYPRESS_AUTH0_CONNECTION: ${{ secrets.E2E_DEV_AUTH0_CONNECTION }}
          CYPRESS_AUTH0_URL: ${{ secrets.E2E_DEV_AUTH0_URL }}
          CYPRESS_AUTH0_CLIENT_ID: ${{ secrets.E2E_DEV_AUTH0_CLIENT_ID }}
          CYPRESS_AUTH0_CLIENT_SECRET: ${{ secrets.E2E_DEV_AUTH0_CLIENT_SECRET }}
          CYPRESS_MAILOSAUR_API_KEY: ${{ secrets.E2E_DEV_MAILOSAUR_API_KEY }}
          CYPRESS_MAILOSAUR_SERVER_ID: ${{ secrets.E2E_DEV_MAILOSAUR_SERVER_ID }}
          CYPRESS_DB_SSH_PRIVATE_KEY: |
            ${{ secrets.E2E_DEV_DB_SSH_PRIVATE_KEY }}
          CYPRESS_DB_DST_ADDR: ${{ vars.E2E_DEV_DB_DST_ADDR }}
          CYPRESS_DB_PASSWORD: ${{ secrets.E2E_DEV_DB_PASSWORD }}
          CYPRESS_DB_DATABASE: ${{ vars.E2E_DEV_DB_DATABASE }}
          CYPRESS_RECORD_KEY: ${{ secrets.E2E_DEV_CYPRESS_RECORD_KEY }}
          CYPRESS_STRIPE_SK: ${{ vars.E2E_DEV_STRIPE_SK }}
          CYPRESS_STRIPE_BASIC_PLAN_PRICE_ID: ${{ vars.E2E_DEV_STRIPE_BASIC_PLAN_ID }}
          CYPRESS_STRIPE_PLUS_PLAN_PRICE_ID: ${{ vars.E2E_DEV_STRIPE_PLUS_PLAN_ID }}
          CYPRESS_STRIPE_ENTERPRISE_PLAN_PRICE_ID: ${{ vars.E2E_DEV_STRIPE_ENTERPRISE_PLAN_ID }}
          SPLIT: ${{ strategy.job-total }}
          SPLIT_INDEX: ${{ strategy.job-index }}
          DEBUG: cypress-split

  save-artifacts-on-failure:
    environment:
      name: non-production
      url: ${{ steps.set_environment_related_parameters.outputs.url }}
    needs: test-split
    runs-on: ubuntu-latest
    if: failure()
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Save screenshots on failure
        uses: actions/upload-artifact@v4
        with:
          name: cypress-screenshots
          path: cypress/screenshots

      - name: Save videos on failure
        uses: actions/upload-artifact@v4
        with:
          name: cypress-videos
          path: cypress/videos

  notify:
    environment:
      name: non-production
      url: ${{ steps.set_environment_related_parameters.outputs.url }}
    needs: [setup, test-split]
    runs-on: ubuntu-latest
    steps:
      - name: Send slack failure notification
        if: failure()
        uses: rtCamp/action-slack-notify@v2
        env:
          SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
          SLACK_COLOR: ${{ job.status }}
          SLACK_MESSAGE: "E2E Tests Failed. See details: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
          SLACK_USERNAME: "Cypress E2E Tests"

      - name: Send slack success notification
        if: success()
        uses: rtCamp/action-slack-notify@v2
        env:
          SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
          SLACK_COLOR: ${{ job.status }}
          SLACK_MESSAGE: "E2E Tests Passed. See details: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
          SLACK_USERNAME: "Cypress E2E Tests"
piozaj commented 2 months ago

After moving return to the end of setupNodeEvents it works as expected