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

moved #27911

Closed
wants to merge 10 commits into from
Closed

moved #27911

Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ _Released 10/03/2023 (PENDING)_
_Released 09/27/2023_

**Features:**

- Added ability to specify the default running browser in cypress config. Addresses [#6646](https://github.com/cypress-io/cypress/issues/6646).
- Introduces new layout for Runs page providing additional run information. Addresses [#27203](https://github.com/cypress-io/cypress/issues/27203).

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

indexHtmlFile: string

/**
* Set a default browser other than electron when user doesn't pass in "--browser".
*/
defaultBrowser: string
}

interface EndToEndConfigOptions extends Omit<CoreConfigOptions, 'indexHtmlFile'> {
Expand Down Expand Up @@ -3536,7 +3541,7 @@ declare namespace Cypress {
hosts?: null | {[key: string]: string}
}

interface PluginConfigOptions extends ResolvedConfigOptions, RuntimeConfigOptions {
interface PluginConfigOptions extends ResolvedConfigOptions, Omit<RuntimeConfigOptions, 'browser'> {
/**
* Absolute path to the root of the project
*/
Expand Down
6 changes: 5 additions & 1 deletion packages/data-context/src/DataContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export interface GraphQLRequestInfo {
export class DataContext {
readonly graphqlRequestInfo?: GraphQLRequestInfo
private _config: Omit<DataContextConfig, 'modeOptions'>
private _modeOptions: Readonly<Partial<AllModeOptions>>
private _modeOptions: Partial<AllModeOptions>
private _coreData: CoreDataShape
readonly lifecycleManager: ProjectLifecycleManager

Expand Down Expand Up @@ -423,4 +423,8 @@ export class DataContext {
this.#awaitingEmptyRequestCount.push(resolve)
})
}

setModeOptionsBrowser (browser: string) {
this._modeOptions.browser = browser
}
}
23 changes: 21 additions & 2 deletions packages/data-context/src/data/ProjectLifecycleManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,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)

Expand Down
2 changes: 2 additions & 0 deletions packages/data-context/src/data/coreDataShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ interface CloudDataShape {

export interface CoreDataShape {
cliBrowser: string | null
isBrowserGivenByCli: boolean
cliTestingType: string | null
activeBrowser: FoundBrowser | null
machineId: Promise<string | null>
Expand Down Expand Up @@ -180,6 +181,7 @@ export function makeCoreData (modeOptions: Partial<AllModeOptions> = {}): CoreDa
return {
servers: {},
cliBrowser: modeOptions.browser ?? null,
isBrowserGivenByCli: modeOptions.isBrowserGivenByCli ?? false,
cliTestingType: modeOptions.testingType ?? null,
machineId: machineId(),
machineBrowsers: null,
Expand Down
2 changes: 2 additions & 0 deletions packages/server/lib/modes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/modeOptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface CommonModeOptions {
_?: (string | null)[] | null
invokedFromCli: boolean
isBrowserGivenByCli: boolean
userNodePath?: string
userNodeVersion?: string
configFile?: string | null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const { defineConfig } = require('cypress')

module.exports = defineConfig({
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)
})
11 changes: 11 additions & 0 deletions system-tests/test/config_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,15 @@ describe('e2e config', () => {
snapshot: true,
})
})

it('launches browser using config.defaultBrowser', async function () {
await Fixtures.scaffoldProject('config-default-browser')

return systemTests.exec(this, {
project: 'config-default-browser',
onStdout: (stdout) => {
expect(stdout).to.include('Browser: Chrome')
},
})
})
})