Skip to content

Commit

Permalink
feat: add index starting with 1 support (#124)
Browse files Browse the repository at this point in the history
* feat: add index 1 support

* add CI job

* debug message
  • Loading branch information
bahmutov committed Oct 12, 2023
1 parent f7c9125 commit 068a1df
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,24 @@ jobs:
component: true
n: 2

# using SPLIT_INDEX1 to start index at 1
test-index1:
runs-on: ubuntu-22.04
steps:
- name: Checkout 🛎
uses: actions/checkout@v4

- name: Run split Cypress E2E tests 🧪
# https://github.com/cypress-io/github-action
uses: cypress-io/github-action@v5
# using operating system process environment variables
env:
SPEC: 'cypress/e2e/spec-b.cy.js,cypress/e2e/spec-e.cy.js'
SPLIT: 2
# should run the first spec "spec-b" in the list
SPLIT_INDEX1: 1
DEBUG: 'cypress-split'

release:
if: github.ref == 'refs/heads/main'
needs:
Expand All @@ -154,6 +172,7 @@ jobs:
test-no-summary,
test-user-spec-list,
test-subfolder,
test-index1,
]
runs-on: ubuntu-22.04
steps:
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ job2: npx cypress run --env split=3,splitIndex=1
job3: npx cypress run --env split=3,splitIndex=2
```

### Index starts at 1

Some CIs provide an agent index that already starts at 1. You can pass it via `SPLIT_INDEX1` instead of `SPLIT_INDEX`

```
job1: SPLIT=3 SPLIT_INDEX1=1 npx cypress run
```

## CI summary

To skip GitHub Actions summary, set an environment variable `SPLIT_SUMMARY=false`. By default, this plugin generates the summary.
Expand Down
14 changes: 14 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ function cypressSplit(on, config) {

let SPLIT = process.env.SPLIT || config.env.split || config.env.SPLIT
let SPLIT_INDEX = process.env.SPLIT_INDEX || config.env.splitIndex

// some CI systems like TeamCity provide agent index starting with 1
// let's check for SPLIT_INDEX1 and if it is set,
// use it instead of zero-based SPLIT_INDEX
if (process.env.SPLIT_INDEX1 || config.env.splitIndex) {
const indexOne = process.env.SPLIT_INDEX1 || config.env.splitIndex
SPLIT_INDEX = Number(indexOne) - 1
debug(
'set SPLIT_INDEX to %d from index starting with 1 "%s"',
SPLIT_INDEX,
indexOne,
)
}

// potentially a list of files to run / split
let SPEC = process.env.SPEC || config.env.spec || config.env.SPEC
let specs
Expand Down

0 comments on commit 068a1df

Please sign in to comment.