Skip to content
This repository was archived by the owner on Mar 29, 2023. It is now read-only.

Commit 8cdc686

Browse files
authored
feat: add option to omit all filtered tests (#84)
* add failing test for omitted tests * feat: add variable to omit filtered tests
1 parent d6cd15a commit 8cdc686

File tree

7 files changed

+61
-3
lines changed

7 files changed

+61
-3
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,15 @@ jobs:
185185
--env grep="works 2" \
186186
--expect-exactly expects/specify.json
187187
188+
# instead of making filtered tests pending
189+
# with it.skip, completely omit them
190+
- name: Omit filtered tests 🧪
191+
run: |
192+
npx cypress-expect \
193+
--spec cypress/integration/spec.js \
194+
--env grep="works 2",grepOmitFiltered=true \
195+
--expect-exactly expects/omit-filtered.json
196+
188197
tests3:
189198
runs-on: ubuntu-20.04
190199
needs: install

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,36 @@ Note 3: if there are no files remaining after filtering, the plugin prints a war
217217
}
218218
```
219219

220+
### omit filtered tests
221+
222+
By default, all filtered tests are made _pending_ using `it.skip` method. If you want to completely omit them, pass the environment variable `grepOmitFiltered=true`.
223+
224+
Pending filtered tests
225+
226+
```
227+
cypress run --env grep="works 2"
228+
```
229+
230+
![Pending tests](./images/includes-pending.png)
231+
232+
Omit filtered tests
233+
234+
```
235+
cypress run --env grep="works 2",grepOmitFiltered=true
236+
```
237+
238+
![Only running tests remaining](./images/omit-pending.png)
239+
240+
**Tip:** you can set this environment variable in the `cypress.json` file to enable it by default and skip using the environment variable:
241+
242+
```json
243+
{
244+
"env": {
245+
"grepOmitFiltered": true
246+
}
247+
}
248+
```
249+
220250
### grep untagged tests
221251

222252
Sometimes you want to run only the tests without any tags, and these tests are inside the describe blocks without any tags.

expects/omit-filtered.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"works 2 @tag1": "passed",
3+
"works 2 @tag1 @tag2": "passed"
4+
}

images/includes-pending.png

62.7 KB
Loading

images/omit-pending.png

45.5 KB
Loading

src/plugin.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ function cypressGrepPlugin(config) {
3535
console.log('cypress-grep: running untagged tests')
3636
}
3737

38+
const omitFiltered =
39+
config.env.grepOmitFiltered || config.env['grep-omit-filtered']
40+
if (omitFiltered) {
41+
console.log('cypress-grep: will omit filtered tests')
42+
}
43+
3844
const grepFilterSpecs = config.env.grepFilterSpecs === true
3945
if (grepFilterSpecs) {
4046
if (grep) {

src/support.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ function cypressGrep() {
4242
Cypress.env('burn') ||
4343
1
4444

45-
debug('grep %o', { grep, grepTags, grepBurn })
45+
/** @type {boolean} Omit filtered tests completely */
46+
const omitFiltered =
47+
Cypress.env('grepOmitFiltered') || Cypress.env('grep-omit-filtered')
48+
49+
debug('grep %o', { grep, grepTags, grepBurn, omitFiltered })
4650
if (!Cypress._.isInteger(grepBurn) || grepBurn < 1) {
4751
throw new Error(`Invalid grep burn value: ${grepBurn}`)
4852
}
@@ -112,8 +116,13 @@ function cypressGrep() {
112116
return _it(name, options, callback)
113117
}
114118

115-
// skip tests without grep string in their names
116-
return _it.skip(name, options, callback)
119+
if (omitFiltered) {
120+
// omit the filtered tests completely
121+
return
122+
} else {
123+
// skip tests without grep string in their names
124+
return _it.skip(name, options, callback)
125+
}
117126
}
118127

119128
// list of "describe" suites for the current test

0 commit comments

Comments
 (0)