-2

I need to use both the configurationForEnvironment and cypress-grep (grepFilterSpecs=true) plugins. However, I couldn't make the two to work at the same time.

If I remove the configurationForEnvironment and return the config, grepFilterSpecs=true will work smoothly.

But if I add the multi env configuration and return configurationForEnvironment, grepFilterSpecs no longer works.

Here's the snapshot where I feel like the issue comes from:

import path = require('path');

const fetchConfigurationByFile = (file: string) => {
  const pathOfConfigurationFile = `config/cypress.${file}.json`;

  return (
    file && fs.readJson(path.join(__dirname, '../', pathOfConfigurationFile))
  );
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export default function (on: any, config: any) {
  require('cypress-mochawesome-reporter/plugin')(on); 
  require('@bahmutov/cy-grep/src/plugin')(config);

 const environment = config.env.configFile || 'preprod';
 const configurationForEnvironment = fetchConfigurationByFile(environment);
 console.log(configurationForEnvironment);
 return configurationForEnvironment || config;

}
npx cypress open --env grepTags=@smokethree,configFile='preprod'

While playing around, this is the observation I have where it seems the problem only occurs when both the configurationForEnvironment and cypress-grep are together. I also tried cy.task but has not been successful on that. Hope someone can help me to see what modifications I can do to handle both ways. Thank you.

Found this: Adding to module.exports on cypress/plugins/index.js file Cypress but doesn't have final solution.

  • 2
    Welcome to StackOverflow. The linked question should indeed give you both features without issue. If you have come across a specific problem, please feel free to add *reproducible* details to your question and someone will help you with it. The code you presented looks like it's **not following the posted answer**, which I think should be the way you want to handle the two features together. – Ho'okano Aug 18 '23 at 07:51

0 Answers0