From 11ee6865e05fd95fb0edc444b930ca8f93bf151c Mon Sep 17 00:00:00 2001 From: Ayagoumi Date: Fri, 22 Sep 2023 10:31:31 +0100 Subject: [PATCH] feat(cypress): enhance browser launch setup for headless Chrome --- cypress.config.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/cypress.config.ts b/cypress.config.ts index 2cca22874..de51d36d2 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -4,11 +4,26 @@ import parseEnvPlugin from './cypress/plugins' import webpack from 'webpack' const webpackPreprocessor = require('@cypress/webpack-preprocessor') +function customBrowserLaunch(on, config) { + on('before:browser:launch', (browser, launchOptions) => { + if (browser.name === 'chrome' && browser.isHeadless) { + const headlessIndex = launchOptions.args.indexOf('--headless') + if (headlessIndex > -1) { + launchOptions.args[headlessIndex] = '--headless=new' + } + } + return launchOptions + }) + return require('./cypress/plugins/index.ts')(on, config) +} + export default defineConfig({ e2e: { // We've imported your old cypress plugins here. // You may want to clean this up later by importing these. setupNodeEvents(on, config) { + customBrowserLaunch(on, config) + const options = { webpackOptions: { resolve: { @@ -52,6 +67,6 @@ export default defineConfig({ grepTags: '', grepFilterSpecs: true, grepOmitFiltered: true, - grepUntagged: true + grepUntagged: true, }, })