From 44e0c99c15539f29de3b7c1273de046d8433ad2d Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Fri, 1 Nov 2024 14:12:50 -0400 Subject: [PATCH 01/25] feat: ability to specify the default browser in cypress config file --- cli/types/cypress.d.ts | 5 ++++ packages/data-context/src/DataContext.ts | 6 ++++- .../src/data/ProjectLifecycleManager.ts | 23 +++++++++++++++++-- .../data-context/src/data/coreDataShape.ts | 2 ++ packages/server/lib/modes/index.ts | 2 ++ packages/types/src/modeOptions.ts | 1 + .../config-defaultBrowser/cypress.config.js | 8 +++++++ .../cypress/e2e/spec.cy.js | 3 +++ system-tests/test/config_spec.js | 11 +++++++++ 9 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 system-tests/projects/system-tests/projects/config-defaultBrowser/cypress.config.js create mode 100644 system-tests/projects/system-tests/projects/config-defaultBrowser/system-tests/projects/config-default-browser/cypress/e2e/spec.cy.js diff --git a/cli/types/cypress.d.ts b/cli/types/cypress.d.ts index f0f0c914b1c3..ede618f989db 100644 --- a/cli/types/cypress.d.ts +++ b/cli/types/cypress.d.ts @@ -3216,6 +3216,11 @@ declare namespace Cypress { setupNodeEvents: (on: PluginEvents, config: PluginConfigOptions) => Promise | PluginConfigOptions | void indexHtmlFile: string + + /** + * Set a default browser other than electron when user doesn't pass in "--browser". + */ + defaultBrowser: string } interface EndToEndConfigOptions extends Omit { diff --git a/packages/data-context/src/DataContext.ts b/packages/data-context/src/DataContext.ts index 895dc4d12e4e..8cb90a0bc255 100644 --- a/packages/data-context/src/DataContext.ts +++ b/packages/data-context/src/DataContext.ts @@ -83,7 +83,7 @@ export interface GraphQLRequestInfo { export class DataContext { readonly graphqlRequestInfo?: GraphQLRequestInfo private _config: Omit - private _modeOptions: Readonly> + private _modeOptions: Partial private _coreData: CoreDataShape readonly lifecycleManager: ProjectLifecycleManager @@ -425,4 +425,8 @@ export class DataContext { this.#awaitingEmptyRequestCount.push(resolve) }) } + + setModeOptionsBrowser (browser: string) { + this._modeOptions.browser = browser + } } diff --git a/packages/data-context/src/data/ProjectLifecycleManager.ts b/packages/data-context/src/data/ProjectLifecycleManager.ts index c46d10b5161d..508bc9b94693 100644 --- a/packages/data-context/src/data/ProjectLifecycleManager.ts +++ b/packages/data-context/src/data/ProjectLifecycleManager.ts @@ -308,10 +308,29 @@ export class ProjectLifecycleManager { /** * Sets the initial `activeBrowser` depending on these criteria, in order of preference: * 1. The value of `--browser` passed via CLI. - * 2. The last browser selected in `open` mode (by name and channel) for this project. - * 3. The first browser found. + * 2. The value of `defaultBrowser` in `cypress.config`. + * 3. The last browser selected in `open` mode (by name and channel) for this project. + * 4. The first browser found. */ async setInitialActiveBrowser () { + const configBrowser = this.loadedFullConfig?.defaultBrowser + + if (configBrowser && !this.ctx.coreData.isBrowserGivenByCli) { + await this.setActiveBrowserByNameOrPath(configBrowser) + + if (this.ctx.isRunMode) { + this.ctx.setModeOptionsBrowser(configBrowser) + + return + } + + if (this.ctx.coreData.activeBrowser) { + await this.ctx.actions.project.launchProject(this.ctx.coreData.currentTestingType) + } + + return + } + if (this.ctx.coreData.cliBrowser) { await this.setActiveBrowserByNameOrPath(this.ctx.coreData.cliBrowser) diff --git a/packages/data-context/src/data/coreDataShape.ts b/packages/data-context/src/data/coreDataShape.ts index 3e37c90a35ee..3b971862e35f 100644 --- a/packages/data-context/src/data/coreDataShape.ts +++ b/packages/data-context/src/data/coreDataShape.ts @@ -143,6 +143,7 @@ interface CloudDataShape { export interface CoreDataShape { cliBrowser: string | null + isBrowserGivenByCli: boolean cliTestingType: string | null activeBrowser: FoundBrowser | null machineId: Promise @@ -182,6 +183,7 @@ export function makeCoreData (modeOptions: Partial = {}): CoreDa return { servers: {}, cliBrowser: modeOptions.browser ?? null, + isBrowserGivenByCli: modeOptions.isBrowserGivenByCli ?? false, cliTestingType: modeOptions.testingType ?? null, machineId: machineId(), machineBrowsers: null, diff --git a/packages/server/lib/modes/index.ts b/packages/server/lib/modes/index.ts index c542b7d807b9..99b7085e8e5f 100644 --- a/packages/server/lib/modes/index.ts +++ b/packages/server/lib/modes/index.ts @@ -10,6 +10,8 @@ export = (mode, options) => { return require('./smoke_test').run(options) } + options.isBrowserGivenByCli = options.browser !== undefined + if (mode === 'run') { _.defaults(options, { socketId: random.id(10), diff --git a/packages/types/src/modeOptions.ts b/packages/types/src/modeOptions.ts index f8ab17f81ec2..1b8b09e8afea 100644 --- a/packages/types/src/modeOptions.ts +++ b/packages/types/src/modeOptions.ts @@ -1,6 +1,7 @@ export interface CommonModeOptions { _?: (string | null)[] | null invokedFromCli: boolean + isBrowserGivenByCli: boolean userNodePath?: string userNodeVersion?: string configFile?: string | null diff --git a/system-tests/projects/system-tests/projects/config-defaultBrowser/cypress.config.js b/system-tests/projects/system-tests/projects/config-defaultBrowser/cypress.config.js new file mode 100644 index 000000000000..20d060ec1140 --- /dev/null +++ b/system-tests/projects/system-tests/projects/config-defaultBrowser/cypress.config.js @@ -0,0 +1,8 @@ +const { defineConfig } = require('cypress') + +module.exports = defineConfig({ + e2e: { + supportFile: false, + }, + defaultBrowser: 'chrome', +}) diff --git a/system-tests/projects/system-tests/projects/config-defaultBrowser/system-tests/projects/config-default-browser/cypress/e2e/spec.cy.js b/system-tests/projects/system-tests/projects/config-defaultBrowser/system-tests/projects/config-default-browser/cypress/e2e/spec.cy.js new file mode 100644 index 000000000000..434d054dfaa1 --- /dev/null +++ b/system-tests/projects/system-tests/projects/config-defaultBrowser/system-tests/projects/config-default-browser/cypress/e2e/spec.cy.js @@ -0,0 +1,3 @@ +it('works', () => { + expect(1).to.eq(1) +}) diff --git a/system-tests/test/config_spec.js b/system-tests/test/config_spec.js index b71c4a206a37..e139f9b382b3 100644 --- a/system-tests/test/config_spec.js +++ b/system-tests/test/config_spec.js @@ -243,4 +243,15 @@ describe('e2e config', () => { snapshot: true, }) }) + + it('launches browser using config.defaultBrowser', async function () { + await Fixtures.scaffoldProject('config-defaultBrowser') + + return systemTests.exec(this, { + project: 'config-defaultBrowser', + onStdout: (stdout) => { + expect(stdout).to.include('Browser: Chrome') + }, + }) + }) }) From 24e3dda611168f15d6f8e238a220f26b53f75745 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Fri, 1 Nov 2024 14:48:22 -0400 Subject: [PATCH 02/25] don't need setActiveBrowserByNameOrPath for run mode --- packages/data-context/src/data/ProjectLifecycleManager.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/data-context/src/data/ProjectLifecycleManager.ts b/packages/data-context/src/data/ProjectLifecycleManager.ts index 508bc9b94693..021672f44e2d 100644 --- a/packages/data-context/src/data/ProjectLifecycleManager.ts +++ b/packages/data-context/src/data/ProjectLifecycleManager.ts @@ -316,14 +316,14 @@ export class ProjectLifecycleManager { const configBrowser = this.loadedFullConfig?.defaultBrowser if (configBrowser && !this.ctx.coreData.isBrowserGivenByCli) { - await this.setActiveBrowserByNameOrPath(configBrowser) - if (this.ctx.isRunMode) { this.ctx.setModeOptionsBrowser(configBrowser) return } + await this.setActiveBrowserByNameOrPath(configBrowser) + if (this.ctx.coreData.activeBrowser) { await this.ctx.actions.project.launchProject(this.ctx.coreData.currentTestingType) } From f8789abb26ba798cef1e92f8f5d5673cbca556a2 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Fri, 1 Nov 2024 15:17:15 -0400 Subject: [PATCH 03/25] restore readonly on attribute --- packages/data-context/src/DataContext.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/data-context/src/DataContext.ts b/packages/data-context/src/DataContext.ts index 8cb90a0bc255..9d1b9311d3ac 100644 --- a/packages/data-context/src/DataContext.ts +++ b/packages/data-context/src/DataContext.ts @@ -83,7 +83,7 @@ export interface GraphQLRequestInfo { export class DataContext { readonly graphqlRequestInfo?: GraphQLRequestInfo private _config: Omit - private _modeOptions: Partial + private _modeOptions: Readonly> private _coreData: CoreDataShape readonly lifecycleManager: ProjectLifecycleManager @@ -427,6 +427,6 @@ export class DataContext { } setModeOptionsBrowser (browser: string) { - this._modeOptions.browser = browser + (this._modeOptions as Partial).browser = browser } } From 2f828767c3edcd6e9da1a194f006bcb7e3031ef1 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Fri, 1 Nov 2024 16:09:17 -0400 Subject: [PATCH 04/25] simplify cypress open version --- packages/data-context/src/data/ProjectLifecycleManager.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/packages/data-context/src/data/ProjectLifecycleManager.ts b/packages/data-context/src/data/ProjectLifecycleManager.ts index 021672f44e2d..a662a17ebb09 100644 --- a/packages/data-context/src/data/ProjectLifecycleManager.ts +++ b/packages/data-context/src/data/ProjectLifecycleManager.ts @@ -322,13 +322,7 @@ export class ProjectLifecycleManager { return } - await this.setActiveBrowserByNameOrPath(configBrowser) - - if (this.ctx.coreData.activeBrowser) { - await this.ctx.actions.project.launchProject(this.ctx.coreData.currentTestingType) - } - - return + this.ctx.coreData.cliBrowser = configBrowser } if (this.ctx.coreData.cliBrowser) { From 11bd2445813be72c0dbfbcb29df8149a30bd8ae8 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Sun, 3 Nov 2024 06:55:13 -0500 Subject: [PATCH 05/25] put isBrowserGivenByCli on modeOptions (#4) * Update coreDataShape.ts * Update ProjectLifecycleManager.ts --- packages/data-context/src/data/ProjectLifecycleManager.ts | 2 +- packages/data-context/src/data/coreDataShape.ts | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/data-context/src/data/ProjectLifecycleManager.ts b/packages/data-context/src/data/ProjectLifecycleManager.ts index a662a17ebb09..872659e372b2 100644 --- a/packages/data-context/src/data/ProjectLifecycleManager.ts +++ b/packages/data-context/src/data/ProjectLifecycleManager.ts @@ -315,7 +315,7 @@ export class ProjectLifecycleManager { async setInitialActiveBrowser () { const configBrowser = this.loadedFullConfig?.defaultBrowser - if (configBrowser && !this.ctx.coreData.isBrowserGivenByCli) { + if (configBrowser && !this.ctx.modeOptions.isBrowserGivenByCli) { if (this.ctx.isRunMode) { this.ctx.setModeOptionsBrowser(configBrowser) diff --git a/packages/data-context/src/data/coreDataShape.ts b/packages/data-context/src/data/coreDataShape.ts index 3b971862e35f..3e37c90a35ee 100644 --- a/packages/data-context/src/data/coreDataShape.ts +++ b/packages/data-context/src/data/coreDataShape.ts @@ -143,7 +143,6 @@ interface CloudDataShape { export interface CoreDataShape { cliBrowser: string | null - isBrowserGivenByCli: boolean cliTestingType: string | null activeBrowser: FoundBrowser | null machineId: Promise @@ -183,7 +182,6 @@ export function makeCoreData (modeOptions: Partial = {}): CoreDa return { servers: {}, cliBrowser: modeOptions.browser ?? null, - isBrowserGivenByCli: modeOptions.isBrowserGivenByCli ?? false, cliTestingType: modeOptions.testingType ?? null, machineId: machineId(), machineBrowsers: null, From c1fc1b26d97f16644ae37782170aa85bfb0e7605 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Sun, 3 Nov 2024 07:09:29 -0500 Subject: [PATCH 06/25] Update cypress.d.ts --- cli/types/cypress.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/types/cypress.d.ts b/cli/types/cypress.d.ts index ede618f989db..5a5be90b3868 100644 --- a/cli/types/cypress.d.ts +++ b/cli/types/cypress.d.ts @@ -3218,7 +3218,7 @@ declare namespace Cypress { indexHtmlFile: string /** - * Set a default browser other than electron when user doesn't pass in "--browser". + * Set a default browser when user doesn't pass in "--browser". */ defaultBrowser: string } From 66d26b1a42eaf947654272f294dbc1f9d7713b34 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Sun, 3 Nov 2024 09:25:24 -0500 Subject: [PATCH 07/25] use isBrowserGivenByCli only for run mode (#5) * Update modeOptions.ts * Update index.ts * Update ProjectLifecycleManager.ts --- packages/data-context/src/data/ProjectLifecycleManager.ts | 6 +++--- packages/server/lib/modes/index.ts | 3 +-- packages/types/src/modeOptions.ts | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/data-context/src/data/ProjectLifecycleManager.ts b/packages/data-context/src/data/ProjectLifecycleManager.ts index 872659e372b2..2f7eb4dcbeb2 100644 --- a/packages/data-context/src/data/ProjectLifecycleManager.ts +++ b/packages/data-context/src/data/ProjectLifecycleManager.ts @@ -315,14 +315,14 @@ export class ProjectLifecycleManager { async setInitialActiveBrowser () { const configBrowser = this.loadedFullConfig?.defaultBrowser - if (configBrowser && !this.ctx.modeOptions.isBrowserGivenByCli) { - if (this.ctx.isRunMode) { + if (configBrowser) { + if (this.ctx.isRunMode && !this.ctx.modeOptions.isBrowserGivenByCli) { this.ctx.setModeOptionsBrowser(configBrowser) return } - this.ctx.coreData.cliBrowser = configBrowser + this.ctx.coreData.cliBrowser ??= configBrowser } if (this.ctx.coreData.cliBrowser) { diff --git a/packages/server/lib/modes/index.ts b/packages/server/lib/modes/index.ts index 99b7085e8e5f..19376aa29c3e 100644 --- a/packages/server/lib/modes/index.ts +++ b/packages/server/lib/modes/index.ts @@ -10,8 +10,6 @@ export = (mode, options) => { return require('./smoke_test').run(options) } - options.isBrowserGivenByCli = options.browser !== undefined - if (mode === 'run') { _.defaults(options, { socketId: random.id(10), @@ -20,6 +18,7 @@ export = (mode, options) => { quiet: false, morgan: false, report: true, + isBrowserGivenByCli: options.browser !== undefined, }) } diff --git a/packages/types/src/modeOptions.ts b/packages/types/src/modeOptions.ts index 1b8b09e8afea..f12a99399f24 100644 --- a/packages/types/src/modeOptions.ts +++ b/packages/types/src/modeOptions.ts @@ -1,7 +1,6 @@ export interface CommonModeOptions { _?: (string | null)[] | null invokedFromCli: boolean - isBrowserGivenByCli: boolean userNodePath?: string userNodeVersion?: string configFile?: string | null @@ -25,6 +24,7 @@ export interface RunModeOptions extends CommonModeOptions { parallel?: boolean | null ciBuildId?: string | null tag?: (string)[] | null + isBrowserGivenByCli: boolean } export type TestingType = 'e2e' | 'component' From d4a68ba7a7f2b222585e1a5dcb2a7597d2cc5d47 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Sun, 3 Nov 2024 09:33:06 -0500 Subject: [PATCH 08/25] make defaultBrowser more conformant --- packages/data-context/src/data/ProjectLifecycleManager.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/data-context/src/data/ProjectLifecycleManager.ts b/packages/data-context/src/data/ProjectLifecycleManager.ts index 2f7eb4dcbeb2..489c3d92bf29 100644 --- a/packages/data-context/src/data/ProjectLifecycleManager.ts +++ b/packages/data-context/src/data/ProjectLifecycleManager.ts @@ -318,8 +318,6 @@ export class ProjectLifecycleManager { if (configBrowser) { if (this.ctx.isRunMode && !this.ctx.modeOptions.isBrowserGivenByCli) { this.ctx.setModeOptionsBrowser(configBrowser) - - return } this.ctx.coreData.cliBrowser ??= configBrowser From 8028e519987ac741fe99fe67ce5ffb1b0042c3a9 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Sun, 3 Nov 2024 13:30:42 -0500 Subject: [PATCH 09/25] Update CHANGELOG.md --- cli/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index c3b652f883b3..4d8c9fef3dac 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -6,6 +6,7 @@ _Released 11/5/2024 (PENDING)_ **Dependency Updates:** - Updated `@cypress/request` from `3.0.4` to `3.0.6`. Addressed in [#30488](https://github.com/cypress-io/cypress/pull/30488). +- Added ability to specify the default running browser in cypress config. Addresses [#6646](https://github.com/cypress-io/cypress/issues/6646). ## 13.15.1 From 77ffd7a1e2d30d6a572fa2e9a962d22c81474e2f Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Sun, 3 Nov 2024 13:33:08 -0500 Subject: [PATCH 10/25] Update CHANGELOG.md --- cli/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 4d8c9fef3dac..d1875963be52 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -3,6 +3,10 @@ _Released 11/5/2024 (PENDING)_ +**Features:** + +- Added ability to specify the default running browser in cypress config. Addresses [#6646](https://github.com/cypress-io/cypress/issues/6646). + **Dependency Updates:** - Updated `@cypress/request` from `3.0.4` to `3.0.6`. Addressed in [#30488](https://github.com/cypress-io/cypress/pull/30488). From 5d6202de678fe8dc5f02a7d0053cf4241508c64a Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Sun, 3 Nov 2024 13:34:02 -0500 Subject: [PATCH 11/25] Update CHANGELOG.md --- cli/CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index d1875963be52..642cb156b092 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -10,7 +10,6 @@ _Released 11/5/2024 (PENDING)_ **Dependency Updates:** - Updated `@cypress/request` from `3.0.4` to `3.0.6`. Addressed in [#30488](https://github.com/cypress-io/cypress/pull/30488). -- Added ability to specify the default running browser in cypress config. Addresses [#6646](https://github.com/cypress-io/cypress/issues/6646). ## 13.15.1 From d036d96be586f80384a2581f79475296a4fce886 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Mon, 4 Nov 2024 16:48:41 -0500 Subject: [PATCH 12/25] oops (#6) * oops * oops --- .../projects => }/config-defaultBrowser/cypress.config.js | 0 .../cypress/e2e/spec.cy.js | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename system-tests/projects/{system-tests/projects => }/config-defaultBrowser/cypress.config.js (100%) rename system-tests/projects/{system-tests/projects/config-defaultBrowser/system-tests/projects/config-default-browser => config-defaultBrowser}/cypress/e2e/spec.cy.js (100%) diff --git a/system-tests/projects/system-tests/projects/config-defaultBrowser/cypress.config.js b/system-tests/projects/config-defaultBrowser/cypress.config.js similarity index 100% rename from system-tests/projects/system-tests/projects/config-defaultBrowser/cypress.config.js rename to system-tests/projects/config-defaultBrowser/cypress.config.js diff --git a/system-tests/projects/system-tests/projects/config-defaultBrowser/system-tests/projects/config-default-browser/cypress/e2e/spec.cy.js b/system-tests/projects/config-defaultBrowser/cypress/e2e/spec.cy.js similarity index 100% rename from system-tests/projects/system-tests/projects/config-defaultBrowser/system-tests/projects/config-default-browser/cypress/e2e/spec.cy.js rename to system-tests/projects/config-defaultBrowser/cypress/e2e/spec.cy.js From 7aaf2a9059ca5b7300066f57e96e616598f0b3fd Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Wed, 6 Nov 2024 08:20:11 -0500 Subject: [PATCH 13/25] changes (#7) --- packages/config/src/options.ts | 5 +++++ .../projects/config-defaultBrowser/cypress.config.js | 6 ++---- system-tests/test/config_spec.js | 8 +++++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/config/src/options.ts b/packages/config/src/options.ts index 87bfa61496d0..ab760f3dfd5a 100644 --- a/packages/config/src/options.ts +++ b/packages/config/src/options.ts @@ -169,6 +169,11 @@ const driverConfigOptions: Array = [ indexHtmlFile: 'cypress/support/component-index.html', }, validation: isValidConfig, + }, { + name: 'defaultBrowser', + defaultValue: null, + validation: validate.isString, + overrideLevel: 'any', }, { name: 'defaultCommandTimeout', defaultValue: 4000, diff --git a/system-tests/projects/config-defaultBrowser/cypress.config.js b/system-tests/projects/config-defaultBrowser/cypress.config.js index 20d060ec1140..4276ccd434fc 100644 --- a/system-tests/projects/config-defaultBrowser/cypress.config.js +++ b/system-tests/projects/config-defaultBrowser/cypress.config.js @@ -1,8 +1,6 @@ -const { defineConfig } = require('cypress') - -module.exports = defineConfig({ +module.exports = { e2e: { supportFile: false, }, defaultBrowser: 'chrome', -}) +} diff --git a/system-tests/test/config_spec.js b/system-tests/test/config_spec.js index e139f9b382b3..44927b5a6a29 100644 --- a/system-tests/test/config_spec.js +++ b/system-tests/test/config_spec.js @@ -249,8 +249,14 @@ describe('e2e config', () => { return systemTests.exec(this, { project: 'config-defaultBrowser', + + // For when Chrome is actually installed + browser: 'chrome', + + command: 'cypress', + args: ['run', '--dev', '--project', path.resolve(process.cwd(), './projects/config-defaultBrowser')], onStdout: (stdout) => { - expect(stdout).to.include('Browser: Chrome') + expect(stdout).to.include('Browser: Chrome') }, }) }) From b7cb4597818a760645a2dba72df5cbf05b8479db Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Wed, 6 Nov 2024 13:58:43 -0500 Subject: [PATCH 14/25] more test fixes (#8) * make test run with all versions of system-tests * Update index.spec.ts.js * Update index.spec.ts.js * Update utils.spec.ts * Update results_spec.ts.js --- packages/config/__snapshots__/index.spec.ts.js | 3 +++ packages/config/test/project/utils.spec.ts | 2 ++ system-tests/__snapshots__/results_spec.ts.js | 1 + system-tests/test/config_spec.js | 4 ---- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/config/__snapshots__/index.spec.ts.js b/packages/config/__snapshots__/index.spec.ts.js index c366c3230ee0..d119255c38cc 100644 --- a/packages/config/__snapshots__/index.spec.ts.js +++ b/packages/config/__snapshots__/index.spec.ts.js @@ -26,6 +26,7 @@ exports['config/src/index .getDefaultValues returns list of public config keys 1 'specPattern': '**/*.cy.{js,jsx,ts,tsx}', 'indexHtmlFile': 'cypress/support/component-index.html', }, + 'defaultBrowser': null, 'defaultCommandTimeout': 4000, 'downloadsFolder': 'cypress/downloads', 'e2e': { @@ -117,6 +118,7 @@ exports['config/src/index .getDefaultValues returns list of public config keys f 'specPattern': '**/*.cy.{js,jsx,ts,tsx}', 'indexHtmlFile': 'cypress/support/component-index.html', }, + 'defaultBrowser': null, 'defaultCommandTimeout': 4000, 'downloadsFolder': 'cypress/downloads', 'e2e': { @@ -206,6 +208,7 @@ exports['config/src/index .getPublicConfigKeys returns list of public config key 'chromeWebSecurity', 'clientCertificates', 'component', + 'defaultBrowser', 'defaultCommandTimeout', 'downloadsFolder', 'e2e', diff --git a/packages/config/test/project/utils.spec.ts b/packages/config/test/project/utils.spec.ts index 0a3ee14c76b8..2573917929a9 100644 --- a/packages/config/test/project/utils.spec.ts +++ b/packages/config/test/project/utils.spec.ts @@ -1054,6 +1054,7 @@ describe('config/src/project/utils', () => { browsers: { value: [], from: 'default' }, chromeWebSecurity: { value: true, from: 'default' }, clientCertificates: { value: [], from: 'default' }, + defaultBrowser: { value: [null], from: 'default' }, defaultCommandTimeout: { value: 4000, from: 'default' }, downloadsFolder: { value: 'cypress/downloads', from: 'default' }, env: {}, @@ -1152,6 +1153,7 @@ describe('config/src/project/utils', () => { browsers: { value: [], from: 'default' }, chromeWebSecurity: { value: true, from: 'default' }, clientCertificates: { value: [], from: 'default' }, + defaultBrowser: { value: [null], from: 'default' }, defaultCommandTimeout: { value: 4000, from: 'default' }, downloadsFolder: { value: 'cypress/downloads', from: 'default' }, execTimeout: { value: 60000, from: 'default' }, diff --git a/system-tests/__snapshots__/results_spec.ts.js b/system-tests/__snapshots__/results_spec.ts.js index bcc4f872c47e..a81d683240e7 100644 --- a/system-tests/__snapshots__/results_spec.ts.js +++ b/system-tests/__snapshots__/results_spec.ts.js @@ -16,6 +16,7 @@ exports['module api and after:run results'] = ` "blockHosts": null, "chromeWebSecurity": true, "clientCertificates": [], + "defaultBrowser": null, "defaultCommandTimeout": 4000, "downloadsFolder": "/path/to/downloadsFolder", "env": {}, diff --git a/system-tests/test/config_spec.js b/system-tests/test/config_spec.js index 44927b5a6a29..4668c329c8d4 100644 --- a/system-tests/test/config_spec.js +++ b/system-tests/test/config_spec.js @@ -249,10 +249,6 @@ describe('e2e config', () => { return systemTests.exec(this, { project: 'config-defaultBrowser', - - // For when Chrome is actually installed - browser: 'chrome', - command: 'cypress', args: ['run', '--dev', '--project', path.resolve(process.cwd(), './projects/config-defaultBrowser')], onStdout: (stdout) => { From ea6783253b582d8c92b96fea060a112d4af88219 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Wed, 6 Nov 2024 15:19:40 -0500 Subject: [PATCH 15/25] Update utils.spec.ts --- packages/config/test/project/utils.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/config/test/project/utils.spec.ts b/packages/config/test/project/utils.spec.ts index 2573917929a9..a958047b54e8 100644 --- a/packages/config/test/project/utils.spec.ts +++ b/packages/config/test/project/utils.spec.ts @@ -1054,7 +1054,7 @@ describe('config/src/project/utils', () => { browsers: { value: [], from: 'default' }, chromeWebSecurity: { value: true, from: 'default' }, clientCertificates: { value: [], from: 'default' }, - defaultBrowser: { value: [null], from: 'default' }, + defaultBrowser: { value: null, from: 'default' }, defaultCommandTimeout: { value: 4000, from: 'default' }, downloadsFolder: { value: 'cypress/downloads', from: 'default' }, env: {}, @@ -1153,7 +1153,7 @@ describe('config/src/project/utils', () => { browsers: { value: [], from: 'default' }, chromeWebSecurity: { value: true, from: 'default' }, clientCertificates: { value: [], from: 'default' }, - defaultBrowser: { value: [null], from: 'default' }, + defaultBrowser: { value: null, from: 'default' }, defaultCommandTimeout: { value: 4000, from: 'default' }, downloadsFolder: { value: 'cypress/downloads', from: 'default' }, execTimeout: { value: 60000, from: 'default' }, From 4f1cd4da1592abb6c9e455e867145305c962f78b Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Wed, 6 Nov 2024 16:36:41 -0500 Subject: [PATCH 16/25] Update packages/config/src/options.ts Co-authored-by: Matt Schile --- packages/config/src/options.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/config/src/options.ts b/packages/config/src/options.ts index ab760f3dfd5a..fd0afbc5e5eb 100644 --- a/packages/config/src/options.ts +++ b/packages/config/src/options.ts @@ -173,7 +173,6 @@ const driverConfigOptions: Array = [ name: 'defaultBrowser', defaultValue: null, validation: validate.isString, - overrideLevel: 'any', }, { name: 'defaultCommandTimeout', defaultValue: 4000, From 71540557c7ca500d1b94997864b4f666bdc8833b Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Wed, 6 Nov 2024 16:36:58 -0500 Subject: [PATCH 17/25] Update cli/CHANGELOG.md Co-authored-by: Matt Schile --- cli/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 9f0b651ae2ee..242d44fab989 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -5,7 +5,7 @@ _Released 11/5/2024 (PENDING)_ **Features:** -- Added ability to specify the default running browser in cypress config. Addresses [#6646](https://github.com/cypress-io/cypress/issues/6646). +- Added new [`defaultBrowser`](https://docs.cypress.io/app/references/configuration) configuration option to specify the default browser to launch. Addresses [#6646](https://github.com/cypress-io/cypress/issues/6646). **Bugfixes:** From 9a740c4b0c0bfe61b089bd24859d77d7aa19926e Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Wed, 6 Nov 2024 16:37:07 -0500 Subject: [PATCH 18/25] Update cli/types/cypress.d.ts Co-authored-by: Matt Schile --- cli/types/cypress.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/types/cypress.d.ts b/cli/types/cypress.d.ts index 5a5be90b3868..ab1dba589fe2 100644 --- a/cli/types/cypress.d.ts +++ b/cli/types/cypress.d.ts @@ -3218,7 +3218,7 @@ declare namespace Cypress { indexHtmlFile: string /** - * Set a default browser when user doesn't pass in "--browser". + * The default browser to launch if the "--browser" command line option is not provided. */ defaultBrowser: string } From 2dddf0ff3d660ae2f957bb3fe0bc32d7f307367d Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Wed, 6 Nov 2024 16:37:17 -0500 Subject: [PATCH 19/25] Update packages/config/src/options.ts Co-authored-by: Matt Schile --- packages/config/src/options.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/config/src/options.ts b/packages/config/src/options.ts index fd0afbc5e5eb..1e65476b3b65 100644 --- a/packages/config/src/options.ts +++ b/packages/config/src/options.ts @@ -173,6 +173,7 @@ const driverConfigOptions: Array = [ name: 'defaultBrowser', defaultValue: null, validation: validate.isString, + requireRestartOnChange: 'browser', }, { name: 'defaultCommandTimeout', defaultValue: 4000, From 5f1d6b9ed6c42ddf1ea30ee58cb19da458e7a161 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Wed, 6 Nov 2024 16:37:50 -0500 Subject: [PATCH 20/25] Update packages/data-context/src/data/ProjectLifecycleManager.ts Co-authored-by: Matt Schile --- .../data-context/src/data/ProjectLifecycleManager.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/data-context/src/data/ProjectLifecycleManager.ts b/packages/data-context/src/data/ProjectLifecycleManager.ts index 489c3d92bf29..fa93356e1904 100644 --- a/packages/data-context/src/data/ProjectLifecycleManager.ts +++ b/packages/data-context/src/data/ProjectLifecycleManager.ts @@ -315,12 +315,11 @@ export class ProjectLifecycleManager { async setInitialActiveBrowser () { const configBrowser = this.loadedFullConfig?.defaultBrowser - if (configBrowser) { - if (this.ctx.isRunMode && !this.ctx.modeOptions.isBrowserGivenByCli) { - this.ctx.setModeOptionsBrowser(configBrowser) - } - - this.ctx.coreData.cliBrowser ??= configBrowser + // if we have a defaultBrowser from the config and a CLI browser wasn't passed, + // update the cliBrowser to the defaultBrowser from the config + // since we want the defaultBrowser to behave as if it was passed via CLI + if (configBrowser && !this.ctx.modeOptions.isBrowserGivenByCli) { + this.ctx.updateCliBrowser(configBrowser) } if (this.ctx.coreData.cliBrowser) { From adec73195f4fb38f0d168b292a9ab96a1728f1cb Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Wed, 6 Nov 2024 16:53:15 -0500 Subject: [PATCH 21/25] Update DataContext.ts --- packages/data-context/src/DataContext.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/data-context/src/DataContext.ts b/packages/data-context/src/DataContext.ts index 9d1b9311d3ac..4cc66bee7ce5 100644 --- a/packages/data-context/src/DataContext.ts +++ b/packages/data-context/src/DataContext.ts @@ -426,7 +426,8 @@ export class DataContext { }) } - setModeOptionsBrowser (browser: string) { + updateCliBrowser (browser: string) { (this._modeOptions as Partial).browser = browser + this.ctx.coreData.cliBrowser } } From 4425433420fd7488e12a571674413c8083a31d88 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Wed, 6 Nov 2024 16:55:29 -0500 Subject: [PATCH 22/25] Update DataContext.ts --- packages/data-context/src/DataContext.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/data-context/src/DataContext.ts b/packages/data-context/src/DataContext.ts index 4cc66bee7ce5..82576c358df6 100644 --- a/packages/data-context/src/DataContext.ts +++ b/packages/data-context/src/DataContext.ts @@ -428,6 +428,6 @@ export class DataContext { updateCliBrowser (browser: string) { (this._modeOptions as Partial).browser = browser - this.ctx.coreData.cliBrowser + this.coreData.cliBrowser = configBrowser } } From 6933638963be485bc595a1a56c978aaf13c89e12 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Wed, 6 Nov 2024 16:57:24 -0500 Subject: [PATCH 23/25] final oops --- packages/data-context/src/DataContext.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/data-context/src/DataContext.ts b/packages/data-context/src/DataContext.ts index 82576c358df6..66290e3c2d17 100644 --- a/packages/data-context/src/DataContext.ts +++ b/packages/data-context/src/DataContext.ts @@ -428,6 +428,6 @@ export class DataContext { updateCliBrowser (browser: string) { (this._modeOptions as Partial).browser = browser - this.coreData.cliBrowser = configBrowser + this.coreData.cliBrowser = browser } } From 1433cbad14045f915619419566bf323a4bbd05ab Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Fri, 8 Nov 2024 15:13:01 -0500 Subject: [PATCH 24/25] Update options.ts --- packages/config/src/options.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/config/src/options.ts b/packages/config/src/options.ts index 1e65476b3b65..e57db0247b0e 100644 --- a/packages/config/src/options.ts +++ b/packages/config/src/options.ts @@ -184,7 +184,6 @@ const driverConfigOptions: Array = [ defaultValue: 'cypress/downloads', validation: validate.isString, isFolder: true, - requireRestartOnChange: 'browser', }, { name: 'e2e', // e2e runner overrides From 574e3bd49180fd51962bd722817bad82f452feb5 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Fri, 8 Nov 2024 15:19:44 -0500 Subject: [PATCH 25/25] Update DataContext.ts --- packages/data-context/src/DataContext.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/data-context/src/DataContext.ts b/packages/data-context/src/DataContext.ts index 66290e3c2d17..bdb2bee08620 100644 --- a/packages/data-context/src/DataContext.ts +++ b/packages/data-context/src/DataContext.ts @@ -427,7 +427,10 @@ export class DataContext { } updateCliBrowser (browser: string) { - (this._modeOptions as Partial).browser = browser - this.coreData.cliBrowser = browser + // in open mode, prevent cliBrowser from being changed after browser is opened + if (this.isRunMode || !this.coreData.cliBrowser) { + (this._modeOptions as Partial).browser = browser + this.coreData.cliBrowser = browser + } } }