cypress-grep icon indicating copy to clipboard operation
cypress-grep copied to clipboard

Grep is not working.

Open zubair-shahid-formsoft-inc-com opened this issue 2 years ago • 24 comments

./node_modules/.bin/cypress run --env grepTags="Smoke" Above command is running all of the tests.

I have the same issue

BelRaz avatar Jul 05 '22 11:07 BelRaz

Same here. I also use the in "open" view and it is including all .js files even though I see this in console:

cypress-grep: filtering using tag(s) "@webAppMonitor"
cypress-grep: will omit filtered tests
grep and/or grepTags has eliminated all specs
grepTags: @webAppMonitor
Will leave all specs to run to filter at run-time

mmitchell3590 avatar Jul 05 '22 16:07 mmitchell3590

FYI I have upgraded my example to Cypress v10 and cypress-grep@3 and it is working as expected, see the update PR https://github.com/bahmutov/cypress-grep-example/pull/79 To debug your problem we would need a reproducible example. My advice is to look at the debugging logging, maybe you can notice where the things go wrong https://github.com/cypress-io/cypress-grep#debugging-in-the-plugin

bahmutov avatar Jul 05 '22 16:07 bahmutov

FYI I have upgraded my example to Cypress v10 and cypress-grep@3 and it is working as expected, see the update PR bahmutov/cypress-grep-example#79 To debug your problem we would need a reproducible example. My advice is to look at the debugging logging, maybe you can notice where the things go wrong https://github.com/cypress-io/cypress-grep#debugging-in-the-plugin

I am using Cypress V10.0.3 and cypress-grep V3.0.1, still facing the same issue. Secondly, Running DEBUG=cypress-grep npx cypress run --env grep=works,grepFilterSpecs=true, does not shows any messages related to the plugin in the terminal output

Make sure you have installed the plugin correctly, see https://github.com/cypress-io/cypress-grep#install

bahmutov avatar Jul 05 '22 18:07 bahmutov

I double checked the plugin installation, and at least in my case it seems ok.

Here my e2e.js e2e js_-_aristamd_-_Visual_Studio_Code_202207051657051279

Here is my cypress.config.js cypress config js_-_aristamd_-_Visual_Studio_Code_202207051657051384

Here is output where it is finding all files in project now. I am only expecting 3 matches package json_-_aristamd_-_Visual_Studio_Code_202207051657051809

mmitchell3590 avatar Jul 05 '22 20:07 mmitchell3590

@mmitchell3590 can you enable debugging logs via DEBUG environment variable, please https://github.com/cypress-io/cypress-grep#debugging-in-the-plugin and see what it gives you?

bahmutov avatar Jul 05 '22 21:07 bahmutov

Here is the output:

  cypress-grep cypress-grep plugin version 3.0.1 +0ms
  cypress-grep Cypress config env object: { ...grepTags: '@webAppMonitor', grepFilterSpecs: true, grepOmitFiltered: true } }  +1ms  
