From 44e0c99c15539f29de3b7c1273de046d8433ad2d Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Fri, 1 Nov 2024 14:12:50 -0400 Subject: [PATCH 01/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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 2a53ba0a9a50de8de8bd62bfb02bdb8afeccf788 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Fri, 8 Nov 2024 15:21:37 -0500 Subject: [PATCH 24/45] remove requireRestartOnChange for defaultBrowser, prevent bad open mode behavior (#9) * Update options.ts * Update DataContext.ts --- packages/config/src/options.ts | 1 - packages/data-context/src/DataContext.ts | 7 +++++-- 2 files changed, 5 insertions(+), 3 deletions(-) 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 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 + } } } From fd9c123d37dc610db0f9d9139470d19b955962c5 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Fri, 8 Nov 2024 15:28:01 -0500 Subject: [PATCH 25/45] oops --- packages/config/src/options.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/config/src/options.ts b/packages/config/src/options.ts index e57db0247b0e..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, - requireRestartOnChange: 'browser', }, { name: 'defaultCommandTimeout', defaultValue: 4000, @@ -184,6 +183,7 @@ const driverConfigOptions: Array = [ defaultValue: 'cypress/downloads', validation: validate.isString, isFolder: true, + requireRestartOnChange: 'browser', }, { name: 'e2e', // e2e runner overrides From 44653034a1d9ced7048ae050724addfb414505f0 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Tue, 12 Nov 2024 12:37:34 -0500 Subject: [PATCH 26/45] organization changes (#10) * Update DataContext.ts * Update BrowserActions.ts * Update ProjectLifecycleManager.ts --- packages/data-context/src/DataContext.ts | 8 ++------ packages/data-context/src/actions/BrowserActions.ts | 5 +++++ .../data-context/src/data/ProjectLifecycleManager.ts | 9 ++++++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/data-context/src/DataContext.ts b/packages/data-context/src/DataContext.ts index bdb2bee08620..4fe623c15e53 100644 --- a/packages/data-context/src/DataContext.ts +++ b/packages/data-context/src/DataContext.ts @@ -426,11 +426,7 @@ export class DataContext { }) } - updateCliBrowser (browser: string) { - // 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 - } + updateModeOptionsBrowser (browser: string) { + (this.modeOptions as Partial).browser = browser } } diff --git a/packages/data-context/src/actions/BrowserActions.ts b/packages/data-context/src/actions/BrowserActions.ts index a78dd045cff9..b6b37885661e 100644 --- a/packages/data-context/src/actions/BrowserActions.ts +++ b/packages/data-context/src/actions/BrowserActions.ts @@ -40,6 +40,11 @@ export class BrowserActions { }) } + updateCliBrowser (browser: string) { + this.ctx.updateModeOptionsBrowser(browser) + this.ctx.coreData.cliBrowser = browser + } + async focusActiveBrowserWindow () { await this.browserApi.focusActiveBrowserWindow() } diff --git a/packages/data-context/src/data/ProjectLifecycleManager.ts b/packages/data-context/src/data/ProjectLifecycleManager.ts index fa93356e1904..bdfab89fe5d0 100644 --- a/packages/data-context/src/data/ProjectLifecycleManager.ts +++ b/packages/data-context/src/data/ProjectLifecycleManager.ts @@ -315,11 +315,14 @@ export class ProjectLifecycleManager { async setInitialActiveBrowser () { const configBrowser = this.loadedFullConfig?.defaultBrowser - // if we have a defaultBrowser from the config and a CLI browser wasn't passed, + // if we have a defaultBrowser from the config and a CLI browser wasn't passed and, + // we are in run mode or the CLI browser isn't set (prevents changing the browser in open mode when the config changes), // 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) + const shouldUpdateCliBrowser = (configBrowser && !this.ctx.modeOptions.isBrowserGivenByCli) && + (this.ctx.isRunMode || this.ctx.coreData.cliBrowser) + if (shouldUpdateCliBrowser) { + this.ctx.actions.browser.updateCliBrowser(configBrowser) } if (this.ctx.coreData.cliBrowser) { From 072ca63992ab56e5c7492758d32478a4caf18bd3 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Tue, 12 Nov 2024 12:42:35 -0500 Subject: [PATCH 27/45] fixed --- packages/data-context/src/data/ProjectLifecycleManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/data-context/src/data/ProjectLifecycleManager.ts b/packages/data-context/src/data/ProjectLifecycleManager.ts index bdfab89fe5d0..ec55638cd9c2 100644 --- a/packages/data-context/src/data/ProjectLifecycleManager.ts +++ b/packages/data-context/src/data/ProjectLifecycleManager.ts @@ -320,7 +320,7 @@ export class ProjectLifecycleManager { // update the cliBrowser to the defaultBrowser from the config // since we want the defaultBrowser to behave as if it was passed via CLI const shouldUpdateCliBrowser = (configBrowser && !this.ctx.modeOptions.isBrowserGivenByCli) && - (this.ctx.isRunMode || this.ctx.coreData.cliBrowser) + (this.ctx.isRunMode || !this.ctx.coreData.cliBrowser) if (shouldUpdateCliBrowser) { this.ctx.actions.browser.updateCliBrowser(configBrowser) } From 9e88d67828c87fd7bad66b4ec88eb0ac6ee3b2a1 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Tue, 12 Nov 2024 13:49:10 -0500 Subject: [PATCH 28/45] if activeBrowser is already set, make sure the label is correct --- .../data-context/src/data/ProjectLifecycleManager.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/data-context/src/data/ProjectLifecycleManager.ts b/packages/data-context/src/data/ProjectLifecycleManager.ts index ec55638cd9c2..0d9512a9ff40 100644 --- a/packages/data-context/src/data/ProjectLifecycleManager.ts +++ b/packages/data-context/src/data/ProjectLifecycleManager.ts @@ -316,13 +316,15 @@ export class ProjectLifecycleManager { const configBrowser = this.loadedFullConfig?.defaultBrowser // if we have a defaultBrowser from the config and a CLI browser wasn't passed and, - // we are in run mode or the CLI browser isn't set (prevents changing the browser in open mode when the config changes), + // the active browser isn't set (we are in run mode or when the config changes in open mode), // update the cliBrowser to the defaultBrowser from the config // since we want the defaultBrowser to behave as if it was passed via CLI - const shouldUpdateCliBrowser = (configBrowser && !this.ctx.modeOptions.isBrowserGivenByCli) && - (this.ctx.isRunMode || !this.ctx.coreData.cliBrowser) - if (shouldUpdateCliBrowser) { - this.ctx.actions.browser.updateCliBrowser(configBrowser) + if (this.ctx.isRunMode || !this.ctx.coreData.cliBrowser) { + if (!this.ctx.coreData.activeBrowser) { + this.ctx.actions.browser.updateCliBrowser(configBrowser) + } else { + this.ctx.actions.browser.updateCliBrowser(this.ctx.coreData.activeBrowser.name) + } } if (this.ctx.coreData.cliBrowser) { From acad76af88c24d58a530bf26f23c55d9e0e1b3e9 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Tue, 12 Nov 2024 13:52:22 -0500 Subject: [PATCH 29/45] oops --- packages/data-context/src/data/ProjectLifecycleManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/data-context/src/data/ProjectLifecycleManager.ts b/packages/data-context/src/data/ProjectLifecycleManager.ts index 0d9512a9ff40..837e87a36b55 100644 --- a/packages/data-context/src/data/ProjectLifecycleManager.ts +++ b/packages/data-context/src/data/ProjectLifecycleManager.ts @@ -319,7 +319,7 @@ export class ProjectLifecycleManager { // the active browser isn't set (we are in run mode or when the config changes in open mode), // update the cliBrowser to the defaultBrowser from the config // since we want the defaultBrowser to behave as if it was passed via CLI - if (this.ctx.isRunMode || !this.ctx.coreData.cliBrowser) { + if (configBrowser && !this.ctx.modeOptions.isBrowserGivenByCli) { if (!this.ctx.coreData.activeBrowser) { this.ctx.actions.browser.updateCliBrowser(configBrowser) } else { From 973932c9c09234dacf72820bb3c429987eaec783 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Tue, 12 Nov 2024 15:24:07 -0500 Subject: [PATCH 30/45] Update ProjectLifecycleManager.spec.ts --- .../unit/data/ProjectLifecycleManager.spec.ts | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/packages/data-context/test/unit/data/ProjectLifecycleManager.spec.ts b/packages/data-context/test/unit/data/ProjectLifecycleManager.spec.ts index b526cc529194..349bce0ee479 100644 --- a/packages/data-context/test/unit/data/ProjectLifecycleManager.spec.ts +++ b/packages/data-context/test/unit/data/ProjectLifecycleManager.spec.ts @@ -94,6 +94,36 @@ describe('ProjectLifecycleManager', () => { expect(ctx.coreData.activeBrowser).to.include({ name: 'electron' }) expect(ctx.actions.project.launchProject).to.not.be.called }) + + it('uses config defaultBrowser option', async () => { + ctx = createDataContext({ + project: 'foo', + testingType: 'e2e', + }) + + // @ts-expect-error + ctx.lifecycleManager._configManager = { + // @ts-expect-error + getFullInitialConfig() { + return { + browsers: [], + } + } + } + + Object.defineProperty(ctx.lifecycleManager, 'loadedFullConfig', { + get() { + return { + defaultBrowser: 'chrome' + } + } + }) + + await ctx.lifecycleManager.setInitialActiveBrowser() + + expect(ctx.modeOptions.browser).to.eq('chrome') + expect(ctx.coreData.cliBrowser).to.eq('chrome') + }) }) context('#eventProcessPid', () => { From 61071cfd0dbfb7c0377b44ef1b9bbd16d8e07222 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Tue, 12 Nov 2024 15:35:40 -0500 Subject: [PATCH 31/45] Update ProjectLifecycleManager.spec.ts --- .../unit/data/ProjectLifecycleManager.spec.ts | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/packages/data-context/test/unit/data/ProjectLifecycleManager.spec.ts b/packages/data-context/test/unit/data/ProjectLifecycleManager.spec.ts index 349bce0ee479..f201b6b57e58 100644 --- a/packages/data-context/test/unit/data/ProjectLifecycleManager.spec.ts +++ b/packages/data-context/test/unit/data/ProjectLifecycleManager.spec.ts @@ -95,10 +95,11 @@ describe('ProjectLifecycleManager', () => { expect(ctx.actions.project.launchProject).to.not.be.called }) - it('uses config defaultBrowser option', async () => { + it('uses config defaultBrowser option if --browser is not given', async () => { ctx = createDataContext({ project: 'foo', testingType: 'e2e', + isBrowserGivenByCli: false }) // @ts-expect-error @@ -124,6 +125,37 @@ describe('ProjectLifecycleManager', () => { expect(ctx.modeOptions.browser).to.eq('chrome') expect(ctx.coreData.cliBrowser).to.eq('chrome') }) + + it('doesn\'t use config defaultBrowser option if --browser is given', async () => { + ctx = createDataContext({ + project: 'foo', + testingType: 'e2e', + isBrowserGivenByCli: true + }) + + // @ts-expect-error + ctx.lifecycleManager._configManager = { + // @ts-expect-error + getFullInitialConfig() { + return { + browsers: [], + } + } + } + + Object.defineProperty(ctx.lifecycleManager, 'loadedFullConfig', { + get() { + return { + defaultBrowser: 'chrome' + } + } + }) + + await ctx.lifecycleManager.setInitialActiveBrowser() + + expect(ctx.modeOptions.browser).to.eq(undefined) + expect(ctx.coreData.cliBrowser).to.eq(undefined) + }) }) context('#eventProcessPid', () => { From 1beecad801b70e58cd3748f0fa56e677699bb07e Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Tue, 12 Nov 2024 15:43:32 -0500 Subject: [PATCH 32/45] Update CHANGELOG.md --- cli/CHANGELOG.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 6beb5646a4aa..7607ba88ade9 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -1,12 +1,16 @@ -## 13.15.2 +## 13.15.3 -_Released 11/5/2024_ +_Released xx/xx/xxxx_ **Features:** - 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). +## 13.15.2 + +_Released 11/5/2024_ + **Bugfixes:** - Fixed an issue where the Cypress runner could hang in `after` or `afterEach` hooks that run Cypress commands after a page load timeout error occurs. Addresses [#30238](https://github.com/cypress-io/cypress/issues/30238). From ea704aa5f49476f8608d546bf509f5e136ecfcaa Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Tue, 12 Nov 2024 15:44:18 -0500 Subject: [PATCH 33/45] Update CHANGELOG.md --- cli/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 7607ba88ade9..0af627f22725 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -1,7 +1,7 @@ ## 13.15.3 -_Released xx/xx/xxxx_ +_Released xx/xx/xxxx (PENDING)_ **Features:** From fb000dfec0ed2b6734e45948530a8fa9faaa6cee Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Tue, 12 Nov 2024 15:47:39 -0500 Subject: [PATCH 34/45] Update CHANGELOG.md --- cli/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 0af627f22725..2902e127ad4c 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -1,7 +1,7 @@ ## 13.15.3 -_Released xx/xx/xxxx (PENDING)_ +_Released 12/31/2025 (PENDING)_ **Features:** From e3c754dbd6fe9d12bfd75606f7f43ebfc7a52785 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Tue, 12 Nov 2024 17:44:38 -0500 Subject: [PATCH 35/45] hopefully fix lint, add to test --- .../unit/data/ProjectLifecycleManager.spec.ts | 40 +++++++++++++------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/packages/data-context/test/unit/data/ProjectLifecycleManager.spec.ts b/packages/data-context/test/unit/data/ProjectLifecycleManager.spec.ts index f201b6b57e58..989d2de5bc23 100644 --- a/packages/data-context/test/unit/data/ProjectLifecycleManager.spec.ts +++ b/packages/data-context/test/unit/data/ProjectLifecycleManager.spec.ts @@ -99,29 +99,37 @@ describe('ProjectLifecycleManager', () => { ctx = createDataContext({ project: 'foo', testingType: 'e2e', - isBrowserGivenByCli: false + isBrowserGivenByCli: false, }) // @ts-expect-error ctx.lifecycleManager._configManager = { // @ts-expect-error - getFullInitialConfig() { + getFullInitialConfig () { return { browsers: [], } - } + }, + } + + // @ts-expect-error + ctx._apis.browserApi.ensureAndGetByNameOrPath = function () { + return browsers[0] } Object.defineProperty(ctx.lifecycleManager, 'loadedFullConfig', { - get() { + get () { return { - defaultBrowser: 'chrome' + defaultBrowser: 'chrome', } - } + }, }) + expect(ctx.modeOptions.activeBrowser).to.eq(undefined) + await ctx.lifecycleManager.setInitialActiveBrowser() + expect(ctx.modeOptions.activeBrowser).to.include({ name: 'chrome' }) expect(ctx.modeOptions.browser).to.eq('chrome') expect(ctx.coreData.cliBrowser).to.eq('chrome') }) @@ -130,29 +138,37 @@ describe('ProjectLifecycleManager', () => { ctx = createDataContext({ project: 'foo', testingType: 'e2e', - isBrowserGivenByCli: true + isBrowserGivenByCli: true, }) // @ts-expect-error ctx.lifecycleManager._configManager = { // @ts-expect-error - getFullInitialConfig() { + getFullInitialConfig () { return { browsers: [], } - } + }, + } + + // @ts-expect-error + ctx._apis.browserApi.ensureAndGetByNameOrPath = function () { + return browsers[0] } Object.defineProperty(ctx.lifecycleManager, 'loadedFullConfig', { - get() { + get () { return { - defaultBrowser: 'chrome' + defaultBrowser: 'chrome', } - } + }, }) + expect(ctx.modeOptions.activeBrowser).to.eq(undefined) + await ctx.lifecycleManager.setInitialActiveBrowser() + expect(ctx.modeOptions.activeBrowser).to.include({ name: 'electron' }) expect(ctx.modeOptions.browser).to.eq(undefined) expect(ctx.coreData.cliBrowser).to.eq(undefined) }) From f550b4cc7b21f72cf81dbaa1b49167d966932b24 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Tue, 12 Nov 2024 17:46:01 -0500 Subject: [PATCH 36/45] Update ProjectLifecycleManager.spec.ts --- .../test/unit/data/ProjectLifecycleManager.spec.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/data-context/test/unit/data/ProjectLifecycleManager.spec.ts b/packages/data-context/test/unit/data/ProjectLifecycleManager.spec.ts index 989d2de5bc23..2fde5bb7a0b7 100644 --- a/packages/data-context/test/unit/data/ProjectLifecycleManager.spec.ts +++ b/packages/data-context/test/unit/data/ProjectLifecycleManager.spec.ts @@ -114,7 +114,8 @@ describe('ProjectLifecycleManager', () => { // @ts-expect-error ctx._apis.browserApi.ensureAndGetByNameOrPath = function () { - return browsers[0] + // return browser object for chrome + return browsers[1] } Object.defineProperty(ctx.lifecycleManager, 'loadedFullConfig', { @@ -153,6 +154,7 @@ describe('ProjectLifecycleManager', () => { // @ts-expect-error ctx._apis.browserApi.ensureAndGetByNameOrPath = function () { + // return browser object for electron return browsers[0] } From 75c30d265076f0cfdb70a38ab307f7a1d67483e2 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Tue, 12 Nov 2024 17:47:24 -0500 Subject: [PATCH 37/45] Update ProjectLifecycleManager.spec.ts --- .../test/unit/data/ProjectLifecycleManager.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/data-context/test/unit/data/ProjectLifecycleManager.spec.ts b/packages/data-context/test/unit/data/ProjectLifecycleManager.spec.ts index 2fde5bb7a0b7..a16c3816796d 100644 --- a/packages/data-context/test/unit/data/ProjectLifecycleManager.spec.ts +++ b/packages/data-context/test/unit/data/ProjectLifecycleManager.spec.ts @@ -130,9 +130,9 @@ describe('ProjectLifecycleManager', () => { await ctx.lifecycleManager.setInitialActiveBrowser() - expect(ctx.modeOptions.activeBrowser).to.include({ name: 'chrome' }) expect(ctx.modeOptions.browser).to.eq('chrome') expect(ctx.coreData.cliBrowser).to.eq('chrome') + expect(ctx.coreData.activeBrowser).to.include({ name: 'chrome' }) }) it('doesn\'t use config defaultBrowser option if --browser is given', async () => { @@ -170,9 +170,9 @@ describe('ProjectLifecycleManager', () => { await ctx.lifecycleManager.setInitialActiveBrowser() - expect(ctx.modeOptions.activeBrowser).to.include({ name: 'electron' }) expect(ctx.modeOptions.browser).to.eq(undefined) expect(ctx.coreData.cliBrowser).to.eq(undefined) + expect(ctx.coreData.activeBrowser).to.include({ name: 'electron' }) }) }) From 337bfb554b7ae822097a0af593fe7efa34f9b8c8 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Tue, 12 Nov 2024 17:49:52 -0500 Subject: [PATCH 38/45] Update ProjectLifecycleManager.spec.ts --- .../test/unit/data/ProjectLifecycleManager.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/data-context/test/unit/data/ProjectLifecycleManager.spec.ts b/packages/data-context/test/unit/data/ProjectLifecycleManager.spec.ts index a16c3816796d..ce4880a8168b 100644 --- a/packages/data-context/test/unit/data/ProjectLifecycleManager.spec.ts +++ b/packages/data-context/test/unit/data/ProjectLifecycleManager.spec.ts @@ -126,7 +126,7 @@ describe('ProjectLifecycleManager', () => { }, }) - expect(ctx.modeOptions.activeBrowser).to.eq(undefined) + expect(ctx.coreData.activeBrowser).to.eq(undefined) await ctx.lifecycleManager.setInitialActiveBrowser() @@ -166,7 +166,7 @@ describe('ProjectLifecycleManager', () => { }, }) - expect(ctx.modeOptions.activeBrowser).to.eq(undefined) + expect(ctx.coreData.activeBrowser).to.eq(undefined) await ctx.lifecycleManager.setInitialActiveBrowser() From d6f72b69c6820fdedb78bbf01f696c6899a464c6 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Tue, 12 Nov 2024 17:55:05 -0500 Subject: [PATCH 39/45] more accurate --- packages/data-context/src/data/ProjectLifecycleManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/data-context/src/data/ProjectLifecycleManager.ts b/packages/data-context/src/data/ProjectLifecycleManager.ts index 837e87a36b55..32b8001efa30 100644 --- a/packages/data-context/src/data/ProjectLifecycleManager.ts +++ b/packages/data-context/src/data/ProjectLifecycleManager.ts @@ -316,7 +316,7 @@ export class ProjectLifecycleManager { const configBrowser = this.loadedFullConfig?.defaultBrowser // if we have a defaultBrowser from the config and a CLI browser wasn't passed and, - // the active browser isn't set (we are in run mode or when the config changes in open mode), + // the active browser isn't set (we are in run mode or when the config doesn't change in open mode), // 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) { From 3371d54dc46ee17099edec30a316e04f3e48c92e Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Wed, 13 Nov 2024 10:03:09 -0500 Subject: [PATCH 40/45] Update CHANGELOG.md --- cli/CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 2902e127ad4c..d71eebfe0760 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -5,7 +5,9 @@ _Released 12/31/2025 (PENDING)_ **Features:** -- 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). +- Added new + [`defaultBrowser`](https://docs.cypress.io/app/references/configuration) + configuration option to specify the default browser to launch. This option only affects the first browser launched; changing this option after the browser is already launched will have no effect. Addresses [#6646](https://github.com/cypress-io/cypress/issues/6646). ## 13.15.2 From 92fc352389f9c63a8af5912277ed9c18c89d2eca Mon Sep 17 00:00:00 2001 From: Matthew Schile Date: Wed, 13 Nov 2024 14:53:41 -0700 Subject: [PATCH 41/45] pr updates --- .../src/data/ProjectLifecycleManager.ts | 24 ++-- .../unit/data/ProjectLifecycleManager.spec.ts | 103 +++++++++--------- 2 files changed, 62 insertions(+), 65 deletions(-) diff --git a/packages/data-context/src/data/ProjectLifecycleManager.ts b/packages/data-context/src/data/ProjectLifecycleManager.ts index 32b8001efa30..fa96c9193e3f 100644 --- a/packages/data-context/src/data/ProjectLifecycleManager.ts +++ b/packages/data-context/src/data/ProjectLifecycleManager.ts @@ -313,18 +313,18 @@ export class ProjectLifecycleManager { * 4. The first browser found. */ async setInitialActiveBrowser () { - const configBrowser = this.loadedFullConfig?.defaultBrowser - - // if we have a defaultBrowser from the config and a CLI browser wasn't passed and, - // the active browser isn't set (we are in run mode or when the config doesn't change in open mode), - // 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) { - if (!this.ctx.coreData.activeBrowser) { - this.ctx.actions.browser.updateCliBrowser(configBrowser) - } else { - this.ctx.actions.browser.updateCliBrowser(this.ctx.coreData.activeBrowser.name) - } + const configDefaultBrowser = this.loadedFullConfig?.defaultBrowser + + // if we have a default browser from the config and a CLI browser wasn't passed and the active browser hasn't been set + // update the cliBrowser to the defaultBrowser from the config since we want the defaultBrowser to behave as if it was passed via CLI + if (configDefaultBrowser && !this.ctx.modeOptions.isBrowserGivenByCli && !this.ctx.coreData.activeBrowser) { + this.ctx.actions.browser.updateCliBrowser(configDefaultBrowser) + } + + // if we already have an activeBrowser, that means we are reloading the browser (e.g. after a config change in open mode) + // so we need to update the CLI browser to the activeBrowser to ensure the GUI shows the correct browser + if (this.ctx.coreData.activeBrowser) { + this.ctx.actions.browser.updateCliBrowser(`${this.ctx.coreData.activeBrowser.name}:${this.ctx.coreData.activeBrowser.channel}`) } if (this.ctx.coreData.cliBrowser) { diff --git a/packages/data-context/test/unit/data/ProjectLifecycleManager.spec.ts b/packages/data-context/test/unit/data/ProjectLifecycleManager.spec.ts index ce4880a8168b..07fcd4e5965c 100644 --- a/packages/data-context/test/unit/data/ProjectLifecycleManager.spec.ts +++ b/packages/data-context/test/unit/data/ProjectLifecycleManager.spec.ts @@ -2,12 +2,13 @@ import { expect } from 'chai' import type { DataContext } from '../../../src' import { createTestDataContext } from '../helper' import sinon from 'sinon' -import { FullConfig } from '@packages/types' +import { FoundBrowser, FullConfig } from '@packages/types' const browsers = [ { name: 'electron', family: 'chromium', channel: 'stable', displayName: 'Electron' }, { name: 'chrome', family: 'chromium', channel: 'stable', displayName: 'Chrome' }, { name: 'chrome', family: 'chromium', channel: 'beta', displayName: 'Chrome Beta' }, + { name: 'firefox', family: 'firefox', channel: 'stable', displayName: 'Firefox' }, ] let ctx: DataContext @@ -15,9 +16,6 @@ let ctx: DataContext function createDataContext (modeOptions?: Parameters[1]) { const context = createTestDataContext('open', modeOptions) - context.coreData.activeBrowser = undefined - context.coreData.cliBrowser = undefined - context._apis.browserApi.getBrowsers = sinon.stub().resolves(browsers) context._apis.projectApi.insertProjectPreferencesToCache = sinon.stub() context.actions.project.launchProject = sinon.stub().resolves() @@ -42,6 +40,9 @@ describe('ProjectLifecycleManager', () => { context('#setInitialActiveBrowser', () => { it('falls back to browsers[0] if preferences and cliBrowser do not exist', async () => { + ctx.coreData.activeBrowser = null + ctx.coreData.cliBrowser = null + await ctx.lifecycleManager.setInitialActiveBrowser() expect(ctx.coreData.activeBrowser).to.include({ name: 'electron' }) @@ -51,6 +52,7 @@ describe('ProjectLifecycleManager', () => { it('uses cli --browser option if one is set', async () => { ctx._apis.browserApi.ensureAndGetByNameOrPath = sinon.stub().withArgs('electron').resolves(browsers[0]) + ctx.coreData.activeBrowser = null ctx.coreData.cliBrowser = 'electron' await ctx.lifecycleManager.setInitialActiveBrowser() @@ -68,6 +70,7 @@ describe('ProjectLifecycleManager', () => { ctx._apis.browserApi.ensureAndGetByNameOrPath = sinon.stub().withArgs('electron').resolves(browsers[0]) + ctx.coreData.activeBrowser = null ctx.coreData.cliBrowser = 'electron' await ctx.lifecycleManager.setInitialActiveBrowser() @@ -79,6 +82,8 @@ describe('ProjectLifecycleManager', () => { it('uses lastBrowser if available', async () => { ctx.project.getProjectPreferences = sinon.stub().resolves({ lastBrowser: { name: 'chrome', channel: 'beta' } }) + ctx.coreData.activeBrowser = null + ctx.coreData.cliBrowser = null await ctx.lifecycleManager.setInitialActiveBrowser() @@ -88,6 +93,8 @@ describe('ProjectLifecycleManager', () => { it('falls back to browsers[0] if lastBrowser does not exist', async () => { ctx.project.getProjectPreferences = sinon.stub().resolves({ lastBrowser: { name: 'chrome', channel: 'dev' } }) + ctx.coreData.activeBrowser = null + ctx.coreData.cliBrowser = null await ctx.lifecycleManager.setInitialActiveBrowser() @@ -102,77 +109,67 @@ describe('ProjectLifecycleManager', () => { isBrowserGivenByCli: false, }) - // @ts-expect-error - ctx.lifecycleManager._configManager = { - // @ts-expect-error - getFullInitialConfig () { - return { - browsers: [], - } - }, - } - - // @ts-expect-error - ctx._apis.browserApi.ensureAndGetByNameOrPath = function () { - // return browser object for chrome - return browsers[1] - } + ctx._apis.browserApi.ensureAndGetByNameOrPath = sinon.stub().withArgs('chrome').resolves(browsers[1]) + sinon.stub(ctx.lifecycleManager, 'loadedFullConfig').get(() => ({ defaultBrowser: 'chrome' })) - Object.defineProperty(ctx.lifecycleManager, 'loadedFullConfig', { - get () { - return { - defaultBrowser: 'chrome', - } - }, - }) - - expect(ctx.coreData.activeBrowser).to.eq(undefined) + expect(ctx.modeOptions.browser).to.eq(undefined) + expect(ctx.coreData.cliBrowser).to.eq(null) + expect(ctx.coreData.activeBrowser).to.eq(null) await ctx.lifecycleManager.setInitialActiveBrowser() expect(ctx.modeOptions.browser).to.eq('chrome') expect(ctx.coreData.cliBrowser).to.eq('chrome') - expect(ctx.coreData.activeBrowser).to.include({ name: 'chrome' }) + expect(ctx.coreData.activeBrowser).to.eq(browsers[1]) }) it('doesn\'t use config defaultBrowser option if --browser is given', async () => { ctx = createDataContext({ project: 'foo', testingType: 'e2e', + browser: 'firefox', isBrowserGivenByCli: true, }) - // @ts-expect-error - ctx.lifecycleManager._configManager = { - // @ts-expect-error - getFullInitialConfig () { - return { - browsers: [], - } - }, - } + sinon.stub(ctx.lifecycleManager, 'getFullInitialConfig').resolves(fullConfig) + ctx._apis.browserApi.ensureAndGetByNameOrPath = sinon.stub().withArgs('firefox').resolves(browsers[3]) + sinon.stub(ctx.lifecycleManager, 'loadedFullConfig').get(() => ({ defaultBrowser: 'chrome' })) - // @ts-expect-error - ctx._apis.browserApi.ensureAndGetByNameOrPath = function () { - // return browser object for electron - return browsers[0] - } + expect(ctx.modeOptions.browser).to.eq('firefox') + expect(ctx.coreData.cliBrowser).to.eq('firefox') + expect(ctx.coreData.activeBrowser).to.eq(null) + + await ctx.lifecycleManager.setInitialActiveBrowser() - Object.defineProperty(ctx.lifecycleManager, 'loadedFullConfig', { - get () { - return { - defaultBrowser: 'chrome', - } - }, + expect(ctx.modeOptions.browser).to.eq('firefox') + expect(ctx.coreData.cliBrowser).to.eq('firefox') + expect(ctx.coreData.activeBrowser).to.eq(browsers[3]) + }) + + it('ignores the defaultBrowser if there is an active browser and updates the CLI browser to the active browser', async () => { + ctx = createDataContext({ + project: 'foo', + testingType: 'e2e', + isBrowserGivenByCli: false, }) - expect(ctx.coreData.activeBrowser).to.eq(undefined) + sinon.stub(ctx.lifecycleManager, 'getFullInitialConfig').resolves(fullConfig) + ctx._apis.browserApi.ensureAndGetByNameOrPath = sinon.stub().withArgs('chrome:beta').resolves(browsers[2]) + // the default browser will be ignored since we have an active browser + sinon.stub(ctx.lifecycleManager, 'loadedFullConfig').get(() => ({ defaultBrowser: 'firefox' })) - await ctx.lifecycleManager.setInitialActiveBrowser() + // set the active browser to chrome:beta + ctx.actions.browser.setActiveBrowser(browsers[2] as FoundBrowser) expect(ctx.modeOptions.browser).to.eq(undefined) - expect(ctx.coreData.cliBrowser).to.eq(undefined) - expect(ctx.coreData.activeBrowser).to.include({ name: 'electron' }) + expect(ctx.coreData.cliBrowser).to.eq(null) + expect(ctx.coreData.activeBrowser).to.eq(browsers[2]) + + await ctx.lifecycleManager.setInitialActiveBrowser() + + expect(ctx.modeOptions.browser).to.eq('chrome:beta') + expect(ctx.coreData.cliBrowser).to.eq('chrome:beta') + expect(ctx.coreData.activeBrowser).to.eq(browsers[2]) }) }) From c859819da4e34c27ff36de4511c5d68d781fd8fe Mon Sep 17 00:00:00 2001 From: Matthew Schile Date: Wed, 13 Nov 2024 15:17:11 -0700 Subject: [PATCH 42/45] a few more updates --- cli/CHANGELOG.md | 4 +--- packages/data-context/src/DataContext.ts | 6 +++--- packages/data-context/src/actions/BrowserActions.ts | 2 +- packages/data-context/src/data/ProjectLifecycleManager.ts | 8 ++++---- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index e1edbf12aa9d..e5b5b394013d 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -6,9 +6,7 @@ _Released 11/19/2024 (PENDING)_ **Features:** - Updated the protocol to be able to flex logic based on project config. Addresses [#30560](https://github.com/cypress-io/cypress/issues/30560). -- Added new - [`defaultBrowser`](https://docs.cypress.io/app/references/configuration) - configuration option to specify the default browser to launch. This option only affects the first browser launched; changing this option after the browser is already launched will have no effect. 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. This option only affects the first browser launch; changing this option after the browser is already launched will have no effect. Addresses [#6646](https://github.com/cypress-io/cypress/issues/6646). ## 13.15.2 diff --git a/packages/data-context/src/DataContext.ts b/packages/data-context/src/DataContext.ts index 4fe623c15e53..7f614bd67827 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 @@ -122,7 +122,7 @@ export class DataContext { return new RemoteRequestDataSource() } - get modeOptions () { + get modeOptions (): Readonly> { return this._modeOptions } @@ -427,6 +427,6 @@ export class DataContext { } updateModeOptionsBrowser (browser: string) { - (this.modeOptions as Partial).browser = browser + this._modeOptions.browser = browser } } diff --git a/packages/data-context/src/actions/BrowserActions.ts b/packages/data-context/src/actions/BrowserActions.ts index b6b37885661e..35177f563a4f 100644 --- a/packages/data-context/src/actions/BrowserActions.ts +++ b/packages/data-context/src/actions/BrowserActions.ts @@ -40,7 +40,7 @@ export class BrowserActions { }) } - updateCliBrowser (browser: string) { + setCliBrowser (browser: string) { this.ctx.updateModeOptionsBrowser(browser) this.ctx.coreData.cliBrowser = browser } diff --git a/packages/data-context/src/data/ProjectLifecycleManager.ts b/packages/data-context/src/data/ProjectLifecycleManager.ts index fa96c9193e3f..cb33a4937147 100644 --- a/packages/data-context/src/data/ProjectLifecycleManager.ts +++ b/packages/data-context/src/data/ProjectLifecycleManager.ts @@ -316,15 +316,15 @@ export class ProjectLifecycleManager { const configDefaultBrowser = this.loadedFullConfig?.defaultBrowser // if we have a default browser from the config and a CLI browser wasn't passed and the active browser hasn't been set - // update the cliBrowser to the defaultBrowser from the config since we want the defaultBrowser to behave as if it was passed via CLI + // set the cliBrowser to the defaultBrowser from the config since we want the defaultBrowser to behave as if it was passed via CLI if (configDefaultBrowser && !this.ctx.modeOptions.isBrowserGivenByCli && !this.ctx.coreData.activeBrowser) { - this.ctx.actions.browser.updateCliBrowser(configDefaultBrowser) + this.ctx.actions.browser.setCliBrowser(configDefaultBrowser) } // if we already have an activeBrowser, that means we are reloading the browser (e.g. after a config change in open mode) - // so we need to update the CLI browser to the activeBrowser to ensure the GUI shows the correct browser + // so we need to set the CLI browser to the activeBrowser to ensure the GUI shows the correct browser if (this.ctx.coreData.activeBrowser) { - this.ctx.actions.browser.updateCliBrowser(`${this.ctx.coreData.activeBrowser.name}:${this.ctx.coreData.activeBrowser.channel}`) + this.ctx.actions.browser.setCliBrowser(`${this.ctx.coreData.activeBrowser.name}:${this.ctx.coreData.activeBrowser.channel}`) } if (this.ctx.coreData.cliBrowser) { From 959efebe921002c037edb054b7f11f173e6e0fac Mon Sep 17 00:00:00 2001 From: Matthew Schile Date: Wed, 13 Nov 2024 19:36:07 -0700 Subject: [PATCH 43/45] fix cy-in-cy tests --- packages/data-context/src/data/ProjectLifecycleManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/data-context/src/data/ProjectLifecycleManager.ts b/packages/data-context/src/data/ProjectLifecycleManager.ts index cb33a4937147..16fc41f79a90 100644 --- a/packages/data-context/src/data/ProjectLifecycleManager.ts +++ b/packages/data-context/src/data/ProjectLifecycleManager.ts @@ -323,7 +323,7 @@ export class ProjectLifecycleManager { // if we already have an activeBrowser, that means we are reloading the browser (e.g. after a config change in open mode) // so we need to set the CLI browser to the activeBrowser to ensure the GUI shows the correct browser - if (this.ctx.coreData.activeBrowser) { + if (this.ctx.coreData.activeBrowser && !process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF) { this.ctx.actions.browser.setCliBrowser(`${this.ctx.coreData.activeBrowser.name}:${this.ctx.coreData.activeBrowser.channel}`) } From 3d5cd9d20372575e73e778522883e26908ac65b2 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Thu, 14 Nov 2024 06:49:54 -0500 Subject: [PATCH 44/45] can once again pass --browser CLI in open mode --- packages/server/lib/modes/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/server/lib/modes/index.ts b/packages/server/lib/modes/index.ts index 19376aa29c3e..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), @@ -18,7 +20,6 @@ export = (mode, options) => { quiet: false, morgan: false, report: true, - isBrowserGivenByCli: options.browser !== undefined, }) } From 1bed7104996ffb9c67b0bf974a557d33b547bc55 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Thu, 14 Nov 2024 10:46:55 -0500 Subject: [PATCH 45/45] Update CHANGELOG.md --- cli/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index e5b5b394013d..259bc2bfab13 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -6,7 +6,7 @@ _Released 11/19/2024 (PENDING)_ **Features:** - Updated the protocol to be able to flex logic based on project config. Addresses [#30560](https://github.com/cypress-io/cypress/issues/30560). -- Added new [`defaultBrowser`](https://docs.cypress.io/app/references/configuration) configuration option to specify the default browser to launch. This option only affects the first browser launch; changing this option after the browser is already launched will have no effect. Addresses [#6646](https://github.com/cypress-io/cypress/issues/6646). +- Added new [`defaultBrowser`](https://docs.cypress.io/app/references/configuration#Browser) configuration option to specify the default browser to launch. This option only affects the first browser launch; changing this option after the browser is already launched will have no effect. Addresses [#6646](https://github.com/cypress-io/cypress/issues/6646). ## 13.15.2