@bahmutov/cy-grep 2.0.37 → 2.1.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 +39 -1
 - package/package.json +2 -2
 - package/src/support.js +13 -0
 
    
        package/README.md
    CHANGED
    
    | 
         @@ -1,4 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # @bahmutov/cy-grep 
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            > Filter tests using substring or tag
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
         @@ -434,6 +434,44 @@ describe('parent', { tags: ['@p1', '@p2'] }, () => { 
     | 
|
| 
       434 
434 
     | 
    
         
             
            })
         
     | 
| 
       435 
435 
     | 
    
         
             
            ```
         
     | 
| 
       436 
436 
     | 
    
         | 
| 
      
 437 
     | 
    
         
            +
            Additionally, you can check both tags and required tags for each test within the current spec by checking the `Cypress.env('specTags')` object
         
     | 
| 
      
 438 
     | 
    
         
            +
             
     | 
| 
      
 439 
     | 
    
         
            +
            See [spec.js](./cypress/e2e/spec.js) for practical test spec example.
         
     | 
| 
      
 440 
     | 
    
         
            +
             
     | 
| 
      
 441 
     | 
    
         
            +
            Example output:
         
     | 
| 
      
 442 
     | 
    
         
            +
             
     | 
| 
      
 443 
     | 
    
         
            +
            ```js
         
     | 
| 
      
 444 
     | 
    
         
            +
            {
         
     | 
| 
      
 445 
     | 
    
         
            +
                "hello world": {
         
     | 
| 
      
 446 
     | 
    
         
            +
                    "effectiveTestTags": [],
         
     | 
| 
      
 447 
     | 
    
         
            +
                    "requiredTestTags": []
         
     | 
| 
      
 448 
     | 
    
         
            +
                },
         
     | 
| 
      
 449 
     | 
    
         
            +
                "works": {
         
     | 
| 
      
 450 
     | 
    
         
            +
                    "effectiveTestTags": [],
         
     | 
| 
      
 451 
     | 
    
         
            +
                    "requiredTestTags": []
         
     | 
| 
      
 452 
     | 
    
         
            +
                },
         
     | 
| 
      
 453 
     | 
    
         
            +
                "works 2 @tag1": {
         
     | 
| 
      
 454 
     | 
    
         
            +
                    "effectiveTestTags": [
         
     | 
| 
      
 455 
     | 
    
         
            +
                        "@tag1"
         
     | 
| 
      
 456 
     | 
    
         
            +
                    ],
         
     | 
| 
      
 457 
     | 
    
         
            +
                    "requiredTestTags": []
         
     | 
| 
      
 458 
     | 
    
         
            +
                },
         
     | 
| 
      
 459 
     | 
    
         
            +
                "works 2 @tag1 @tag2": {
         
     | 
| 
      
 460 
     | 
    
         
            +
                    "effectiveTestTags": [
         
     | 
| 
      
 461 
     | 
    
         
            +
                        "@tag1",
         
     | 
| 
      
 462 
     | 
    
         
            +
                        "@tag2"
         
     | 
| 
      
 463 
     | 
    
         
            +
                    ],
         
     | 
| 
      
 464 
     | 
    
         
            +
                    "requiredTestTags": []
         
     | 
| 
      
 465 
     | 
    
         
            +
                },
         
     | 
| 
      
 466 
     | 
    
         
            +
                "works @tag2": {
         
     | 
| 
      
 467 
     | 
    
         
            +
                    "effectiveTestTags": [
         
     | 
| 
      
 468 
     | 
    
         
            +
                        "@tag2"
         
     | 
| 
      
 469 
     | 
    
         
            +
                    ],
         
     | 
| 
      
 470 
     | 
    
         
            +
                    "requiredTestTags": []
         
     | 
| 
      
 471 
     | 
    
         
            +
                }
         
     | 
| 
      
 472 
     | 
    
         
            +
            }
         
     | 