cypress-grep: filtering using tag(s) "@webAppMonitor"
cypress-grep: will omit filtered tests
  cypress-grep parsed grep tags [ [ { tag: '@webAppMonitor', invert: false } ] ] +7ms
  cypress-grep specPattern **/*.* +4ms
  cypress-grep excludeSpecPattern *.hot-update.js +0ms
  cypress-grep integrationFolder C:\Users\matt_local\project\cypress-test\config\monitor\subproject +0ms
  cypress-grep found 1 spec files +21ms
  cypress-grep [ 'C:/Users/matt_local/project/cypress-test/config/monitor/subproject/cypress.config.js' ] +0ms
  cypress-grep parsed grep tags { title: [], tags: [ [ [Object] ] ] } +2ms
  cypress-grep spec file C:/Users/matt_local/project/cypress-test/config/monitor/subproject/cypress.config.js +61ms
  cypress-grep test info: [] +0ms
  cypress-grep found grep tags "@webAppMonitor" in 0 specs +0ms
  cypress-grep [] +1ms
grep and/or grepTags has eliminated all specs
grepTags: @webAppMonitor
Will leave all specs to run to filter at run-time

mmitchell3590 avatar Jul 06 '22 01:07 mmitchell3590

ok, so it seems it might not even find the config file correctly - can I ask about the repo setup? Where are the files package.json and cypress.config.js and the tests? Are they like this:

cypress-test/
  package.json
  config/
     monitor/
        subproject/
           cypress.config.js
           cypress/
              e2e/
                 spec1.cy.js
                 spec2.cy.js 
                 ...

bahmutov avatar Jul 06 '22 01:07 bahmutov

It is like this:

cypress-test/
  package.json
  config/
     monitor/
        subproject/
           cypress.config.js
  cypress/
      integration/
               spec1.js
               spec2.js 
           

mmitchell3590 avatar Jul 06 '22 01:07 mmitchell3590

And what’s the cypress.config.js spec pattern?

Sent from my iPhone

On Jul 5, 2022, at 21:59, Matt Mitchell @.***> wrote:

 It is like this:

cypress-test/ package.json config/ monitor/ subproject/ cypress.config.js cypress/ integration/ spec1.cy.js spec2.cy.js

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.

bahmutov avatar Jul 06 '22 02:07 bahmutov

Here is my cypress.config.js Screenshot 2022-07-06 at 2 41 40 PM

That's my project hierarchy

Screenshot 2022-07-06 at 2 44 44 PM

Here is my terminal output: Screenshot 2022-07-06 at 2 46 17 PM

Here is my package.json Screenshot 2022-07-06 at 2 47 35 PM

Make sure you have installed the plugin correctly, see https://github.com/cypress-io/cypress-grep#install

@bahmutov specPattern is: **/*.*

mmitchell3590 avatar Jul 06 '22 13:07 mmitchell3590

I think the problem comes when cypress-grep is setting the integrationFolder constant. if your cypress.config.js is not in the cypress folder then the plugin won't find your tests.

https://github.com/cypress-io/cypress-grep/blob/2568aebbe43291c1015afb1ae549403176498157/src/plugin.js#L55

So just set an environment variable in your cypress.config.js called grepIntegrationFolder pointing to the cypress folder. That's how I made it work.

image

I hope this help someone 😁

GilbertoGNG avatar Jul 14 '22 10:07 GilbertoGNG

I think the problem comes when cypress-grep is setting the integrationFolder constant. if your cypress.config.js is not in the cypress folder then the plugin won't find your tests.

https://github.com/cypress-io/cypress-grep/blob/2568aebbe43291c1015afb1ae549403176498157/src/plugin.js#L55

So just set an environment variable in your cypress.config.js called grepIntegrationFolder pointing to the cypress folder. That's how I made it work.

image

I hope this help someone 😁

@GilbertoGNG Still facing the same issue. I have added grepIntegrationFolder: '../../', in the cypress.config.js file Screenshot 2022-07-14 at 4 14 09 PM

Probably its my path issue which I am not able to resolve as my Plugin > Index.js shows error on require('cypress-grep/src/plugin')(config) (pic attached) Screenshot 2022-07-14 at 4 23 01 PM Screenshot 2022-07-14 at 4 23 05 PM

@zubair-shahid-formsoft-inc-com I believe you should import the plugin in the setupNodeEvents function in your cypress.config.js instead of your plugins/index.js file. Actually with Cypress 10 you don't need the plugins/index.js file anymore.

Example:

image

GilbertoGNG avatar Jul 14 '22 12:07 GilbertoGNG

I think the problem comes when cypress-grep is setting the integrationFolder constant. if your cypress.config.js is not in the cypress folder then the plugin won't find your tests.

https://github.com/cypress-io/cypress-grep/blob/2568aebbe43291c1015afb1ae549403176498157/src/plugin.js#L55

So just set an environment variable in your cypress.config.js called grepIntegrationFolder pointing to the cypress folder. That's how I made it work.

image

I hope this help someone 😁

This helped me, at least to filter the specs down to the ones that include my grep tag. The issue I am facing now, is that for example, in one spec file I may have 5 tests, but only 2 of them are marked with the grep tag. It is still trying to run all tests in the spec file anyway. grepOmitFiltered is set to true as well.

mmitchell3590 avatar Jul 14 '22 13:07 mmitchell3590

@GilbertoGNG I have imported everything under setupNodeEvents function in my cypress.config.js But I am still getting the same issue

