diff --git a/cli/types/cypress.d.ts b/cli/types/cypress.d.ts index 1b6c4fb3e28c..426cb2e3936f 100644 --- a/cli/types/cypress.d.ts +++ b/cli/types/cypress.d.ts @@ -5495,6 +5495,7 @@ declare namespace Cypress { extensions: string[] preferences: { [key: string]: any } args: string[] + env: { [key: string]: any } } interface Dimensions { diff --git a/cli/types/tests/plugins-config.ts b/cli/types/tests/plugins-config.ts index 2292a8e42fa4..bbe8fcc71494 100644 --- a/cli/types/tests/plugins-config.ts +++ b/cli/types/tests/plugins-config.ts @@ -19,6 +19,7 @@ const pluginConfig2: Cypress.PluginConfig = (on, config) => { browser.displayName // $ExpectType string options.extensions // $ExpectType string[] options.args // $ExpectType string[] + options.env // $ExpectType { [key: string]: any; } console.log('launching browser', browser.displayName) return options diff --git a/packages/errors/__snapshot-html__/CONFIG_VALIDATION_ERROR - pluginsFile.html b/packages/errors/__snapshot-html__/BROWSER_UNSUPPORTED_LAUNCH_OPTION.html similarity index 56% rename from packages/errors/__snapshot-html__/CONFIG_VALIDATION_ERROR - pluginsFile.html rename to packages/errors/__snapshot-html__/BROWSER_UNSUPPORTED_LAUNCH_OPTION.html index 8d55d4294883..99ec4e5464ac 100644 --- a/packages/errors/__snapshot-html__/CONFIG_VALIDATION_ERROR - pluginsFile.html +++ b/packages/errors/__snapshot-html__/BROWSER_UNSUPPORTED_LAUNCH_OPTION.html @@ -34,9 +34,7 @@ -
Your pluginsFile at cypress/plugins/index.js set an invalid value:
+ Warning: The following browser launch options were provided but are not supported by electron
-Expected defaultCommandTimeout to be a number.
-
-Instead the value was: false
+ - env
\ No newline at end of file
diff --git a/packages/errors/src/errors.ts b/packages/errors/src/errors.ts
index 073cc28b012b..456915870395 100644
--- a/packages/errors/src/errors.ts
+++ b/packages/errors/src/errors.ts
@@ -90,6 +90,12 @@ export const AllCypressErrors = {
This option will not have an effect in ${fmt.off(_.capitalize(browser))}. Tests that rely on web security being disabled will not run as expected.`
},
+ BROWSER_UNSUPPORTED_LAUNCH_OPTION: (browser: string, options: string[]) => {
+ return errTemplate`\
+ Warning: The following browser launch options were provided but are not supported by ${fmt.highlightSecondary(browser)}
+
+ ${fmt.listItems(options)}`
+ },
BROWSER_NOT_FOUND_BY_NAME: (browser: string, foundBrowsersStr: string[]) => {
let canarySuffix: PartialErr | null = null
diff --git a/packages/errors/test/unit/visualSnapshotErrors_spec.ts b/packages/errors/test/unit/visualSnapshotErrors_spec.ts
index a81dacf282ca..bf5e141f06e1 100644
--- a/packages/errors/test/unit/visualSnapshotErrors_spec.ts
+++ b/packages/errors/test/unit/visualSnapshotErrors_spec.ts
@@ -1206,5 +1206,11 @@ describe('visual error templates', () => {
default: [],
}
},
+
+ BROWSER_UNSUPPORTED_LAUNCH_OPTION: () => {
+ return {
+ default: ['electron', ['env']],
+ }
+ },
})
})
diff --git a/packages/launcher/lib/browsers.ts b/packages/launcher/lib/browsers.ts
index df393a866845..bd91d5f4692d 100644
--- a/packages/launcher/lib/browsers.ts
+++ b/packages/launcher/lib/browsers.ts
@@ -165,7 +165,7 @@ export function launch (
url: string,
debuggingPort: number,
args: string[] = [],
- defaultBrowserEnv = {},
+ browserEnv = {},
) {
debug('launching browser %o', { browser, url })
@@ -181,7 +181,9 @@ export function launch (
// allow setting default env vars such as MOZ_HEADLESS_WIDTH
// but only if it's not already set by the environment
- const env = Object.assign({}, defaultBrowserEnv, process.env)
+ const env = Object.assign({}, browserEnv, process.env)
+
+ debug('spawning browser with environment %o', { env })
const proc = cp.spawn(browser.path, args, { stdio: ['ignore', 'pipe', 'pipe'], env })
diff --git a/packages/server/lib/browsers/chrome.ts b/packages/server/lib/browsers/chrome.ts
index 5bea2301576f..3217e5c1ba02 100644
--- a/packages/server/lib/browsers/chrome.ts
+++ b/packages/server/lib/browsers/chrome.ts
@@ -651,7 +651,7 @@ export = {
// first allows us to connect the remote interface,
// start video recording and then
// we will load the actual page
- const launchedBrowser = await launch(browser, 'about:blank', port, args) as unknown as BrowserInstance & { browserCriClient: BrowserCriClient}
+ const launchedBrowser = await launch(browser, 'about:blank', port, args, launchOptions.env) as unknown as BrowserInstance & { browserCriClient: BrowserCriClient}
la(launchedBrowser, 'did not get launched browser instance')
diff --git a/packages/server/lib/browsers/electron.ts b/packages/server/lib/browsers/electron.ts
index 639c608b0dbf..e56ed3680246 100644
--- a/packages/server/lib/browsers/electron.ts
+++ b/packages/server/lib/browsers/electron.ts
@@ -465,6 +465,18 @@ export = {
throw new Error('Attempting to connect to existing browser for Cypress in Cypress which is not yet implemented for electron')
},
+ validateLaunchOptions (launchOptions: typeof utils.defaultLaunchOptions) {
+ const options: string[] = []
+
+ if (Object.keys(launchOptions.env).length > 0) options.push('env')
+
+ if (launchOptions.args.length > 0) options.push('args')
+
+ if (options.length > 0) {
+ errors.warning('BROWSER_UNSUPPORTED_LAUNCH_OPTION', 'electron', options)
+ }
+ },
+
async open (browser: Browser, url: string, options: BrowserLaunchOpts, automation: Automation) {
debug('open %o', { browser, url })
@@ -486,6 +498,8 @@ export = {
const launchOptions = await utils.executeBeforeBrowserLaunch(browser, defaultLaunchOptions, electronOptions)
+ this.validateLaunchOptions(launchOptions)
+
const { preferences } = launchOptions
debug('launching browser window to url: %s', url)
diff --git a/packages/server/lib/browsers/firefox.ts b/packages/server/lib/browsers/firefox.ts
index ea7db6f5ccea..6bbc42ef4088 100644
--- a/packages/server/lib/browsers/firefox.ts
+++ b/packages/server/lib/browsers/firefox.ts
@@ -536,6 +536,7 @@ export async function open (browser: Browser, url: string, options: BrowserLaunc
// user can overwrite this default with these env vars or --height, --width arguments
MOZ_HEADLESS_WIDTH: '1280',
MOZ_HEADLESS_HEIGHT: '721',
+ ...launchOptions.env,
})
try {
diff --git a/packages/server/lib/browsers/utils.ts b/packages/server/lib/browsers/utils.ts
index cee282e2b593..03e240dce50a 100644
--- a/packages/server/lib/browsers/utils.ts
+++ b/packages/server/lib/browsers/utils.ts
@@ -46,10 +46,12 @@ const defaultLaunchOptions: {
preferences: {[key: string]: any}
extensions: string[]
args: string[]
+ env: {[key: string]: any}
} = {
preferences: {},
extensions: [],
args: [],
+ env: {},
}
const KNOWN_LAUNCH_OPTION_PROPERTIES = _.keys(defaultLaunchOptions)
diff --git a/packages/server/lib/browsers/webkit.ts b/packages/server/lib/browsers/webkit.ts
index 1444807bff84..534cff80347d 100644
--- a/packages/server/lib/browsers/webkit.ts
+++ b/packages/server/lib/browsers/webkit.ts
@@ -70,6 +70,7 @@ export async function open (browser: Browser, url: string, options: BrowserLaunc
},
extensions: [],
args: [],
+ env: {},
}
const launchOptions = await utils.executeBeforeBrowserLaunch(browser, defaultLaunchOptions, options)
diff --git a/system-tests/__snapshots__/deprecated_spec.ts.js b/system-tests/__snapshots__/deprecated_spec.ts.js
index 3550aa5aace0..4424fdfd9e53 100644
--- a/system-tests/__snapshots__/deprecated_spec.ts.js
+++ b/system-tests/__snapshots__/deprecated_spec.ts.js
@@ -26,6 +26,7 @@ launchOptions may only contain the properties:
- preferences
- extensions
- args
+ - env
https://on.cypress.io/browser-launch-api
@@ -91,7 +92,7 @@ This code will not work in a future version of Cypress. Please see the upgrade g
`
-exports['deprecated before:browser:launch args / using non-deprecated API - no warning'] = `
+exports['deprecated before:browser:launch args / concat return returns once per spec - [electron]'] = `
====================================================================================================
@@ -100,14 +101,24 @@ exports['deprecated before:browser:launch args / using non-deprecated API - no w
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
- │ Specs: 1 found (app.cy.js) │
- │ Searched: cypress/e2e/app.cy.js │
+ │ Specs: 2 found (app.cy.js, app_spec2.js) │
+ │ Searched: cypress/e2e/app.cy.js, cypress/e2e/app_spec2.js │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
- Running: app.cy.js (1 of 1)
+ Running: app.cy.js (1 of 2)
+Deprecation Warning: The before:browser:launch plugin event changed its signature in Cypress version 4.0.0
+
+The event switched from yielding the second argument as an array of browser arguments to an options object with an args property.
+
+We've detected that your code is still using the previous, deprecated interface signature.
+
+This code will not work in a future version of Cypress. Please see the upgrade guide: https://on.cypress.io/deprecated-before-browser-launch-args
+Warning: The following browser launch options were provided but are not supported by electron
+
+ - args
✓ asserts on browser args
@@ -130,6 +141,41 @@ exports['deprecated before:browser:launch args / using non-deprecated API - no w
└────────────────────────────────────────────────────────────────────────────────────────────────┘
+────────────────────────────────────────────────────────────────────────────────────────────────────
+
+ Running: app_spec2.js (2 of 2)
+Deprecation Warning: The before:browser:launch plugin event changed its signature in Cypress version 4.0.0
+
+The event switched from yielding the second argument as an array of browser arguments to an options object with an args property.
+
+We've detected that your code is still using the previous, deprecated interface signature.
+
+This code will not work in a future version of Cypress. Please see the upgrade guide: https://on.cypress.io/deprecated-before-browser-launch-args
+Warning: The following browser launch options were provided but are not supported by electron
+
+ - args
+
+
+ ✓ 2 - asserts on browser args
+
+ 1 passing
+
+
+ (Results)
+
+ ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
+ │ Tests: 1 │
+ │ Passing: 1 │
+ │ Failing: 0 │
+ │ Pending: 0 │
+ │ Skipped: 0 │
+ │ Screenshots: 0 │
+ │ Video: false │
+ │ Duration: X seconds │
+ │ Spec Ran: app_spec2.js │
+ └────────────────────────────────────────────────────────────────────────────────────────────────┘
+
+
====================================================================================================
(Run Finished)
@@ -138,13 +184,15 @@ exports['deprecated before:browser:launch args / using non-deprecated API - no w
Spec Tests Passing Failing Pending Skipped
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ ✔ app.cy.js XX:XX 1 1 - - - │
+ ├────────────────────────────────────────────────────────────────────────────────────────────────┤
+ │ ✔ app_spec2.js XX:XX 1 1 - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
- ✔ All specs passed! XX:XX 1 1 - - -
+ ✔ All specs passed! XX:XX 2 2 - - -
`
-exports['deprecated before:browser:launch args / concat return returns once per spec - [electron]'] = `
+exports['deprecated before:browser:launch args / displays errors thrown and aborts the run'] = `
====================================================================================================
@@ -161,13 +209,53 @@ exports['deprecated before:browser:launch args / concat return returns once per
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: app.cy.js (1 of 2)
-Deprecation Warning: The before:browser:launch plugin event changed its signature in Cypress version 4.0.0
+Error thrown from plugins handler
+Error: Error thrown from plugins handler
+ [stack trace lines]
+`
-The event switched from yielding the second argument as an array of browser arguments to an options object with an args property.
+exports['deprecated before:browser:launch args / displays promises rejected and aborts the run'] = `
-We've detected that your code is still using the previous, deprecated interface signature.
+====================================================================================================
-This code will not work in a future version of Cypress. Please see the upgrade guide: https://on.cypress.io/deprecated-before-browser-launch-args
+ (Run Starting)
+
+ ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
+ │ Cypress: 1.2.3 │
+ │ Browser: FooBrowser 88 │
+ │ Specs: 2 found (app.cy.js, app_spec2.js) │
+ │ Searched: cypress/e2e/app.cy.js, cypress/e2e/app_spec2.js │
+ └────────────────────────────────────────────────────────────────────────────────────────────────┘
+
+
+────────────────────────────────────────────────────────────────────────────────────────────────────
+
+ Running: app.cy.js (1 of 2)
+Promise rejected from plugins handler
+Error: Promise rejected from plugins handler
+ [stack trace lines]
+`
+
+exports['deprecated before:browser:launch args / using non-deprecated API - no warning - [electron]'] = `
+
+====================================================================================================
+
+ (Run Starting)
+
+ ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
+ │ Cypress: 1.2.3 │
+ │ Browser: FooBrowser 88 │
+ │ Specs: 1 found (app.cy.js) │
+ │ Searched: cypress/e2e/app.cy.js │
+ └────────────────────────────────────────────────────────────────────────────────────────────────┘
+
+
+────────────────────────────────────────────────────────────────────────────────────────────────────
+
+ Running: app.cy.js (1 of 1)
+Warning: The following browser launch options were provided but are not supported by electron
+
+ - args
✓ asserts on browser args
@@ -190,19 +278,40 @@ This code will not work in a future version of Cypress. Please see the upgrade g
└────────────────────────────────────────────────────────────────────────────────────────────────┘
-────────────────────────────────────────────────────────────────────────────────────────────────────
-
- Running: app_spec2.js (2 of 2)
-Deprecation Warning: The before:browser:launch plugin event changed its signature in Cypress version 4.0.0
+====================================================================================================
-The event switched from yielding the second argument as an array of browser arguments to an options object with an args property.
+ (Run Finished)
-We've detected that your code is still using the previous, deprecated interface signature.
-This code will not work in a future version of Cypress. Please see the upgrade guide: https://on.cypress.io/deprecated-before-browser-launch-args
+ Spec Tests Passing Failing Pending Skipped
+ ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
+ │ ✔ app.cy.js XX:XX 1 1 - - - │
+ └────────────────────────────────────────────────────────────────────────────────────────────────┘
+ ✔ All specs passed! XX:XX 1 1 - - -
- ✓ 2 - asserts on browser args
+`
+
+exports['deprecated before:browser:launch args / using non-deprecated API - no warning - [firefox,chromium]'] = `
+
+====================================================================================================
+
+ (Run Starting)
+
+ ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
+ │ Cypress: 1.2.3 │
+ │ Browser: FooBrowser 88 │
+ │ Specs: 1 found (app.cy.js) │
+ │ Searched: cypress/e2e/app.cy.js │
+ └────────────────────────────────────────────────────────────────────────────────────────────────┘
+
+
+────────────────────────────────────────────────────────────────────────────────────────────────────
+
+ Running: app.cy.js (1 of 1)
+
+
+ ✓ asserts on browser args
1 passing
@@ -218,7 +327,7 @@ This code will not work in a future version of Cypress. Please see the upgrade g
│ Screenshots: 0 │
│ Video: false │
│ Duration: X seconds │
- │ Spec Ran: app_spec2.js │
+ │ Spec Ran: app.cy.js │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
@@ -230,10 +339,8 @@ This code will not work in a future version of Cypress. Please see the upgrade g
Spec Tests Passing Failing Pending Skipped
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ ✔ app.cy.js XX:XX 1 1 - - - │
- ├────────────────────────────────────────────────────────────────────────────────────────────────┤
- │ ✔ app_spec2.js XX:XX 1 1 - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
- ✔ All specs passed! XX:XX 2 2 - - -
+ ✔ All specs passed! XX:XX 1 1 - - -
`
@@ -325,7 +432,7 @@ This code will not work in a future version of Cypress. Please see the upgrade g
`
-exports['deprecated before:browser:launch args / no mutate return'] = `
+exports['deprecated before:browser:launch args / concat return returns once per test run - [firefox,chromium]'] = `
====================================================================================================
@@ -334,14 +441,21 @@ exports['deprecated before:browser:launch args / no mutate return'] = `
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
- │ Specs: 1 found (app.cy.js) │
- │ Searched: cypress/e2e/app.cy.js │
+ │ Specs: 2 found (app.cy.js, app_spec2.js) │
+ │ Searched: cypress/e2e/app.cy.js, cypress/e2e/app_spec2.js │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
- Running: app.cy.js (1 of 1)
+ Running: app.cy.js (1 of 2)
+Deprecation Warning: The before:browser:launch plugin event changed its signature in Cypress version 4.0.0
+
+The event switched from yielding the second argument as an array of browser arguments to an options object with an args property.
+
+We've detected that your code is still using the previous, deprecated interface signature.
+
+This code will not work in a future version of Cypress. Please see the upgrade guide: https://on.cypress.io/deprecated-before-browser-launch-args
✓ asserts on browser args
@@ -364,60 +478,43 @@ exports['deprecated before:browser:launch args / no mutate return'] = `
└────────────────────────────────────────────────────────────────────────────────────────────────┘
-====================================================================================================
-
- (Run Finished)
-
-
- Spec Tests Passing Failing Pending Skipped
- ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
- │ ✔ app.cy.js XX:XX 1 1 - - - │
- └────────────────────────────────────────────────────────────────────────────────────────────────┘
- ✔ All specs passed! XX:XX 1 1 - - -
+────────────────────────────────────────────────────────────────────────────────────────────────────
+
+ Running: app_spec2.js (2 of 2)
-`
+ ✓ 2 - asserts on browser args
-exports['deprecated before:browser:launch args / displays errors thrown and aborts the run'] = `
+ 1 passing
-====================================================================================================
- (Run Starting)
+ (Results)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
- │ Cypress: 1.2.3 │
- │ Browser: FooBrowser 88 │
- │ Specs: 2 found (app.cy.js, app_spec2.js) │
- │ Searched: cypress/e2e/app.cy.js, cypress/e2e/app_spec2.js │
+ │ Tests: 1 │
+ │ Passing: 1 │
+ │ Failing: 0 │
+ │ Pending: 0 │
+ │ Skipped: 0 │
+ │ Screenshots: 0 │
+ │ Video: false │
+ │ Duration: X seconds │
+ │ Spec Ran: app_spec2.js │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
-────────────────────────────────────────────────────────────────────────────────────────────────────
-
- Running: app.cy.js (1 of 2)
-Error thrown from plugins handler
-Error: Error thrown from plugins handler
- [stack trace lines]
-`
-
-exports['deprecated before:browser:launch args / displays promises rejected and aborts the run'] = `
-
====================================================================================================
- (Run Starting)
+ (Run Finished)
+
+ Spec Tests Passing Failing Pending Skipped
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
- │ Cypress: 1.2.3 │
- │ Browser: FooBrowser 88 │
- │ Specs: 2 found (app.cy.js, app_spec2.js) │
- │ Searched: cypress/e2e/app.cy.js, cypress/e2e/app_spec2.js │
+ │ ✔ app.cy.js XX:XX 1 1 - - - │
+ ├────────────────────────────────────────────────────────────────────────────────────────────────┤
+ │ ✔ app_spec2.js XX:XX 1 1 - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
+ ✔ All specs passed! XX:XX 2 2 - - -
-────────────────────────────────────────────────────────────────────────────────────────────────────
-
- Running: app.cy.js (1 of 2)
-Promise rejected from plugins handler
-Error: Promise rejected from plugins handler
- [stack trace lines]
`
diff --git a/system-tests/test/deprecated_spec.ts b/system-tests/test/deprecated_spec.ts
index 36ec1b5aabf9..d159a69f3f7e 100644
--- a/system-tests/test/deprecated_spec.ts
+++ b/system-tests/test/deprecated_spec.ts
@@ -60,6 +60,13 @@ describe('deprecated before:browser:launch args', () => {
project: beforeBrowserLaunchProject,
spec: 'app.cy.js',
snapshot: true,
+ onRun: (exec, browser) => {
+ if (browser === 'electron') {
+ return exec({ originalTitle: `deprecated before:browser:launch args / using non-deprecated API - no warning - [electron]` })
+ }
+
+ return exec({ originalTitle: `deprecated before:browser:launch args / using non-deprecated API - no warning - [firefox,chromium]` })
+ },
onStdout: excludesString('Deprecation Warning:'),
})