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

"grepFilterSpecs": true not working when passed through env files

Open shutchison-bai opened this issue 3 years ago • 10 comments

I have env files for each environment (dev,qa,uat,prod) when passing "grepFilterSpecs": true in the env file grepFilterSpecs is not working. I am thinking this either a bug or I am not loading/registering the module to the plugin file correctly. Be below is an example of my plugin file, env file and debug console.

Plugin file `/// // *********************************************************** // This example plugins/index.js can be used to load plugins // // You can change the location of this file or turn off loading // the plugins file with the 'pluginsFile' configuration option. // // You can read more here: // https://on.cypress.io/plugins-guide // ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to // the project's config changing)

/**

  • @type {Cypress.PluginConfig} */ // eslint-disable-next-line no-unused-vars

const { on } = require('events'); const fs = require('fs-extra'); const path = require('path');

function getConfigurationByFile(file) { const pathToConfigFile = path.resolve('config', ${file}.json);

return fs.readJson(pathToConfigFile); }

module.exports = (on, config) => { // on is used to hook into various events Cypress emits // config is the resolved Cypress config const file = config.env.configFile || 'qa'; let newConfig = getConfigurationByFile(file); require('cypress-grep/src/plugin')(newConfig);

return newConfig;

};`

env file

{ "baseUrl": "https://www.example.com", "env": { "name": "qa", "FAIL_FAST_STRATEGY": "spec", "FAIL_FAST_ENABLED": true, "grepTags": "@SMOKE", "grepBurn": 1, "grepFilterSpecs": true, "grepOmitFiltered": true } }

debug log {grep: undefined, grepTags: '@SMOKE ', grepBurn: 1, omitFiltered: true, version: '2.12.1'}

What is displaying in cypress settings config image

Cypress version 9.1.1 cypress-grep version 2.12.1

shutchison-bai avatar Dec 21 '21 21:12 shutchison-bai

I do not understand the issue - the settings are showing "grepFilterSpecs: true". Are they not applied? Can you try using the latest version of this plugin please?

bahmutov avatar Dec 22 '21 11:12 bahmutov

Correct the "grepFilterSpecs: true" is not applied. When running the suite with qa.json config file its loading all the specs instead of only loading specs with grepTags of @SMOKE. When I debugged the "grepFilterSpecs: true" setting was missing (see debug log above), but all other settings were applied.

I updated to the latest version and no luck.

shutchison-bai avatar Dec 22 '21 15:12 shutchison-bai

Hello @bahmutov,

Please know that I am facing the same issue.

I have added the below to my env file

env: {
    // grep: 'test',
    grepTags: '@test',
    grepFilterSpecs: true,
    // grepOmitFiltered: true"
    }

and am running the tests via Cypress Module API cypress.run().

If I run the tests locally, I get the following quick logs on the console:

cypress-grep: filtering using tag "@test"      
cypress-grep: filtering specs using tag "@test"
Grep "undefined" has eliminated all specs        
Will leave all specs to run to filter at run-time

I suppose it's the same issue, but it looks like if we are using only grepTags it will not properly filter out the spec files.

If I uncomment grep in my env:

env: {
    grep: 'test',
    grepTags: '@test',
    grepFilterSpecs: true,
    // grepOmitFiltered: true"
    }

Then the logs tell me they are filtering out the specs:

cypress-grep: tests with "test" in their names
cypress-grep: filtering using tag "@test"
cypress-grep: filtering specs using "test" in the title

But in reality Cypress still finds, queues and skips the execution for all my Spec files without the given grep/grepTag, and will eventually also run the ones that have the grep/grepTag as well.

cypress version 8.3.0 cypress-grep version 2.12.2 node version: 14.16.1

alexniculae avatar Dec 28 '21 16:12 alexniculae

Are you using the latest plugin version?

Sent from my iPhone

On Dec 28, 2021, at 11:56, testingJava2 @.***> wrote:

 Hello @bahmutov,

Please know that I am facing the same issue.

I have added the below to my env file

env: { // grep: 'test', grepTags: 'test', grepFilterSpecs: true, // grepOmitFiltered: true" } and am running the tests via Cypress Module API cypress.run().

If I run the tests locally, I get the following quick logs on the console:

cypress-grep: filtering using tag @."
cypress-grep: filtering specs using tag @.
" Grep "undefined" has eliminated all specs
Will leave all specs to run to filter at run-time I suppose it's the same issue, but it looks like if we are using only grepTags it will not properly filter out the spec files.

If I uncomment grep in my env:

env: { grep: 'test', grepTags: 'test', grepFilterSpecs: true, // grepOmitFiltered: true" } Then the logs tell me they are filtering out the specs:

cypress-grep: tests with "test" in their names cypress-grep: filtering using tag @.***" cypress-grep: filtering specs using "test" in the title But in reality Cypress still finds, queues and skips the execution for all my Spec files.

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

bahmutov avatar Dec 28 '21 17:12 bahmutov

@bahmutov I was just updating my comment with the versions of the packages I am using 🙂

Please see above

cypress version 8.3.0 cypress-grep version 2.12.2 node version: 14.16.1

alexniculae avatar Dec 28 '21 17:12 alexniculae

Hello, Happy New Year! 🙂

After running a DEBUG, I have the same behavior as @shutchison-bai:

  • the grepFilterSpecs: true is defined in my Cypress Test Runner GUI:

image

  • but in the verbose debug logs, the key-value pair is not there:

image

Let me know if I can help with additional details in debugging this one, @bahmutov.

Thank you.

alexniculae avatar Jan 03 '22 08:01 alexniculae

grepFilterSpecs is not present in the browser, because filtering happens in the plugins file, so that is expected.

bahmutov avatar Jan 03 '22 15:01 bahmutov

Hey @bahmutov, here is the repo containing the configuration to reproduce this issue: https://github.com/jjhelguero/cypress-configuration-files

Like the initial issue describes, the grepFilterSpecs will not be accounted even if it was set to true, which will result that all the specs will be loaded instead of the ones tagged with grepTags.

However, the grepOmitFiltered is working as expected.

sasocarthook avatar Feb 23 '22 13:02 sasocarthook

I am running into the same issue using grepFilterSpecs=true. Cypress 9.5.1 Cypress-grep 2.13.1 Is there a workaround to grep the specs? image

EmilyRocks avatar Mar 16 '22 22:03 EmilyRocks

Any updates on this one? I'm facing the same issue with

"cypress": "7.1.0",
"cypress-grep": "2.14.0",

cpradekwartalski avatar Jul 18 '22 06:07 cpradekwartalski

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