| 
      
 473 
     | 
    
         
            +
            ```
         
     | 
| 
      
 474 
     | 
    
         
            +
             
     | 
| 
       437 
475 
     | 
    
         
             
            ## Pre-filter specs (grepFilterSpecs)
         
     | 
| 
       438 
476 
     | 
    
         | 
| 
       439 
477 
     | 
    
         
             
            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.
         
     | 
    
        package/package.json
    CHANGED
    
    | 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            {
         
     | 
| 
       2 
2 
     | 
    
         
             
              "name": "@bahmutov/cy-grep",
         
     | 
| 
       3 
     | 
    
         
            -
              "version": "2.0 
     | 
| 
      
 3 
     | 
    
         
            +
              "version": "2.1.0",
         
     | 
| 
       4 
4 
     | 
    
         
             
              "description": "Filter Cypress tests using title or tags",
         
     | 
| 
       5 
5 
     | 
    
         
             
              "main": "src/support.js",
         
     | 
| 
       6 
6 
     | 
    
         
             
              "scripts": {
         
     | 
| 
         @@ -20,7 +20,7 @@ 
     | 
|
| 
       20 
20 
     | 
    
         
             
                "globby": "^11.1.0"
         
     | 
| 
       21 
21 
     | 
    
         
             
              },
         
     | 
| 
       22 
22 
     | 
    
         
             
              "devDependencies": {
         
     | 
| 
       23 
     | 
    
         
            -
                "cypress": "15. 
     | 
| 
      
 23 
     | 
    
         
            +
                "cypress": "15.4.0",
         
     | 
| 
       24 
24 
     | 
    
         
             
                "cypress-each": "^1.11.0",
         
     | 
| 
       25 
25 
     | 
    
         
             
                "cypress-expect": "^3.1.0",
         
     | 
| 
       26 
26 
     | 
    
         
             
                "prettier": "^3.0.0",
         
     | 
    
        package/src/support.js
    CHANGED
    
    | 
         @@ -20,6 +20,10 @@ const _describe = describe 
     | 
|
| 
       20 
20 
     | 
    
         
             
            // includes both the test tags and the suite tags
         
     | 
| 
       21 
21 
     | 
    
         
             
            // and the required test tags
         
     | 
| 
       22 
22 
     | 
    
         
             
            const testTree = {}
         
     | 
| 
      
 23 
     | 
    
         
            +
            // keeps all collected test tags by the individual test title
         
     | 
| 
      
 24 
     | 
    
         
            +
            // includes both the test tags and the suite tags
         
     | 
| 
      
 25 
     | 
    
         
            +
            // used to expose within a Cypress environment variable
         
     | 
| 
      
 26 
     | 
    
         
            +
            const modifiedTestTree = {}
         
     | 
| 
       23 
27 
     | 
    
         | 
| 
       24 
28 
     | 
    
         
             
            beforeEach(() => {
         
     | 
| 
       25 
29 
     | 
    
         
             
              // set the test tags for the current test
         
     | 
| 
         @@ -136,6 +140,10 @@ function registerCyGrep() { 
     | 
|
| 
       136 
140 
     | 
    
         
             
                  .map((item) => item.name)
         
     | 
| 
       137 
141 
     | 
    
         
             
                  .concat(name)
         
     | 
| 
       138 
142 
     | 
    
         
             
                  .join(' ')
         
     | 
| 
      
 143 
     | 
    
         
            +
                const nameOfTest = suiteStack
         
     | 
| 
      
 144 
     | 
    
         
            +
                  .map((item) => item.name)
         
     | 
| 
      
 145 
     | 
    
         
            +
                  .concat(name)
         
     | 
| 
      
 146 
     | 
    
         
            +
                  .pop()
         
     | 
| 
       139 
147 
     | 
    
         
             
                const effectiveTestTags = suiteStack
         
     | 
| 
       140 
148 
     | 
    
         
             
                  .flatMap((item) => item.tags)
         
     | 
| 
       141 
149 
     | 
    
         
             
                  .concat(configTags)
         
     | 
| 
         @@ -147,6 +155,11 @@ function registerCyGrep() { 
     | 
|
| 
       147 
155 
     | 
    
         
             
                debug({ nameToGrep, effectiveTestTags, requiredTestTags })
         
     | 
| 
       148 
156 
     | 
    
         
             
                testTree[nameToGrep] = { effectiveTestTags, requiredTestTags }
         
     | 
| 
       149 
157 
     | 
    
         | 
| 
      
 158 
     | 
    
         
            +
                // Store the tags by individual name of test
         
     | 
| 
      
 159 
     | 
    
         
            +
                // Expose the object within the Cypress environment variables
         
     | 
| 
      
 160 
     | 
    
         
            +
                modifiedTestTree[nameOfTest] = { effectiveTestTags, requiredTestTags }
         
     | 
| 
      
 161 
     | 
    
         
            +
                Cypress.env('specTags', modifiedTestTree)
         
     | 
| 
      
 162 
     | 
    
         
            +
             
     | 
| 
       150 
163 
     | 
    
         
             
                const shouldRun = shouldTestRun(
         
     | 
| 
       151 
164 
     | 
    
         
             
                  parsedGrep,
         
     | 
| 
       152 
165 
     | 
    
         
             
                  nameToGrep,
         
     |