@bahmutov/cy-grep 1.9.16 → 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.14.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)
@@ -145,6 +146,19 @@ module.exports = defineConfig({
145
146
  })
146
147
  ```
147
148
 
149
+ Trying to call the plugin function without any arguments or with more than a single argument throws an error
150
+
151
+ ```js
152
+ // ERROR: forgot the config file
153
+ setupNodeEvents(on, config) {
154
+ require('@bahmutov/cy-grep/src/plugin')();
155
+ }
156
+ // ERROR: too many arguments
157
+ setupNodeEvents(on, config) {
158
+ require('@bahmutov/cy-grep/src/plugin')(on, config);
159
+ }
160
+ ```
161
+
148
162
  ### Install in Cypress versions before 10
149
163
 
150
164
  See [test-cy-v9](./test-cy-v9/) for example
@@ -394,6 +408,22 @@ Sometimes you want to run only the tests without any tags, and these tests are i
394
408
  $ npx cypress run --env grepUntagged=true
395
409
  ```
396
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
+
397
427
  ## Pre-filter specs (grepFilterSpecs)
398
428
 
399
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.
@@ -695,6 +725,7 @@ To see how to debug this plugin, watch the video [Debug cypress-grep Plugin](htt
695
725
  - [cypress-select-tests](https://github.com/bahmutov/cypress-select-tests)
696
726
  - [cypress-skip-test](https://github.com/cypress-io/cypress-skip-test)
697
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)
698
729
 
699
730
  ## cy-grep vs cypress-grep vs @cypress/grep
700
731
 
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@bahmutov/cy-grep",
3
- "version": "1.9.16",
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",
@@ -14,17 +15,17 @@
14
15
  "dependencies": {
15
16
  "cypress-plugin-config": "^1.2.0",
16
17
  "debug": "^4.3.2",
17
- "find-cypress-specs": "^1.29.4",
18
- "find-test-names": "1.28.12"
18
+ "find-cypress-specs": "^1.35.1",
19
+ "find-test-names": "1.28.21"
19
20
  },
20
21
  "devDependencies": {
21
- "cypress": "12.14.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.0.5",
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/plugin.js CHANGED
@@ -68,6 +68,17 @@ function getGrepSettings(config) {
68
68
  * @param {Cypress.ConfigOptions} config
69
69
  */
70
70
  function cypressGrepPlugin(config) {
71
+ if (arguments.length === 0) {
72
+ throw new Error(
73
+ 'ERROR: forgot the config file, see https://github.com/bahmutov/cy-grep',
74
+ )
75
+ }
76
+ if (arguments.length > 1) {
77
+ throw new Error(
78
+ 'ERROR: too many arguments, see https://github.com/bahmutov/cy-grep',
79
+ )
80
+ }
81
+
71
82
  if (!config || !config.env) {
72
83
  return config
73
84
  }
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,