Skip to content

Commit

Permalink
test SPEC wildcards (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov authored Apr 9, 2024
1 parent e166a56 commit 57e148c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,29 @@ jobs:
SPLIT_INDEX: ${{ strategy.job-index }}
DEBUG: 'cypress-split'

test-spec-wildcard:
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
containers: [1, 2]
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@v6
with:
build: npm run demo-preview-spec
# using operating system process environment variables
env:
# confirm we can use wildcards in the SPEC list
SPEC: 'cypress/e2e/spec-*.cy.js, cypress/e2e/spec-*.cy.js'
SPLIT: ${{ strategy.job-total }}
SPLIT_INDEX: ${{ strategy.job-index }}
DEBUG: 'cypress-split'

test-subfolder:
runs-on: ubuntu-22.04
steps:
Expand Down Expand Up @@ -322,6 +345,7 @@ jobs:
test-pending-tests,
test-merge-timings,
test-find-timings-file,
test-spec-wildcard,
preview,
]
runs-on: ubuntu-22.04
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,12 @@ $ npx cypress run --env split=2,splitIndex=1,spec="spec1,spec2,spec3"
$ npx cypress run --env split=true,spec="spec1,spec2,spec3"
```

Inside the `SPEC=....` value you can use wildcards, for example to run all specs inside a subfolder

```
$ SPEC="cypress/e2e/featureA/*.cy.js" npx cypress run --spec "cypress/e2e/featureA/*.cy.js"
```

**Important:** if you are passing the list of specs using `--env spec="..."` and get the error `Cannot parse as valid JSON`, switch to using `SPEC` environment variable, see [#79](https://github.com/bahmutov/cypress-split/issues/79).

```
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"timings-split-output-file": "DEBUG=cypress-split SPLIT=2 SPLIT_INDEX=0 SPLIT_OUTPUT_FILE=new-timings.json SPLIT_FILE=timings.json cypress run",
"demo-merge": "node ./bin/merge --parent-folder examples/split-times --split-file timings.json --output out-timings.json",
"demo-preview": "node ./bin/preview --split 2",
"demo-preview-spec": "SPEC=\"cypress/e2e/spec*.cy.js\" node ./bin/preview --split 2",
"unit": "ava test/*.test.js",
"unit:watch": "ava --watch test/*.test.js"
},
Expand Down
6 changes: 6 additions & 0 deletions src/parse-inputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ function getSpecsToSplit(env = {}, config) {
return path.resolve(specFilename)
})
// all resolved absolute spec filenames
debug(
'resolving %d specs "%s"',
possiblePatterns.length,
possiblePatterns.join(','),
)

const specs = []
possiblePatterns.forEach((pattern) => {
if (pattern.includes('*')) {
Expand Down

0 comments on commit 57e148c

Please sign in to comment.