/// // *********************************************************** // 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 path = require("path"); const webpack = require("@cypress/webpack-preprocessor"); const { cypressBrowserPermissionsPlugin, } = require("cypress-browser-permissions"); const fs = require("fs-extra"); const getConfigurationByFile = file => { const pathToConfigFile = `config/cypress.${file}.json`; return file && fs.readJsonSync(path.join(__dirname, "../", pathToConfigFile)); }; const merge = (target, source = {}) => { Object.keys(source).forEach(key => { if (source[key] && typeof source[key] === "object") { merge((target[key] = target[key] || {}), source[key]); return; } target[key] = source[key]; }); return target; }; module.exports = (on, config) => { const environment = config.env.configFile; const configForEnvironment = getConfigurationByFile(environment); const options = { // send in the options from your webpack.config.js webpackOptions: require("../webpack.config"), watchOptions: {}, }; on("file:preprocessor", webpack(options)); config = cypressBrowserPermissionsPlugin(on, config); const newEnvironment = merge(config, configForEnvironment); require("@cypress/grep/src/plugin")(newEnvironment); require("@cypress/code-coverage/task")(on, newEnvironment); return config, newEnvironment; };