@bahmutov/cy-grep 3.0.1 → 3.0.2

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.
Files changed (2) hide show
  1. package/package.json +5 -3
  2. package/src/support.js +30 -1
package/package.json CHANGED
@@ -1,16 +1,18 @@
1
1
  {
2
2
  "name": "@bahmutov/cy-grep",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "Filter Cypress tests using title or tags",
5
5
  "main": "src/support.js",
6
6
  "scripts": {
7
+ "dev": "cypress open --e2e -b electron",
7
8
  "cy:run": "cypress run --config specPattern='**/unit.js'",
8
9
  "cy:open": "cypress open --e2e -b electron --config specPattern='**/unit.js'",
9
10
  "cy:open:tags": "cypress open --e2e -b electron --config specPattern='cypress/e2e/test-tags/*.cy.js'",
10
11
  "badges": "npx -p dependency-version-badge update-badge cypress",
11
12
  "semantic-release": "semantic-release",
12
13
  "deps": "npm audit --report --omit dev",
13
- "stop-only": "stop-only --folder cypress/e2e"
14
+ "stop-only": "stop-only --folder cypress/e2e --exclude cypress/e2e/only/check-only.cy.js",
15
+ "open:check-only": "cypress open --e2e -b electron --config specPattern='cypress/e2e/only/check-only.cy.js' --expose grepFilterSpecs=true,grepOmitFiltered=true,grepTags=@one"
14
16
  },
15
17
  "dependencies": {
16
18
  "cypress-plugin-config": "^2.0.0",
@@ -25,7 +27,7 @@
25
27
  "cypress-expect": "^3.1.0",
26
28
  "prettier": "^3.8.1",
27
29
  "semantic-release": "^25.0.3",
28
- "stop-only": "^3.3.1",
30
+ "stop-only": "^3.4.4",
29
31
  "typescript": "^5.9.3"
30
32
  },
31
33
  "peerDependencies": {
package/src/support.js CHANGED
@@ -110,6 +110,16 @@ function registerCyGrep() {
110
110
  return
111
111
  }
112
112
 
113
+ // global state :(
114
+ // when using "it.only" it calls via internal Mocha functions our "it"
115
+ // BUT without passing test tags or test config -
116
+ // thus our "it" function thinks there are no effective tags to use
117
+ // against the current grep, so it skips the "it.only" test.
118
+ // we want the opposite: any "it.only" test should run
119
+ // thus we set this global flag from our "it.only" before
120
+ // Cypress/Mocha calls our "it" and we know to run the test without checking the tags
121
+ let insideItOnly = false
122
+
113
123
  it = function itGrep(name, options, callback) {
114
124
  if (typeof options === 'function') {
115
125
  // the test has format it('...', cb)
@@ -122,6 +132,11 @@ function registerCyGrep() {
122
132
  return _it(name, options)
123
133
  }
124
134
 
135
+ if (insideItOnly) {
136
+ insideItOnly = false
137
+ return _it(name, callback)
138
+ }
139
+
125
140
  let configTags = options && options.tags
126
141
  if (typeof configTags === 'string') {
127
142
  configTags = [configTags]
@@ -196,6 +211,7 @@ function registerCyGrep() {
196
211
  // omit the filtered tests completely
197
212
  // in order to be compatible with Mocha, create fake method and test object
198
213
  return {
214
+ markOnly: () => {},
199
215
  parent: {
200
216
  appendOnlyTest: () => {},
201
217
  },
@@ -273,7 +289,20 @@ function registerCyGrep() {
273
289
 
274
290
  // keep the ".skip", ".only" methods the same as before
275
291
  it.skip = _it.skip
276
- it.only = _it.only
292
+
293
+ const _itOnly = _it.only
294
+ it.only = function itGrep(name, options, callback) {
295
+ insideItOnly = true
296
+ if (typeof options === 'function') {
297
+ // the test has format it('...', cb)
298
+ callback = options
299
+ options = {}
300
+ }
301
+
302
+ debugger
303
+ return _itOnly(name, options, callback)
304
+ }
305
+
277
306
  // preserve "it.each" method if found
278
307
  if (typeof _it.each === 'function') {
279
308
  it.each = _it.each