Skip to content

Commit

Permalink
added cypress/plugins/index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
sksaju committed Nov 5, 2024
1 parent fa93074 commit 3adf941
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 16 deletions.
27 changes: 11 additions & 16 deletions tests/cypress/cypress.config.js
Original file line number Diff line number Diff line change
@@ -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`,
},
});
35 changes: 35 additions & 0 deletions tests/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/// <reference types="cypress" />
// ***********************************************************
// 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');

/**

Check warning on line 18 in tests/cypress/plugins/index.js

View workflow job for this annotation

GitHub Actions / eslint

Missing JSDoc block description
* @type {Cypress.PluginConfig}

Check warning on line 19 in tests/cypress/plugins/index.js

View workflow job for this annotation

GitHub Actions / eslint

The type 'Cypress' is undefined
*/
// 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;
};

0 comments on commit 3adf941

Please sign in to comment.