From cf8f65fb1ad8af30f6eca9114cbbab089beb4364 Mon Sep 17 00:00:00 2001 From: Ans Date: Wed, 14 Jun 2023 13:41:26 -0400 Subject: [PATCH 1/8] Add devtools open on launch config to Cypress plugins --- cypress/plugins/index.js | 22 ---------------------- test/cypress/plugins/index.js | 27 +++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 26 deletions(-) delete mode 100644 cypress/plugins/index.js diff --git a/cypress/plugins/index.js b/cypress/plugins/index.js deleted file mode 100644 index 8229063adc1..00000000000 --- a/cypress/plugins/index.js +++ /dev/null @@ -1,22 +0,0 @@ -/// -// *********************************************************** -// 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 -module.exports = (on, config) => { - // `on` is used to hook into various events Cypress emits - // `config` is the resolved Cypress config -}; diff --git a/test/cypress/plugins/index.js b/test/cypress/plugins/index.js index 5ed3ca1d4bc..80a20c69cdd 100644 --- a/test/cypress/plugins/index.js +++ b/test/cypress/plugins/index.js @@ -14,11 +14,30 @@ /** * @type {Cypress.PluginConfig} - * @param {object} on - hook into various events Cypress emits - * @param {object} config - the resolved Cypress config + * @param {object} on - hook into various events Cypress emits. + * @param {object} config - the resolved Cypress config. */ // eslint-disable-next-line no-unused-vars module.exports = (on, config) => { - /* `on` is used to hook into various events Cypress emits - `config` is the resolved Cypress config */ + // Workaround to show devtools in failure screenshots. + // See https://github.com/cypress-io/cypress/issues/2024#issuecomment-754571301 + on('before:browser:launch', (browser = {}, launchOptions) => { + if (browser.family === 'chromium' && browser.name !== 'electron') { + // auto open devtools + launchOptions.args.push('--auto-open-devtools-for-tabs'); + } + + if (browser.family === 'firefox') { + // auto open devtools + launchOptions.args.push('-devtools'); + } + + if (browser.name === 'electron') { + // auto open devtools + launchOptions.preferences.devTools = true; + } + + // whatever you return here becomes the launchOptions + return launchOptions; + }); }; From ae13cf0d8da9e70710935924d5544be741f13d10 Mon Sep 17 00:00:00 2001 From: Ans Date: Wed, 14 Jun 2023 14:26:23 -0400 Subject: [PATCH 2/8] Cypress plugin formatting adjustments --- test/cypress/plugins/index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/cypress/plugins/index.js b/test/cypress/plugins/index.js index 80a20c69cdd..2d8be183e44 100644 --- a/test/cypress/plugins/index.js +++ b/test/cypress/plugins/index.js @@ -21,23 +21,23 @@ module.exports = (on, config) => { // Workaround to show devtools in failure screenshots. // See https://github.com/cypress-io/cypress/issues/2024#issuecomment-754571301 - on('before:browser:launch', (browser = {}, launchOptions) => { + on('before:browser:launch', (browser = {}, launchOptions = {}) => { if (browser.family === 'chromium' && browser.name !== 'electron') { - // auto open devtools + // Auto open devtools. launchOptions.args.push('--auto-open-devtools-for-tabs'); } if (browser.family === 'firefox') { - // auto open devtools + // Auto open devtools. launchOptions.args.push('-devtools'); } if (browser.name === 'electron') { - // auto open devtools + // Auto open devtools. launchOptions.preferences.devTools = true; } - // whatever you return here becomes the launchOptions + // Whatever you return here becomes the launchOptions. return launchOptions; }); }; From cb20623f0a45d85e5e92f91231802a6d8b7ba106 Mon Sep 17 00:00:00 2001 From: Ans Date: Wed, 14 Jun 2023 14:49:06 -0400 Subject: [PATCH 3/8] Place plugin in correct spot --- cypress.config.cjs | 24 +++++++++++++++++++ test/cypress/plugins/index.js | 43 ----------------------------------- 2 files changed, 24 insertions(+), 43 deletions(-) delete mode 100644 test/cypress/plugins/index.js diff --git a/cypress.config.cjs b/cypress.config.cjs index 14bc68e70a0..02f73429b75 100644 --- a/cypress.config.cjs +++ b/cypress.config.cjs @@ -13,6 +13,30 @@ module.exports = defineConfig({ specPattern: 'test/cypress/integration/**/*.cy.{js,jsx,ts,tsx}', supportFile: 'test/cypress/support/e2e.js', excludeSpecPattern: 'test/cypress/integration/**/*-helpers.cy.js', + setupNodeEvents(on, config) { + on('before:browser:launch', (browser = {}, launchOptions = {}) => { + // Log browser info. This could be useful when comparing local to CI. + console.log('Launching browser', browser); + + if (browser.family === 'chromium' && browser.name !== 'electron') { + // Auto open devtools. + launchOptions.args.push('--auto-open-devtools-for-tabs'); + } + + if (browser.family === 'firefox') { + // Auto open devtools. + launchOptions.args.push('-devtools'); + } + + if (browser.name === 'electron') { + // Auto open devtools. + launchOptions.preferences.devTools = true; + } + + // Whatever you return here becomes the launchOptions. + return launchOptions; + }); + }, }, component: { specPattern: 'test/cypress/component/**/*.cy.{js,jsx,ts,tsx}', diff --git a/test/cypress/plugins/index.js b/test/cypress/plugins/index.js deleted file mode 100644 index 2d8be183e44..00000000000 --- a/test/cypress/plugins/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/* / - *********************************************************** - 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} - * @param {object} on - hook into various events Cypress emits. - * @param {object} config - the resolved Cypress config. - */ -// eslint-disable-next-line no-unused-vars -module.exports = (on, config) => { - // Workaround to show devtools in failure screenshots. - // See https://github.com/cypress-io/cypress/issues/2024#issuecomment-754571301 - on('before:browser:launch', (browser = {}, launchOptions = {}) => { - if (browser.family === 'chromium' && browser.name !== 'electron') { - // Auto open devtools. - launchOptions.args.push('--auto-open-devtools-for-tabs'); - } - - if (browser.family === 'firefox') { - // Auto open devtools. - launchOptions.args.push('-devtools'); - } - - if (browser.name === 'electron') { - // Auto open devtools. - launchOptions.preferences.devTools = true; - } - - // Whatever you return here becomes the launchOptions. - return launchOptions; - }); -}; From a2983c93e6013799b4da0c2ff9040ce8a9a533e1 Mon Sep 17 00:00:00 2001 From: Ans Date: Wed, 14 Jun 2023 15:59:38 -0400 Subject: [PATCH 4/8] Comment out console.log of browser settings --- cypress.config.cjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress.config.cjs b/cypress.config.cjs index 02f73429b75..6aab4d2f71a 100644 --- a/cypress.config.cjs +++ b/cypress.config.cjs @@ -16,7 +16,7 @@ module.exports = defineConfig({ setupNodeEvents(on, config) { on('before:browser:launch', (browser = {}, launchOptions = {}) => { // Log browser info. This could be useful when comparing local to CI. - console.log('Launching browser', browser); + // console.log('Launching browser', browser); if (browser.family === 'chromium' && browser.name !== 'electron') { // Auto open devtools. From fc0a34d0fe12ec92101f2039b561a8e7bdb50100 Mon Sep 17 00:00:00 2001 From: Ans Date: Wed, 14 Jun 2023 17:03:29 -0400 Subject: [PATCH 5/8] Refactor plugin --- cypress.config.cjs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/cypress.config.cjs b/cypress.config.cjs index 6aab4d2f71a..f92a226e269 100644 --- a/cypress.config.cjs +++ b/cypress.config.cjs @@ -18,21 +18,15 @@ module.exports = defineConfig({ // Log browser info. This could be useful when comparing local to CI. // console.log('Launching browser', browser); - if (browser.family === 'chromium' && browser.name !== 'electron') { - // Auto open devtools. - launchOptions.args.push('--auto-open-devtools-for-tabs'); - } - - if (browser.family === 'firefox') { - // Auto open devtools. + // Auto open devtools. + if (browser.family === 'chromium') { + if (browser.name === 'electron') + launchOptions.preferences.devTools = true; + else launchOptions.args.push('--auto-open-devtools-for-tabs'); + } else if (browser.family === 'firefox') { launchOptions.args.push('-devtools'); } - if (browser.name === 'electron') { - // Auto open devtools. - launchOptions.preferences.devTools = true; - } - // Whatever you return here becomes the launchOptions. return launchOptions; }); From 0bd281a5fd662dde2ab51478b1ea02975be2f4f5 Mon Sep 17 00:00:00 2001 From: Ans Date: Wed, 14 Jun 2023 17:14:37 -0400 Subject: [PATCH 6/8] Return `config` from `setupNodeEvents` --- cypress.config.cjs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cypress.config.cjs b/cypress.config.cjs index f92a226e269..b1c9e026e3d 100644 --- a/cypress.config.cjs +++ b/cypress.config.cjs @@ -13,6 +13,8 @@ module.exports = defineConfig({ specPattern: 'test/cypress/integration/**/*.cy.{js,jsx,ts,tsx}', supportFile: 'test/cypress/support/e2e.js', excludeSpecPattern: 'test/cypress/integration/**/*-helpers.cy.js', + // setupNodeEvents can be defined in either + // the e2e or component configuration. setupNodeEvents(on, config) { on('before:browser:launch', (browser = {}, launchOptions = {}) => { // Log browser info. This could be useful when comparing local to CI. @@ -30,6 +32,9 @@ module.exports = defineConfig({ // Whatever you return here becomes the launchOptions. return launchOptions; }); + + // IMPORTANT return the updated config object. + return config; }, }, component: { From 0bcb90f597d066acc39262e9ba4bf5f554aa8a30 Mon Sep 17 00:00:00 2001 From: Ans Date: Wed, 14 Jun 2023 18:49:32 -0400 Subject: [PATCH 7/8] Change order of plugin --- cypress.config.cjs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cypress.config.cjs b/cypress.config.cjs index b1c9e026e3d..dcf4f5e9715 100644 --- a/cypress.config.cjs +++ b/cypress.config.cjs @@ -9,10 +9,6 @@ module.exports = defineConfig({ defaultCommandTimeout: 25000, blockHosts: ['*google-analytics.com', '*googletagmanager.com'], e2e: { - baseUrl: 'http://localhost:8000', - specPattern: 'test/cypress/integration/**/*.cy.{js,jsx,ts,tsx}', - supportFile: 'test/cypress/support/e2e.js', - excludeSpecPattern: 'test/cypress/integration/**/*-helpers.cy.js', // setupNodeEvents can be defined in either // the e2e or component configuration. setupNodeEvents(on, config) { @@ -36,6 +32,10 @@ module.exports = defineConfig({ // IMPORTANT return the updated config object. return config; }, + baseUrl: 'http://localhost:8000', + specPattern: 'test/cypress/integration/**/*.cy.{js,jsx,ts,tsx}', + supportFile: 'test/cypress/support/e2e.js', + excludeSpecPattern: 'test/cypress/integration/**/*-helpers.cy.js', }, component: { specPattern: 'test/cypress/component/**/*.cy.{js,jsx,ts,tsx}', From 0c0948d2ae85613f9700481c942055504b744561 Mon Sep 17 00:00:00 2001 From: Ans Date: Wed, 14 Jun 2023 18:59:25 -0400 Subject: [PATCH 8/8] Remove launch options default value --- cypress.config.cjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress.config.cjs b/cypress.config.cjs index dcf4f5e9715..838b6f9f68f 100644 --- a/cypress.config.cjs +++ b/cypress.config.cjs @@ -12,7 +12,7 @@ module.exports = defineConfig({ // setupNodeEvents can be defined in either // the e2e or component configuration. setupNodeEvents(on, config) { - on('before:browser:launch', (browser = {}, launchOptions = {}) => { + on('before:browser:launch', (browser = {}, launchOptions) => { // Log browser info. This could be useful when comparing local to CI. // console.log('Launching browser', browser);