@bahmutov/cy-grep 1.1.0 → 1.2.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.
Files changed (3) hide show
  1. package/README.md +23 -15
  2. package/package.json +1 -1
  3. package/src/plugin.js +9 -10
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
 
@@ -81,7 +81,8 @@ yarn add -D @bahmutov/cy-grep
81
81
  **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
82
 
83
83
  ```js
84
- // cypress/support/index.js
84
+ // cypress/support/e2e.js
85
+
85
86
  // load and register the grep feature using "require" function
86
87
  // https://github.com/bahmutov/cy-grep
87
88
  const registerCypressGrep = require('@bahmutov/cy-grep')
@@ -90,7 +91,7 @@ registerCypressGrep()
90
91
  // if you want to use the "import" keyword
91
92
  // note: `./index.d.ts` currently extends the global Cypress types and
92
93
  // does not define `registerCypressGrep` so the import path is directly
93
- // pointed to the `support.js` file
94
+ // pointed to the support file
94
95
  import registerCypressGrep from '@bahmutov/cy-grep/src/support'
95
96
  registerCypressGrep()
96
97
 
@@ -111,13 +112,14 @@ registerCypressGrep()
111
112
  e2e: {
112
113
  setupNodeEvents(on, config) {
113
114
  require('@bahmutov/cy-grep/src/plugin')(config);
115
+ // IMPORTANT: return the config object
114
116
  return config;
115
- },
117
+ },
116
118
  }
117
119
  }
118
120
  ```
119
121
 
120
- Installing the plugin via `setupNodeEvents()` is required to enable the [grepFilterSpecs](#grepfilterspecs) feature.
122
+ Installing the plugin via `setupNodeEvents()` is required to enable the [grepFilterSpecs](#pre-filter-specs-grepfilterspecs) feature.
121
123
 
122
124
  ## Usage Overview
123
125
 
@@ -353,9 +355,12 @@ $ npx cypress run --env grepTags=@smoke,grepFilterSpecs=true
353
355
  **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
356
 
355
357
  ```js
358
+ // config file
356
359
  {
357
- "env": {
358
- "grepFilterSpecs": true
360
+ "e2e": {
361
+ "env": {
362
+ "grepFilterSpecs": true
363
+ }
359
364
  }
360
365
  }
361
366
  ```
@@ -505,20 +510,23 @@ Once the tests finish, you can run just the failed tests from DevTools console
505
510
 
506
511
  **Tip:** use `Cypress.grep()` to reset and run all the tests
507
512
 
513
+ 📝 Read the blog post [Run Just The Failed Tests In Cypress](https://glebbahmutov.com/blog/run-failed-tests/).
514
+
508
515
  ## Debugging
509
516
 
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).
517
+ 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
518
 
512
519
  ```
513
- # get the cypress-grep version using NPM
514
- $ npm ls cypress-grep
520
+ # get the plugin's version using NPM
521
+ $ npm ls @bahmutov/cy-grep
515
522
  ...
516
- └── cypress-grep@2.10.1
517
- # get the cypress-grep version using Yarn
518
- $ yarn why cypress-grep
523
+ └── @bahmutov/cy-grep@1.1.0
524
+
525
+ # get the plugin's version using Yarn
526
+ $ yarn why @bahmutov/cy-grep
519
527
  ...
520
- => Found "cypress-grep@2.10.1"
521
- info Has been hoisted to "cypress-grep"
528
+ => Found "@bahmutov/cy-grep@1.1.0"
529
+ info Has been hoisted to "@bahmutov/cy-grep"
522
530
  info This module exists because it's specified in "devDependencies".
523
531
  ...
524
532
  ```
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.0",
4
4
  "description": "Filter Cypress tests using title or tags",
5
5
  "main": "src/support.js",
6
6
  "scripts": {
package/src/plugin.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const debug = require('debug')('cypress-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')
@@ -9,7 +9,7 @@ const { parseGrep, shouldTestRun } = require('./utils')
9
9
  * Prints the cypress-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
  }
@@ -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]
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)