diff --git a/tests/cypress/cypress.config.js b/tests/cypress/cypress.config.js index bafa2a5..67ba915 100644 --- a/tests/cypress/cypress.config.js +++ b/tests/cypress/cypress.config.js @@ -1,23 +1,18 @@ const { defineConfig } = require('cypress'); -const path = require('path'); module.exports = defineConfig({ chromeWebSecurity: false, - fixturesFolder: 'tests/cypress/fixtures', - screenshotsFolder: 'tests/cypress/screenshots', - videosFolder: 'tests/cypress/videos', - downloadsFolder: 'tests/cypress/downloads', - video: true, - reporter: 'mochawesome', - reporterOptions: { - mochaFile: 'mochawesome-[name]', - reportDir: path.join(__dirname, 'reports'), - overwrite: false, - html: false, - json: true, - }, + fixturesFolder: `${__dirname}/fixtures`, + screenshotsFolder: `${__dirname}/screenshots`, + videosFolder: `${__dirname}/videos`, + downloadsFolder: `${__dirname}/downloads`, + video: false, e2e: { - specPattern: 'tests/cypress/e2e/**/*.cy.{js,jsx,ts,tsx}', - supportFile: 'tests/cypress/support/index.js', + setupNodeEvents(on, config) { + // eslint-disable-next-line import/no-dynamic-require, global-require + return require(`${__dirname}/plugins/index.js`)(on, config); + }, + specPattern: `${__dirname}/e2e/*.test.{js,jsx,ts,tsx}`, + supportFile: `${__dirname}/support/index.js`, }, }); diff --git a/tests/cypress/plugins/index.js b/tests/cypress/plugins/index.js new file mode 100644 index 0000000..b8eff11 --- /dev/null +++ b/tests/cypress/plugins/index.js @@ -0,0 +1,35 @@ +/// +// *********************************************************** +// 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 { loadConfig } = require('@wordpress/env/lib/config'); +const getCacheDirectory = require('@wordpress/env/lib/config/get-cache-directory'); + +/** + * @type {Cypress.PluginConfig} + */ +// eslint-disable-next-line no-unused-vars +module.exports = async (on, config) => { + const cacheDirectory = await getCacheDirectory(); + const wpEnvConfig = await loadConfig(cacheDirectory); + + if (wpEnvConfig) { + const port = wpEnvConfig.env.tests.port || null; + + if (port) { + config.baseUrl = wpEnvConfig.env.tests.config.WP_SITEURL; + } + } + + return config; +};