@bahmutov/cy-grep 1.9.17 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @bahmutov/cy-grep ![cypress version](https://img.shields.io/badge/cypress-12.15.0-brightgreen)
1
+ # @bahmutov/cy-grep ![cypress version](https://img.shields.io/badge/cypress-13.1.0-brightgreen)
2
2
 
3
3
  > Filter tests using substring or tag
4
4
 
@@ -55,6 +55,7 @@ Watch the video [intro to cypress-grep plugin](https://www.youtube.com/watch?v=H
55
55
  - [NOT tags](#not-tags)
56
56
  - [Tags in test suites](#tags-in-test-suites)
57
57
  - [Grep untagged tests](#grep-untagged-tests)
58
+ - [Access the tags in the test](#access-the-tags-in-the-test)
58
59
  - [Pre-filter specs (grepFilterSpecs)](#pre-filter-specs-grepfilterspecs)
59
60
  - [Omit filtered tests (grepOmitFiltered)](#omit-filtered-tests-grepomitfiltered)
60
61
  - [Disable grep](#disable-grep)
@@ -407,6 +408,22 @@ Sometimes you want to run only the tests without any tags, and these tests are i
407
408
  $ npx cypress run --env grepUntagged=true
408
409
  ```
409
410
 
411
+ ### Access the tags in the test
412
+
413
+ You can check the current test's tags (including its parent suites) by checking the `Cypress.env('testTags')` list
414
+
415
+ ```js
416
+ describe('parent', { tags: ['@p1', '@p2'] }, () => {
417
+ describe('child', { tags: '@c1' }, () => {
418
+ it('has all effective test tags', { tags: '@t1' }, () => {
419
+ const tags = Cypress.env('testTags')
420
+ // includes tags from the parent suites and the test itself
421
+ expect(tags, 'tags').to.deep.equal(['@p1', '@p2', '@c1', '@t1'])
422
+ })
423
+ })
424
+ })
425
+ ```
426
+
410
427
  ## Pre-filter specs (grepFilterSpecs)
411
428
 
412
429
  By default, when using `grep` and `grepTags` all specs are executed, and inside each the filters are applied. This can be very wasteful, if only a few specs contain the `grep` in the test titles. Thus when doing the positive `grep`, you can pre-filter specs using the `grepFilterSpecs=true` parameter.
@@ -708,6 +725,7 @@ To see how to debug this plugin, watch the video [Debug cypress-grep Plugin](htt
708
725
  - [cypress-select-tests](https://github.com/bahmutov/cypress-select-tests)
709
726
  - [cypress-skip-test](https://github.com/cypress-io/cypress-skip-test)
710
727
  - 📝 Read the blog post [Cypress GitHub Actions Slash Command](https://glebbahmutov.com/blog/cypress-slash-command/)
728
+ - plugin [dennisbergevin/cypress-plugin-last-failed](https://github.com/dennisbergevin/cypress-plugin-last-failed)
711
729
 
712
730
  ## cy-grep vs cypress-grep vs @cypress/grep
713
731
 
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@bahmutov/cy-grep",
3
- "version": "1.9.17",
3
+ "version": "1.10.0",
4
4
  "description": "Filter Cypress tests using title or tags",
5
5
  "main": "src/support.js",
6
6
  "scripts": {
7
7
  "cy:run": "cypress run --config specPattern='**/unit.js'",
8
8
  "cy:open": "cypress open --e2e -b electron --config specPattern='**/unit.js'",
9
+ "cy:open:tags": "cypress open --e2e -b electron --config specPattern='cypress/e2e/test-tags/*.cy.js'",
9
10
  "badges": "npx -p dependency-version-badge update-badge cypress",
10
11
  "semantic-release": "semantic-release",
11
12
  "deps": "npm audit --report --omit dev",
@@ -15,16 +16,16 @@
15
16
  "cypress-plugin-config": "^1.2.0",
16
17
  "debug": "^4.3.2",
17
18
  "find-cypress-specs": "^1.35.1",
18
- "find-test-names": "1.28.13"
19
+ "find-test-names": "1.28.21"
19
20
  },
20
21
  "devDependencies": {
21
- "cypress": "13.1.0",
22
+ "cypress": "13.11.0",
22
23
  "cypress-each": "^1.11.0",
23
24
  "cypress-expect": "^3.1.0",
24
- "prettier": "^2.8.1",
25
- "semantic-release": "^21.1.1",
25
+ "prettier": "^3.0.0",
26
+ "semantic-release": "^24.0.0",
26
27
  "stop-only": "^3.3.1",
27
- "typescript": "^4.7.4"
28
+ "typescript": "^5.0.0"
28
29
  },
29
30
  "peerDependencies": {
30
31
  "cypress": ">=8"
package/src/support.js CHANGED
@@ -16,6 +16,22 @@ debug.log = console.info.bind(console)
16
16
  // preserve the real "it" function
17
17
  const _it = it
18
18
  const _describe = describe
19
+ // keeps all collected test tags by the full test title
20
+ // includes both the test tags and the suite tags
21
+ // and the required test tags
22
+ const testTree = {}
23
+
24
+ beforeEach(() => {
25
+ // set the test tags for the current test
26
+ const testTitle = Cypress.currentTest.titlePath.join(' ')
27
+ const info = testTree[testTitle]
28
+ if (info) {
29
+ const allTags = info.effectiveTestTags.concat(info.requiredTestTags)
30
+ Cypress.env('testTags', allTags)
31
+ } else {
32
+ Cypress.env('testTags', null)
33
+ }
34
+ })
19
35
 
20
36
  /**
21
37
  * Wraps the "it" and "describe" functions that support tags.
@@ -122,6 +138,7 @@ function registerCyGrep() {
122
138
  .concat(configRequiredTags)
123
139
  .filter(Boolean)
124
140
  debug({ nameToGrep, effectiveTestTags, requiredTestTags })
141
+ testTree[nameToGrep] = { effectiveTestTags, requiredTestTags }
125
142
 
126
143
  const shouldRun = shouldTestRun(
127
144
  parsedGrep,