cypress-io / cypress-grep

Filter tests using substring
137 stars 19 forks source link

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

Closed shutchison-bai closed 1 year ago

shutchison-bai commented 2 years ago

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)

/**

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

bahmutov commented 2 years ago

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?

shutchison-bai commented 2 years ago

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.

alexniculae commented 2 years ago

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

bahmutov commented 2 years ago

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.

alexniculae commented 2 years ago

@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 commented 2 years ago

Hello, Happy New Year! 🙂

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

image

image

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

Thank you.

bahmutov commented 2 years ago

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

sasocarthook commented 2 years ago

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.

EmilyRocks commented 2 years ago

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

cpradekwartalski commented 2 years ago

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

"cypress": "7.1.0",
"cypress-grep": "2.14.0",
jordanpowell88 commented 1 year ago

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