cypresscirclecicircleci-workflowscircleci-orb

How can we group Cypress specs using tags and run groups in parallel on CircleCI?


Suppose I have the following it blocks. I have added some tags to group the tests. I need to run all the specs having "Group1" tag on one machine. And those having "Group2" tag in the other machine. Basically, I need to run Group1 and Group2 in parallel.

The reason for grouping is, if I just enable --parallel, there are chances for running "Test1" and "Test3" in parallel. But it will fail due to some data dependency. So Test1 and Test3 should run in series. But Test1 and Test2 can be run in parallel.

    it("Test1", { tags: ["Parallel", "Group1"] }, () => {
      cy.log("Test1");
    });
    
    it("Test2", { tags: ["Parallel", "Group2"] }, () => {
      cy.log("Test2");
    });
    
    it("Test3", { tags: ["Parallel", "Group1"] }, () => {
      cy.log("Test3");
    });
    
    it("Test4", { tags: ["Parallel", "Group2"] }, () => {
      cy.log("Test4");
    });

Expected Behavior

Parallel: 2
Machine 1: Run All specs in Group1 in series
Machine 2: Run All specs in Group2 in series

Current circle.yml

version: 2

workflows:
  version: 2

jobs:
  cypress-ci:
    parallelism: 1
    docker:
      - image: "cypress/included:10.0.0"
    working_directory: ~/app
    steps:
      - checkout
      - restore_cache:
          keys:
            - node-deps-v1-{{ .Branch }}-{{ checksum "cypress-tests/yarn.lock" }}
      - run:
          name: Install Packages
          command: |
            cd cypress-tests
            npm install --legacy-peer-deps
      - save_cache:
          key: node-deps-v1-{{ .Branch }}-{{ checksum "cypress-tests/yarn.lock" }}
          paths:
            - ~/cypress-tests/.npm
      - run:
          name: Execute cypress
          command: |
            cd cypress-tests
            npm run --env grepTags="Parallel" --RECORD_KEY=${RECORD_KEY}

Can someone help me to update the circle.yml file to get the expected behaviour?


Solution

  • You should create a job for each group (see this example) and filter the run by the given group tag.

    So something like this:

      group-1:
        steps:
          ...
          - run: npm run --group group-1 --tags Group1
    
      group-2:
        steps:
          ...
          - run: npm run --group group-2 --tags Group2