This repository was archived by the owner on Sep 1, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 14 files changed +183
-1
lines changed
packages/cypress-plugin/test Expand file tree Collapse file tree 14 files changed +183
-1
lines changed Original file line number Diff line number Diff line change 1+ // Copyright (c) 2023 Developer Innovations, LLC
2+
3+ /**
4+ * Workaround for https://github.com/cypress-io/cypress/issues/27804.
5+ *
6+ * @param {Cypress.PluginEvents } on
7+ * @returns void
8+ */
9+ export const fixHeadlessChrome = ( on ) => {
10+ on (
11+ "before:browser:launch" ,
12+ /**
13+ * @param {Cypress.Browser } browser,
14+ * @param {Cypress.BrowserLaunchOptions } launchOptions
15+ * @returns {void | Cypress.BrowserLaunchOptions }
16+ */
17+ ( browser , launchOptions ) => {
18+ if (
19+ browser . family === "chromium" &&
20+ browser . name !== "electron" &&
21+ browser . isHeadless
22+ ) {
23+ launchOptions . args = launchOptions . args . map ( ( arg ) =>
24+ arg === "--headless" ? "--headless=new" : arg
25+ ) ;
26+ }
27+
28+ return launchOptions ;
29+ }
30+ ) ;
31+ } ;
Original file line number Diff line number Diff line change 1+ // Copyright (c) 2023 Developer Innovations, LLC
2+
3+ // Workaround for https://github.com/cypress-io/cypress/issues/27804.
4+ export const fixHeadlessChrome = ( on : Cypress . PluginEvents ) : void => {
5+ on (
6+ "before:browser:launch" ,
7+ (
8+ browser : Cypress . Browser ,
9+ launchOptions : Cypress . BrowserLaunchOptions
10+ ) : void | Cypress . BrowserLaunchOptions => {
11+ if (
12+ browser . family === "chromium" &&
13+ browser . name !== "electron" &&
14+ browser . isHeadless
15+ ) {
16+ launchOptions . args = launchOptions . args . map ( ( arg ) =>
17+ arg === "--headless" ? "--headless=new" : arg
18+ ) ;
19+ }
20+
21+ return launchOptions ;
22+ }
23+ ) ;
24+ } ;
Original file line number Diff line number Diff line change @@ -17,6 +17,9 @@ module.exports = {
1717 * @returns {Promise<Cypress.PluginConfigOptions | void> | Cypress.PluginConfigOptions | void }
1818 */
1919 async setupNodeEvents ( on , _config ) {
20+ const { fixHeadlessChrome } = await import ( "./config-js/headless.js" ) ;
21+
22+ fixHeadlessChrome ( on ) ;
2023 registerCosmiconfigMock ( ) ;
2124 registerSimpleGitMock ( ) ;
2225
@@ -38,6 +41,9 @@ module.exports = {
3841 * @returns {Promise<Cypress.PluginConfigOptions | void> | Cypress.PluginConfigOptions | void }
3942 */
4043 async setupNodeEvents ( on , _config ) {
44+ const { fixHeadlessChrome } = await import ( "./config-js/headless.js" ) ;
45+
46+ fixHeadlessChrome ( on ) ;
4147 registerCosmiconfigMock ( ) ;
4248 registerSimpleGitMock ( ) ;
4349
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { registerTasks } from "./config-js/tasks.js";
55import webpackConfig from "./config-js/webpack.js" ;
66import { registerSimpleGitMock } from "unflakable-test-common/dist/git.js" ;
77import { registerCosmiconfigMock } from "unflakable-test-common/dist/config.js" ;
8+ import { fixHeadlessChrome } from "./config-js/headless.js" ;
89
910/**
1011 * @type {Cypress.ConfigOptions }
@@ -17,6 +18,7 @@ export default {
1718 * @returns {Promise<Cypress.PluginConfigOptions | void> | Cypress.PluginConfigOptions | void }
1819 */
1920 setupNodeEvents ( on , _config ) {
21+ fixHeadlessChrome ( on ) ;
2022 registerCosmiconfigMock ( ) ;
2123 registerSimpleGitMock ( ) ;
2224 registerTasks ( on ) ;
@@ -35,6 +37,7 @@ export default {
3537 * @returns {Promise<Cypress.PluginConfigOptions | void> | Cypress.PluginConfigOptions | void }
3638 */
3739 setupNodeEvents ( on , _config ) {
40+ fixHeadlessChrome ( on ) ;
3841 registerCosmiconfigMock ( ) ;
3942 registerSimpleGitMock ( ) ;
4043 registerTasks ( on ) ;
Original file line number Diff line number Diff line change @@ -8,10 +8,12 @@ import { registerTasks } from "./config/tasks.js";
88import webpackConfig from "./config/webpack.js" ;
99import { registerSimpleGitMock } from "unflakable-test-common/dist/git.js" ;
1010import { registerCosmiconfigMock } from "unflakable-test-common/dist/config.js" ;
11+ import { fixHeadlessChrome } from "./config/headless.js" ;
1112
1213export default defineConfig ( {
1314 component : {
1415 setupNodeEvents ( on : Cypress . PluginEvents , _config ) {
16+ fixHeadlessChrome ( on ) ;
1517 registerCosmiconfigMock ( ) ;
1618 registerSimpleGitMock ( ) ;
1719 registerTasks ( on ) ;
@@ -31,6 +33,7 @@ export default defineConfig({
3133 | Promise < Cypress . PluginConfigOptions | void >
3234 | Cypress . PluginConfigOptions
3335 | void {
36+ fixHeadlessChrome ( on ) ;
3437 registerCosmiconfigMock ( ) ;
3538 registerSimpleGitMock ( ) ;
3639 registerTasks ( on ) ;
Original file line number Diff line number Diff line change 1+ // Copyright (c) 2023 Developer Innovations, LLC
2+
3+ module . exports = {
4+ /**
5+ * Workaround for https://github.com/cypress-io/cypress/issues/27804.
6+ *
7+ * @param {Cypress.PluginEvents } on
8+ * @returns void
9+ */
10+ fixHeadlessChrome : ( on ) => {
11+ on (
12+ "before:browser:launch" ,
13+ /**
14+ * @param {Cypress.Browser } browser,
15+ * @param {Cypress.BrowserLaunchOptions } launchOptions
16+ * @returns {void | Cypress.BrowserLaunchOptions }
17+ */
18+ ( browser , launchOptions ) => {
19+ if (
20+ browser . family === "chromium" &&
21+ browser . name !== "electron" &&
22+ browser . isHeadless
23+ ) {
24+ launchOptions . args = launchOptions . args . map ( ( arg ) =>
25+ arg === "--headless" ? "--headless=new" : arg
26+ ) ;
27+ }
28+
29+ return launchOptions ;
30+ }
31+ ) ;
32+ } ,
33+ } ;
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import { registerCosmiconfigMock } from "unflakable-test-common/dist/config.js";
88import { registerUnflakable } from "@unflakable/cypress-plugin" ;
99import semverGte from "semver/functions/gte.js" ;
1010import path from "path" ;
11+ import headless from "./config/headless.js" ;
1112import cypressOnFix from "cypress-on-fix" ;
1213
1314/**
@@ -22,6 +23,7 @@ export default {
2223 */
2324 setupNodeEvents ( baseOn , config ) {
2425 const on = cypressOnFix ( baseOn ) ;
26+ headless . fixHeadlessChrome ( on ) ;
2527 registerCosmiconfigMock ( ) ;
2628 registerSimpleGitMock ( ) ;
2729 tasks . registerTasks ( on ) ;
@@ -43,6 +45,7 @@ export default {
4345 */
4446 setupNodeEvents ( baseOn , config ) {
4547 const on = cypressOnFix ( baseOn ) ;
48+ headless . fixHeadlessChrome ( on ) ;
4649 registerCosmiconfigMock ( ) ;
4750 registerSimpleGitMock ( ) ;
4851 tasks . registerTasks ( on ) ;
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ const semverGte = require("semver/functions/gte");
1111
1212const { registerUnflakable } = require ( "@unflakable/cypress-plugin" ) ;
1313const path = require ( "path" ) ;
14+ const { fixHeadlessChrome } = require ( "./config/headless" ) ;
1415const cypressOnFix = require ( "cypress-on-fix" ) ;
1516
1617module . exports = {
@@ -25,6 +26,7 @@ module.exports = {
2526 */
2627 setupNodeEvents ( baseOn , config ) {
2728 const on = cypressOnFix ( baseOn ) ;
29+ fixHeadlessChrome ( on ) ;
2830 registerCosmiconfigMock ( ) ;
2931 registerSimpleGitMock ( ) ;
3032 registerTasks ( on ) ;
@@ -46,6 +48,7 @@ module.exports = {
4648 */
4749 setupNodeEvents ( baseOn , config ) {
4850 const on = cypressOnFix ( baseOn ) ;
51+ fixHeadlessChrome ( on ) ;
4952 registerCosmiconfigMock ( ) ;
5053 registerSimpleGitMock ( ) ;
5154 registerTasks ( on ) ;
Original file line number Diff line number Diff line change 1+ // Copyright (c) 2023 Developer Innovations, LLC
2+
3+ module . exports = {
4+ /**
5+ * Workaround for https://github.com/cypress-io/cypress/issues/27804.
6+ *
7+ * @param {Cypress.PluginEvents } on
8+ * @returns void
9+ */
10+ fixHeadlessChrome : ( on ) => {
11+ on (
12+ "before:browser:launch" ,
13+ /**
14+ * @param {Cypress.Browser } browser,
15+ * @param {Cypress.BrowserLaunchOptions } launchOptions
16+ * @returns {void | Cypress.BrowserLaunchOptions }
17+ */
18+ ( browser , launchOptions ) => {
19+ if (
20+ browser . family === "chromium" &&
21+ browser . name !== "electron" &&
22+ browser . isHeadless
23+ ) {
24+ launchOptions . args = launchOptions . args . map ( ( arg ) =>
25+ arg === "--headless" ? "--headless=new" : arg
26+ ) ;
27+ }
28+
29+ return launchOptions ;
30+ }
31+ ) ;
32+ } ,
33+ } ;
Original file line number Diff line number Diff line change 1+ // Copyright (c) 2023 Developer Innovations, LLC
2+
3+ // Workaround for https://github.com/cypress-io/cypress/issues/27804.
4+ export const fixHeadlessChrome = ( on : Cypress . PluginEvents ) : void => {
5+ on (
6+ "before:browser:launch" ,
7+ (
8+ browser : Cypress . Browser ,
9+ launchOptions : Cypress . BrowserLaunchOptions
10+ ) : void | Cypress . BrowserLaunchOptions => {
11+ if (
12+ browser . family === "chromium" &&
13+ browser . name !== "electron" &&
14+ browser . isHeadless
15+ ) {
16+ launchOptions . args = launchOptions . args . map ( ( arg ) =>
17+ arg === "--headless" ? "--headless=new" : arg
18+ ) ;
19+ }
20+
21+ return launchOptions ;
22+ }
23+ ) ;
24+ } ;
You can’t perform that action at this time.
0 commit comments