@bahmutov/cy-grep 1.1.0 → 1.2.1

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
@@ -19,7 +19,7 @@ All other tests will be marked pending, see why in the [Cypress test statuses](h
19
19
 
20
20
  If you have multiple spec files, all specs will be loaded, and every test will be filtered the same way, since the grep is run-time operation and cannot eliminate the spec files without loading them. If you want to run only specific tests, use the built-in [--spec](https://on.cypress.io/command-line#cypress-run-spec-lt-spec-gt) CLI argument.
21
21
 
22
- Watch the video [intro to cypress-grep plugin](https://www.youtube.com/watch?v=HS-Px-Sghd8)
22
+ Watch the video [intro to cypress-grep plugin](https://www.youtube.com/watch?v=HS-Px-Sghd8) and study my 🎓 Cypress course [Cypress Plugins](https://cypress.tips/courses/cypress-plugins).
23
23
 
24
24
  Table of Contents
25
25
 
@@ -56,9 +56,6 @@ Table of Contents
56
56
  - [Debugging in the browser](#debugging-in-the-browser)
57
57
  - [Examples](#examples)
58
58
  - [See also](#see-also)
59
- - [Migration guide](#migration-guide)
60
- - [from v1 to v2](#from-v1-to-v2)
61
- - [from v2 to v3](#from-v2-to-v3)
62
59
  - [Small Print](#small-print)
63
60
 
64
61
  <!-- /MarkdownTOC -->
@@ -81,7 +78,8 @@ yarn add -D @bahmutov/cy-grep
81
78
  **required:** load this module from the [support file](https://on.cypress.io/writing-and-organizing-tests#Support-file) or at the top of the spec file if not using the support file. You import the registration function and then call it:
82
79
 
83
80
  ```js
84
- // cypress/support/index.js
81
+ // cypress/support/e2e.js
82
+
85
83
  // load and register the grep feature using "require" function
86
84
  // https://github.com/bahmutov/cy-grep
87
85
  const registerCypressGrep = require('@bahmutov/cy-grep')
@@ -90,7 +88,7 @@ registerCypressGrep()
90
88
  // if you want to use the "import" keyword
91
89
  // note: `./index.d.ts` currently extends the global Cypress types and
92
90
  // does not define `registerCypressGrep` so the import path is directly
93
- // pointed to the `support.js` file
91
+ // pointed to the support file
94
92
  import registerCypressGrep from '@bahmutov/cy-grep/src/support'
95
93
  registerCypressGrep()
96
94
 
@@ -111,13 +109,14 @@ registerCypressGrep()
111
109
  e2e: {
112
110
  setupNodeEvents(on, config) {
113
111
  require('@bahmutov/cy-grep/src/plugin')(config);
112
+ // IMPORTANT: return the config object
114
113
  return config;
115
- },
114
+ },
116
115
  }
117
116
  }
118
117
  ```
119
118
 
120
- Installing the plugin via `setupNodeEvents()` is required to enable the [grepFilterSpecs](#grepfilterspecs) feature.
119
+ Installing the plugin via `setupNodeEvents()` is required to enable the [grepFilterSpecs](#pre-filter-specs-grepfilterspecs) feature.
121
120
 
122
121
  ## Usage Overview
123
122
 
@@ -215,8 +214,6 @@ $ npx cypress run --env grep="-hello world"
215
214
  $ npx cypress run --env grep="hello; -world"
216
215
  ```
217
216
 
218
- **Note:** Inverted title filter is not compatible with the `grepFilterSpecs` option
219
-
220
217
  ## Filter with tags
221
218
 
222
219
  You can select tests to run or skip using tags by passing `--env grepTags=...` value.
@@ -353,9 +350,12 @@ $ npx cypress run --env grepTags=@smoke,grepFilterSpecs=true
353
350
  **Tip:** you can set this environment variable in the [config file](https://docs.cypress.io/guides/references/configuration) file to enable it by default and skip using the environment variable:
354
351
 
355
352
  ```js
353
+ // config file
356
354
  {
357
- "env": {
358
- "grepFilterSpecs": true
355
+ "e2e": {
356
+ "env": {
357
+ "grepFilterSpecs": true
358
+ }
359
359
  }
360
360
  }
361
361
  ```
@@ -505,20 +505,23 @@ Once the tests finish, you can run just the failed tests from DevTools console
505
505
 
506
506
  **Tip:** use `Cypress.grep()` to reset and run all the tests
507
507
 
508
+ 📝 Read the blog post [Run Just The Failed Tests In Cypress](https://glebbahmutov.com/blog/run-failed-tests/).
509
+
508
510
  ## Debugging
509
511
 
510
- When debugging a problem, first make sure you are using the expected version of this plugin, as some features might be only available in the [later releases](https://github.com/cypress-io/cypress-grep/releases).
512
+ When debugging a problem, first make sure you are using the expected version of this plugin, as some features might be only available in the [later releases](https://github.com/bahmutov/cy-grep/releases).
511
513
 
512
514
  ```
513
- # get the cypress-grep version using NPM
514
- $ npm ls cypress-grep
515
+ # get the plugin's version using NPM
516
+ $ npm ls @bahmutov/cy-grep
515
517
  ...
516
- └── cypress-grep@2.10.1
517
- # get the cypress-grep version using Yarn
518
- $ yarn why cypress-grep
518
+ └── @bahmutov/cy-grep@1.1.0
519
+
520
+ # get the plugin's version using Yarn
521
+ $ yarn why @bahmutov/cy-grep
519
522
  ...
520
- => Found "cypress-grep@2.10.1"
521
- info Has been hoisted to "cypress-grep"
523
+ => Found "@bahmutov/cy-grep@1.1.0"
524
+ info Has been hoisted to "@bahmutov/cy-grep"
522
525
  info This module exists because it's specified in "devDependencies".
523
526
  ...
524
527
  ```
@@ -539,30 +542,28 @@ This module uses [debug](https://github.com/visionmedia/debug#readme) to log ver
539
542
 
540
543
  ### Debugging in the plugin
541
544
 
542
- Start Cypress with the environment variable `DEBUG=cypress-grep`. You will see a few messages from this plugin in the terminal output:
545
+ Start Cypress with the environment variable `DEBUG=cy-grep`. You will see a few messages from this plugin in the terminal output:
543
546
 
544
547
  ```
545
- $ DEBUG=cypress-grep npx cypress run --env grep=works,grepFilterSpecs=true
546
- cypress-grep: tests with "works" in their names
547
- cypress-grep: filtering specs using "works" in the title
548
- cypress-grep Cypress config env object: { grep: 'works', grepFilterSpecs: true }
548
+ $ DEBUG=cy-grep npx cypress run --env grep=works,grepFilterSpecs=true
549
+ cy-grep: tests with "works" in their names
550
+ cy-grep: filtering specs using "works" in the title
551
+ cy-grep Cypress config env object: { grep: 'works', grepFilterSpecs: true }
549
552
  ...
550
- cypress-grep found 1 spec files +5ms
551
- cypress-grep [ 'spec.js' ] +0ms
552
- cypress-grep spec file spec.js +5ms
553
- cypress-grep suite and test names: [ 'hello world', 'works', 'works 2 @tag1',
553
+ cy-grep found 1 spec files +5ms
554
+ cy-grep [ 'spec.js' ] +0ms
555
+ cy-grep spec file spec.js +5ms
556
+ cy-grep suite and test names: [ 'hello world', 'works', 'works 2 @tag1',
554
557
  'works 2 @tag1 @tag2', 'works @tag2' ] +0ms
555
- cypress-grep found "works" in 1 specs +0ms
556
- cypress-grep [ 'spec.js' ] +0ms
558
+ cy-grep found "works" in 1 specs +0ms
559
+ cy-grep [ 'spec.js' ] +0ms
557
560
  ```
558
561
 
559
562
  ### Debugging in the browser
560
563
 
561
- To enable debug console messages in the browser, from the DevTools console set `localStorage.debug='cypress-grep'` and run the tests again.
562
-
563
- ![Debug messages](./images/debug.png)
564
+ To enable debug console messages in the browser, from the DevTools console set `localStorage.debug='cy-grep'` and run the tests again.
564
565
 
565
- To see how to debug this plugin, watch the video [Debug cypress-grep Plugin](https://youtu.be/4YMAERddHYA).
566
+ To see how to debug this plugin, watch the video [Debug cypress-grep Plugin](https://youtu.be/4YMAERddHYA) but use the string `cy-grep`
566
567
 
567
568
  ## Examples
568
569
 
@@ -574,37 +575,6 @@ To see how to debug this plugin, watch the video [Debug cypress-grep Plugin](htt
574
575
  - [cypress-select-tests](https://github.com/bahmutov/cypress-select-tests)
575
576
  - [cypress-skip-test](https://github.com/cypress-io/cypress-skip-test)
576
577
 
577
- ## Migration guide
578
-
579
- ### from v1 to v2
580
-
581
- In v2 we have separated grepping by part of the title string from tags.
582
-
583
- **v1**
584
-
585
- ```
586
- --env grep="one two"
587
- ```
588
-
589
- The above scenario was confusing - did you want to find all tests with title containing "one two" or did you want to run tests tagged `one` or `two`?
590
-
591
- **v2**
592
-
593
- ```
594
- # enable the tests with string "one two" in their titles
595
- --env grep="one two"
596
- # enable the tests with tag "one" or "two"
597
- --env grepTags="one two"
598
- # enable the tests with both tags "one" and "two"
599
- --env grepTags="one+two"
600
- # enable the tests with "hello" in the title and tag "smoke"
601
- --env grep=hello,grepTags=smoke
602
- ```
603
-
604
- ### from v2 to v3
605
-
606
- Version >= 3 of cypress-grep _only_ supports Cypress >= 10.
607
-
608
578
  ## Small Print
609
579
 
610
580
  License: MIT - do anything with the code, but don't blame me if it does not work.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bahmutov/cy-grep",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Filter Cypress tests using title or tags",
5
5
  "main": "src/support.js",
6
6
  "scripts": {
@@ -12,15 +12,15 @@
12
12
  "dependencies": {
13
13
  "cypress-plugin-config": "^1.2.0",
14
14
  "debug": "^4.3.2",
15
- "find-test-names": "^1.22.2",
15
+ "find-test-names": "^1.23.0",
16
16
  "globby": "^11.0.4"
17
17
  },
18
18
  "devDependencies": {
19
- "cypress": "12.1.0",
19
+ "cypress": "12.3.0",
20
20
  "cypress-each": "^1.11.0",
21
21
  "cypress-expect": "^2.5.3",
22
22
  "prettier": "^2.8.1",
23
- "semantic-release": "^19.0.5",
23
+ "semantic-release": "^20.0.2",
24
24
  "typescript": "^4.7.4"
25
25
  },
26
26
  "peerDependencies": {
package/src/plugin.js CHANGED
@@ -1,15 +1,15 @@
1
- const debug = require('debug')('cypress-grep')
1
+ const debug = require('debug')('cy-grep')
2
2
  const globby = require('globby')
3
- const { getTestNames } = require('find-test-names')
3
+ const { getTestNames, findEffectiveTestTags } = require('find-test-names')
4
4
  const fs = require('fs')
5
5
  const { version } = require('../package.json')
6
6
  const { parseGrep, shouldTestRun } = require('./utils')
7
7
 
8
8
  /**
9
- * Prints the cypress-grep environment values if any.
9
+ * Prints the cy-grep environment values if any.
10
10
  * @param {Cypress.ConfigOptions} config
11
11
  */
12
- function cypressGrepPlugin (config) {
12
+ function cypressGrepPlugin(config) {
13
13
  if (!config || !config.env) {
14
14
  return config
15
15
  }
@@ -18,23 +18,23 @@ function cypressGrepPlugin (config) {
18
18
 
19
19
  if (!config.specPattern) {
20
20
  throw new Error(
21
- 'Incompatible versions detected, cypress-grep 3.0.0+ requires Cypress 10.0.0+',
21
+ 'Incompatible versions detected, cy-grep requires Cypress 10.0.0+',
22
22
  )
23
23
  }
24
24
 
25
- debug('cypress-grep plugin version %s', version)
25
+ debug('cy-grep plugin version %s', version)
26
26
  debug('Cypress config env object: %o', env)
27
27
 
28
28
  const grep = env.grep ? String(env.grep) : undefined
29
29
 
30
30
  if (grep) {
31
- console.log('cypress-grep: tests with "%s" in their names', grep.trim())
31
+ console.log('cy-grep: tests with "%s" in their names', grep.trim())
32
32
  }
33
33
 
34
34
  const grepTags = env.grepTags || env['grep-tags']
35
35
 
36
36
  if (grepTags) {
37
- console.log('cypress-grep: filtering using tag(s) "%s"', grepTags)
37
+ console.log('cy-grep: filtering using tag(s) "%s"', grepTags)
38
38
  const parsedGrep = parseGrep(null, grepTags)
39
39
 
40
40
  debug('parsed grep tags %o', parsedGrep.tags)
@@ -43,19 +43,19 @@ function cypressGrepPlugin (config) {
43
43
  const grepBurn = env.grepBurn || env['grep-burn'] || env.burn
44
44
 
45
45
  if (grepBurn) {
46
- console.log('cypress-grep: running filtered tests %d times', grepBurn)
46
+ console.log('cy-grep: running filtered tests %d times', grepBurn)
47
47
  }
48
48
 
49
49
  const grepUntagged = env.grepUntagged || env['grep-untagged']
50
50
 
51
51
  if (grepUntagged) {
52
- console.log('cypress-grep: running untagged tests')
52
+ console.log('cy-grep: running untagged tests')
53
53
  }
54
54
 
55
55
  const omitFiltered = env.grepOmitFiltered || env['grep-omit-filtered']
56
56
 
57
57
  if (omitFiltered) {
58
- console.log('cypress-grep: will omit filtered tests')
58
+ console.log('cy-grep: will omit filtered tests')
59
59
  }
60
60
 
61
61
  const { specPattern, excludeSpecPattern } = config
@@ -78,7 +78,7 @@ function cypressGrepPlugin (config) {
78
78
  let greppedSpecs = []
79
79
 
80
80
  if (grep) {
81
- console.log('cypress-grep: filtering specs using "%s" in the title', grep)
81
+ console.log('cy-grep: filtering specs using "%s" in the title', grep)
82
82
  const parsedGrep = parseGrep(grep)
83
83
 
84
84
  debug('parsed grep %o', parsedGrep)
@@ -117,15 +117,14 @@ function cypressGrepPlugin (config) {
117
117
  const text = fs.readFileSync(specFile, { encoding: 'utf8' })
118
118
 
119
119
  try {
120
- const testInfo = getTestNames(text)
121
-
120
+ const testTags = findEffectiveTestTags(text)
121
+ // we get back a single object with keys being full test titles
122
+ // and the values being arrays of effective test tags
122
123
  debug('spec file %s', specFile)
123
- debug('test info: %o', testInfo.tests)
124
-
125
- return testInfo.tests.some((info) => {
126
- const shouldRun = shouldTestRun(parsedGrep, null, info.tags)
127
-
128
- return shouldRun
124
+ debug('effective test tags %o', testTags)
125
+ return Object.keys(testTags).some((testTitle) => {
126
+ const effectiveTags = testTags[testTitle].effectiveTags
127
+ return shouldTestRun(parsedGrep, null, effectiveTags)
129
128
  })
130
129
  } catch (err) {
131
130
  console.error('Could not determine test names in file: %s', specFile)
package/src/support.js CHANGED
@@ -8,7 +8,8 @@ const {
8
8
  getPluginConfigValue,
9
9
  setPluginConfigValue,
10
10
  } = require('cypress-plugin-config')
11
- const debug = require('debug')('@bahmutov/cy-grep')
11
+ // to debug in the browser, set the "localStorage.debug='cy-grep'"
12
+ const debug = require('debug')('cy-grep')
12
13
 
13
14
  debug.log = console.info.bind(console)
14
15
 
@@ -18,7 +19,7 @@ const _describe = describe
18
19
 
19
20
  /**
20
21
  * Wraps the "it" and "describe" functions that support tags.
21
- * @see https://github.com/cypress-io/cypress-grep
22
+ * @see https://github.com/bahmutov/cy-grep
22
23
  */
23
24
  function cypressGrep() {
24
25
  /** @type {string} Part of the test title go grep */
@@ -70,9 +71,8 @@ function cypressGrep() {
70
71
  debug('parsed grep %o', parsedGrep)
71
72
 
72
73
  // prevent multiple registrations
73
- // https://github.com/cypress-io/cypress-grep/issues/59
74
74
  if (it.name === 'itGrep') {
75
- debug('already registered cypress-grep')
75
+ debug('already registered cy-grep')
76
76
 
77
77
  return
78
78
  }
@@ -205,7 +205,6 @@ function cypressGrep() {
205
205
  it.skip = _it.skip
206
206
  it.only = _it.only
207
207
  // preserve "it.each" method if found
208
- // https://github.com/cypress-io/cypress-grep/issues/72
209
208
  if (typeof _it.each === 'function') {
210
209
  it.each = _it.each
211
210
  }
@@ -237,7 +236,6 @@ if (!Cypress.grep) {
237
236
  * // remove all current grep settings
238
237
  * // and run all tests
239
238
  * Cypress.grep()
240
- * @see "Grep from DevTools console" https://github.com/cypress-io/cypress-grep#devtools-console
241
239
  */
242
240
  Cypress.grep = function grep(grep, tags, burn) {
243
241
  setPluginConfigValue('grep', grep)