Screenshot 2022-07-14 at 6 46 54 PM

Using Command: ./node_modules/.bin/cypress run --env grepTags="Smoke" It executes all of the tests

@zubair-shahid-formsoft-inc-com I believe you should import the plugin in the setupNodeEvents function in your cypress.config.js instead of your plugins/index.js file. Actually with Cypress 10 you don't need the plugins/index.js file anymore.

Example:

image

I double checked the plugin installation, and at least in my case it seems ok.

Here my e2e.js e2e js_-_aristamd_-_Visual_Studio_Code_202207051657051279

Here is my cypress.config.js cypress config js_-_aristamd_-_Visual_Studio_Code_202207051657051384

Here is output where it is finding all files in project now. I am only expecting 3 matches package json_-_aristamd_-_Visual_Studio_Code_202207051657051809

@zubair-shahid-formsoft-inc-com from these screenshots it looks like Cypress might not be finding your support file, which would potentially cause the issues you are seeing...

joshuajtward avatar Jul 26 '22 08:07 joshuajtward

Nice catch @joshuajtward -- I think you meant to tag me though, as those were my screenshots. I have another config file that extends to the one I shared in the screenshot, and the support file path was not defined there. Everything is working as expected on my end now. Thank you!

mmitchell3590 avatar Jul 28 '22 19:07 mmitchell3590

@mmitchell3590 Working through the same issues you shared above, curious how you fixed the support file?

Showler avatar Aug 30 '22 21:08 Showler

Hi @Showler! I believe the problem @mmitchell3590 was facing was the line supportFile: false in the cypress.config.js file - cypress-grep needs the plugin to be registered in the support file in order to function properly

joshuajtward avatar Sep 01 '22 10:09 joshuajtward

Thanks @joshuajtward that fixed the main issue. Now everything is running as expected! I did notice one interesting thing though. It appears that when passing in a config file the grep commands are not being recognized.

Here is what I am seeing:

  1. This command is working as expected with no issues (from my package.json file) "cy:run:smoke" : "cypress run --env grepTags=@smoke,grepFilterSpecs=true
  2. This command is not working as expected. It appears to be finding all files with spec in the file name and running those. "cy:run:sandbox-config:smoke": "cypress run --config-file cypress/configs/environment-configs/sandbox.config.js --env grepTags=@smoke,grepFilterSpecs=true"

It is curious because my cypress.config.js and my sandbox.config.js file are the same. This is the contents of both config files.

`const { defineConfig } = require('cypress')

  module.exports = defineConfig({
    e2e: {
      chromeWebSecurity: false,
      // Reporter options
      reporter: 'junit',
      reporterOptions: {
        outputs: true,
        attachments: true,
        includePending: true,
        testsuitesTitle: typeof(process.env.SUITE_NAME) != 'undefined' ? process.env.SUITE_NAME: "Cypress Tests " + new Date().toISOString(),
        rootSuiteTitle: "",
        mochaFile: 'cypress/results/test-results-[hash].xml',
      },
      baseUrl: "masking this url",
      specPattern: 'cypress/e2e/**/*spec.cy.js',
      // Import cypress plugins
      async setupNodeEvents(on, config) {
        // https://github.com/bahmutov/cypress-testrail-simple
        await require('cypress-testrail-simple/src/plugin')(on, config);
        await require('cypress-grep/src/plugin')(config);
        
        // make sure to return the config object
        // as it might have been modified by the plugin
        return config;
      },
    },
    env: {
      // Grep options for triggering tests
      grepFilterSpecs: true,
      grepOmitFiltered: true,
    }
})

Showler avatar Sep 01 '22 15:09 Showler

Glad to hear the main issue is resolved @Showler. As for the other problem with the other config file I'm not sure why it would be happening, do you get any insight if you run the command with DEBUG=cypress-grep?

joshuajtward avatar Sep 03 '22 07:09 joshuajtward

We are in the process of deprecating this repo as this package has been republished under @cypress/grep and has moved to https://github.com/cypress-io/cypress/tree/develop/npm/grep. I'm going to go ahead and close this issue as it appears stale. If this is still an issue, please open a new issue here

jordanpowell88 avatar Oct 28 '22 19:10 jordanpowell88