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

Commit 1a2bd34

Browse files
pmweeks98Pádraig Weeks
andauthored
feat: Add support for explicit not tags (#122)
* Add support for explicit not tags * Add integration tests * Add omit integration test * Add readme for not tags Co-authored-by: Pádraig Weeks <Padraig.Weeks1@ibm.com>
1 parent 0b94dcd commit 1a2bd34

File tree

7 files changed

+85
-1
lines changed

7 files changed

+85
-1
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,20 @@ jobs:
412412
--env grepTags="@sanity+@screen-b" \
413413
--expect-exactly expects/inherits-tag-spec.json
414414
415+
- name : explicit not tags prevent test from running
416+
run: |
417+
npx cypress-expect \
418+
--config testFiles="**/explicit-spec.js" \
419+
--env grepTags="@tag1 --@tag2" \
420+
--expect-exactly expects/explicit-spec.json
421+
422+
- name : explicit not tags work with omitFiltered
423+
run: |
424+
npx cypress-expect \
425+
--config testFiles="**/explicit-spec.js" \
426+
--env grepTags="@tag1 --@tag2",grepOmitFiltered=true \
427+
--expect-exactly expects/explicit-omit-spec.json
428+
415429
release:
416430
needs: [tests1, tests2, tests3]
417431
runs-on: ubuntu-20.04

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,24 @@ You can run tests that match one tag or another using spaces. Make sure to quote
361361
--env grepTags='@slow @critical'
362362
```
363363

364+
### NOT tags
365+
366+
You can skip running the tests with specific tag, even if they have a tag that should run, using the not option: prefix the tag with `--`.
367+
368+
Note this is the same as appending `+-<tag to never run>` to each tag. May be useful with large number of tags.
369+
370+
If you want to run tests with tags `@slow` or `@regression` but without tag `@smoke`
371+
372+
```
373+
--env grepTags='@slow @regression --@smoke'
374+
```
375+
376+
which is equivalent to
377+
378+
```
379+
--env grepTags='@slow+-@smoke @regression+-@smoke'
380+
```
381+
364382
## Burn
365383

366384
You can repeat (burn) the filtered tests to make sure they are flake-free

cypress/integration/explicit-spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// <reference types="cypress" />
2+
3+
it('tag1', {tags: '@tag1'}, () => {});
4+
5+
it('tag2', {tags: '@tag2'}, () => {});
6+
7+
it('tag3', {tags: '@tag3'}, () => {});
8+
9+
it('tag1 and 2', {tags: ['@tag1','@tag2']}, () => {});
10+
11+
it('tag1 and 3', {tags: ['@tag1', '@tag3']}, () => {})
12+
13+
it('tag2 and 3', {tags: ['@tag2', '@tag3']}, () => {})
14+
15+
it('all tags', {tags: ['@tag1', '@tag2', '@tag3']}, () => {});

cypress/integration/unit.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ describe('utils', () => {
153153
],
154154
])
155155
})
156+
157+
it('filters out explicit not tags', () => {
158+
const parsed = parseTagsGrep('@tag1 --@tag2 -@tag3')
159+
expect(parsed).to.deep.equal([
160+
[{ tag: '@tag1', invert: false }, { tag: '@tag2', invert: true }],
161+
[{ tag: '@tag3', invert: true }, { tag: '@tag2', invert: true }],
162+
])
163+
})
156164
})
157165

158166
context('parseGrep', () => {

expects/explicit-omit-spec.json

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

expects/explicit-spec.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"tag1": "passed",
3+
"tag2": "pending",
4+
"tag3": "pending",
5+
"tag1 and 2": "pending",
6+
"tag1 and 3": "passed",
7+
"tag2 and 3": "pending",
8+
"all tags": "pending"
9+
}

src/utils.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,22 @@ function parseTagsGrep(s) {
4343
return []
4444
}
4545

46+
const explicitNotTags = []
47+
4648
// top level split - using space or comma, each part is OR
4749
const ORS = s
4850
.split(/[ ,]/)
4951
// remove any empty tags
5052
.filter(Boolean)
5153
.map((part) => {
5254
// now every part is an AND
55+
if (part.startsWith('--')) {
56+
explicitNotTags.push({
57+
tag: part.slice(2),
58+
invert: true,
59+
})
60+
return
61+
}
5362
const parsed = part.split('+').map((tag) => {
5463
if (tag.startsWith('-')) {
5564
return {
@@ -67,7 +76,14 @@ function parseTagsGrep(s) {
6776
return parsed
6877
})
6978

70-
return ORS
79+
// filter out undefined from explicit not tags
80+
const ORS_filtered = ORS.filter(x => x !==undefined)
81+
if(explicitNotTags.length > 0 ){
82+
ORS_filtered.forEach((OR, index) => {
83+
ORS_filtered[index] = OR.concat(explicitNotTags)
84+
})
85+
}
86+
return ORS_filtered
7187
}
7288

7389
function shouldTestRunTags(parsedGrepTags, tags = []) {

0 commit comments

Comments
 (0)