Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- #30604

Closed
wants to merge 30 commits into from
Closed

- #30604

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
44e0c99
feat: ability to specify the default browser in cypress config file
alexsch01 Nov 1, 2024
24e3dda
don't need setActiveBrowserByNameOrPath for run mode
alexsch01 Nov 1, 2024
f8789ab
restore readonly on attribute
alexsch01 Nov 1, 2024
2f82876
simplify cypress open version
alexsch01 Nov 1, 2024
11bd244
put isBrowserGivenByCli on modeOptions (#4)
alexsch01 Nov 3, 2024
c1fc1b2
Update cypress.d.ts
alexsch01 Nov 3, 2024
66d26b1
use isBrowserGivenByCli only for run mode (#5)
alexsch01 Nov 3, 2024
d4a68ba
make defaultBrowser more conformant
alexsch01 Nov 3, 2024
8028e51
Update CHANGELOG.md
alexsch01 Nov 3, 2024
77ffd7a
Update CHANGELOG.md
alexsch01 Nov 3, 2024
5d6202d
Update CHANGELOG.md
alexsch01 Nov 3, 2024
17c40b3
Merge branch 'develop' into defaultBrowser-config
jennifer-shehane Nov 4, 2024
d036d96
oops (#6)
alexsch01 Nov 4, 2024
08fb3a3
Merge branch 'develop' into defaultBrowser-config
jennifer-shehane Nov 5, 2024
7aaf2a9
changes (#7)
alexsch01 Nov 6, 2024
b7cb459
more test fixes (#8)
alexsch01 Nov 6, 2024
ea67832
Update utils.spec.ts
alexsch01 Nov 6, 2024
4f1cd4d
Update packages/config/src/options.ts
alexsch01 Nov 6, 2024
7154055
Update cli/CHANGELOG.md
alexsch01 Nov 6, 2024
9a740c4
Update cli/types/cypress.d.ts
alexsch01 Nov 6, 2024
2dddf0f
Update packages/config/src/options.ts
alexsch01 Nov 6, 2024
5f1d6b9
Update packages/data-context/src/data/ProjectLifecycleManager.ts
alexsch01 Nov 6, 2024
adec731
Update DataContext.ts
alexsch01 Nov 6, 2024
4425433
Update DataContext.ts
alexsch01 Nov 6, 2024
6933638
final oops
alexsch01 Nov 6, 2024
2a53ba0
remove requireRestartOnChange for defaultBrowser, prevent bad open mo…
alexsch01 Nov 8, 2024
fd9c123
oops
alexsch01 Nov 8, 2024
c5ace21
Update DataContext.ts
alexsch01 Nov 12, 2024
568d222
Update BrowserActions.ts
alexsch01 Nov 12, 2024
c6766bc
Update ProjectLifecycleManager.ts
alexsch01 Nov 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

_Released 11/5/2024 (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).

**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).
Expand Down
5 changes: 5 additions & 0 deletions cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3216,6 +3216,11 @@ declare namespace Cypress {
setupNodeEvents: (on: PluginEvents, config: PluginConfigOptions) => Promise<PluginConfigOptions | void> | PluginConfigOptions | void

indexHtmlFile: string

/**
* The default browser to launch if the "--browser" command line option is not provided.
*/
defaultBrowser: string
}

interface EndToEndConfigOptions extends Omit<CoreConfigOptions, 'indexHtmlFile'> {
Expand Down
3 changes: 3 additions & 0 deletions packages/config/__snapshots__/index.spec.ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down Expand Up @@ -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': {
Expand Down Expand Up @@ -206,6 +208,7 @@ exports['config/src/index .getPublicConfigKeys returns list of public config key
'chromeWebSecurity',
'clientCertificates',
'component',
'defaultBrowser',
'defaultCommandTimeout',
'downloadsFolder',
'e2e',
Expand Down
4 changes: 4 additions & 0 deletions packages/config/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ const driverConfigOptions: Array<DriverConfigOption> = [
indexHtmlFile: 'cypress/support/component-index.html',
},
validation: isValidConfig,
}, {
name: 'defaultBrowser',
defaultValue: null,
validation: validate.isString,
}, {
name: 'defaultCommandTimeout',
defaultValue: 4000,
Expand Down
2 changes: 2 additions & 0 deletions packages/config/test/project/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down Expand Up @@ -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' },
Expand Down
4 changes: 4 additions & 0 deletions packages/data-context/src/DataContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,4 +425,8 @@ export class DataContext {
this.#awaitingEmptyRequestCount.push(resolve)
})
}

updateModeOptionsBrowser (browser: string) {
(this.modeOptions as Partial<AllModeOptions>).browser = browser
}
}
5 changes: 5 additions & 0 deletions packages/data-context/src/actions/BrowserActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
17 changes: 15 additions & 2 deletions packages/data-context/src/data/ProjectLifecycleManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,23 @@ 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 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
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) {
await this.setActiveBrowserByNameOrPath(this.ctx.coreData.cliBrowser)

Expand Down
1 change: 1 addition & 0 deletions packages/server/lib/modes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export = (mode, options) => {
quiet: false,
morgan: false,
report: true,
isBrowserGivenByCli: options.browser !== undefined,
})
}

Expand Down
1 change: 1 addition & 0 deletions packages/types/src/modeOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface RunModeOptions extends CommonModeOptions {
parallel?: boolean | null
ciBuildId?: string | null
tag?: (string)[] | null
isBrowserGivenByCli: boolean
}

export type TestingType = 'e2e' | 'component'
Expand Down
1 change: 1 addition & 0 deletions system-tests/__snapshots__/results_spec.ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
Expand Down
6 changes: 6 additions & 0 deletions system-tests/projects/config-defaultBrowser/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
e2e: {
supportFile: false,
},
defaultBrowser: 'chrome',
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
it('works', () => {
expect(1).to.eq(1)
})
13 changes: 13 additions & 0 deletions system-tests/test/config_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,17 @@ 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',
command: 'cypress',
args: ['run', '--dev', '--project', path.resolve(process.cwd(), './projects/config-defaultBrowser')],
onStdout: (stdout) => {
expect(stdout).to.include('Browser: Chrome')
},
})
})
})
Loading