My cypress/plugins/index.js file looks like this and I know that there can only be one module.exports, but I'm struggling to add cypressBrowserPermissionsPlugin and getConfigurationByFile together
const cucumber = require('cypress-cucumber-preprocessor').default
const { cypressBrowserPermissionsPlugin } = require('cypress-browser-permissions')
const path = require('path')
const fs = require('fs')
require('@applitools/eyes-cypress')(module);
function getConfigurationByFile(file) {
const pathToConfigFile = path.resolve('cypress/config', `${file}.json`);
return fs.readJson(pathToConfigFile);
}
const file = config.env.configFile || 'qa';
module.exports = (on, config) => {
on('file:preprocessor', cucumber())
config = cypressBrowserPermissionsPlugin(on, config)
return config
// I want to also return the getConfigurationByFile(file) function
}
You would need to wrap the function getConfigurationByFile
into a task
function getConfigurationByFile(file) {
const pathToConfigFile = path.resolve('cypress/config', `${file}.json`);
return fs.readJson(pathToConfigFile);
}
module.exports = (on, config) => {
on('file:preprocessor', cucumber());
on('task', {
getConfiguration (fileName) {
const file = fileName || config.env.configFile || 'qa'; // filename defaults
return getConfigurationByFile (file);
}
})
config = cypressBrowserPermissionsPlugin(on, config);
return config;
}
and call it in the test like this
cy.task('getConfiguration', 'my-config-file').then(config => {
...
});
or with default file name
cy.task('getConfiguration').then(config => {
...
});