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.