Skip to content

Commit

Permalink
feat: Passing --browser flag alone will launch after test selection (
Browse files Browse the repository at this point in the history
…#28538)

* Add localSettings field to OpenBrowser query

* Add wasBrowserSetInCLI as OpenBrowserList prop

* Emit launch on mount if --browser was passed

* Add entry to cli changelog

* Correct typo in changelog

* Add link to issue addressed

* Add pull request title

* Check if browser is already open before launch

* Moved features section to top of file

* Add reference to PR in changelog

* Correct unintended completion

* Add features to top of changelog

* Change prop name for convention

* Add isValidBrowser

checkes whether a cliBrowser is valid or not and
returns a boolean

* Add isValidBrowser to schema

* Use isValid browser

creates a function launchIfBrowserSetInCli that
will launch the browser if a valid browser flag
was passed to the cli

* Add to changelog.md

* Add global launch count to keep track project launch

* Make global count available to the launchPad

* Add description for globalLaunchCount

* Add globalCounnt to schema

* Remove unused import and remove unused prop

* Use launch function

* Import document and use query

* Add to changelog

* Add to existing features section

* Add to changelog

* Update changelog.md

* Add setter for launchCount and add tests

* Update changelog

* Remove extra bugfix title

* Update changelog

* Update changelog

* Update changelog

* Update changelog

* Update Changelog

* Update changelog

* Update Changelog

* Update changelog

* Fix changelog for line break error

* Update changelog

* Refactor to create single field for launching browser

* Update schema

* Refactor function to make use of single field

* Change launch count in beforeEach hook instead

* Clean up await in function

* Update changelog

* Add additional optional chaining for resiliency

* Use more precise browser launching query to fix silent bug

* Assert that launchProject hasn't been called when browser not found

* Update changelog

* Update cli/CHANGELOG.md

---------

Co-authored-by: Mark Noonan <mark@cypress.io>
Co-authored-by: Ryan Manuel <ryanm@cypress.io>
Co-authored-by: Matt Schile <mschile@cypress.io>
Co-authored-by: Jennifer Shehane <shehane.jennifer@gmail.com>
Co-authored-by: Jennifer Shehane <jennifer@cypress.io>
  • Loading branch information
6 people authored Aug 27, 2024
1 parent 5a6b8c4 commit efe577a
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 3 deletions.
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ _Released 8/27/2024 (PENDING)_
- `.type({upArrow})` and `.type({downArrow})` now also works for date, month, week, time, datetime-local and range input types. Addresses [#29665](https://github.com/cypress-io/cypress/issues/29665).
- Added a `CYPRESS_SKIP_VERIFY` flag to enable suppressing Cypress verification checks. Addresses [#22243](https://github.com/cypress-io/cypress/issues/22243).
- Updated the protocol to allow making Cloud API requests. Addressed in [#30066](https://github.com/cypress-io/cypress/pull/30066).
- Passing the browser without the testing type (i.e. `cypress open --browser <browser-name-or-path>`) will now directly launch the browser after the testing type is selected. Addresses [#22003](https://github.com/cypress-io/cypress/issues/22003). Addressed in [#28538](https://github.com/cypress-io/cypress/pull/28538).

**Bugfixes:**

Expand Down
16 changes: 16 additions & 0 deletions packages/data-context/src/actions/ProjectActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ type SetForceReconfigureProjectByTestingType = {
const debug = debugLib('cypress:data-context:ProjectActions')

export class ProjectActions {
/**
* @var globalLaunchCount
* Used as a read-only in the launchpad to ensure
* that launchProject is only called once if
* the --browser flag is passed alone.
*/
private globalLaunchCount = 0
constructor (private ctx: DataContext) {}

private get api () {
Expand Down Expand Up @@ -127,6 +134,14 @@ export class ProjectActions {
})
}

get launchCount () {
return this.globalLaunchCount
}

set launchCount (count) {
this.globalLaunchCount = count
}

openDirectoryInIDE (projectPath: string) {
this.ctx.debug(`opening ${projectPath} in ${this.ctx.coreData.localSettings.preferences.preferredEditorBinary}`)

Expand Down Expand Up @@ -284,6 +299,7 @@ export class ProjectActions {
}

await this.api.launchProject(browser, activeSpec ?? emptySpec, options)
this.globalLaunchCount++

return
}
Expand Down
5 changes: 5 additions & 0 deletions packages/graphql/schemas/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,11 @@ type LocalSettingsPreferences {
proxyBypass: String
proxyServer: String
reporterWidth: Int

"""
Determine if the browser should launch when the browser flag is passed alone
"""
shouldLaunchBrowserFromOpenBrowser: Boolean
specListWidth: Int
wasBrowserSetInCLI: Boolean
}
Expand Down
21 changes: 21 additions & 0 deletions packages/graphql/src/schemaTypes/objectTypes/gql-LocalSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,27 @@ export const LocalSettingsPreferences = objectType({
},
})

t.boolean('shouldLaunchBrowserFromOpenBrowser', {
description: 'Determine if the browser should launch when the browser flag is passed alone',
resolve: async (_source, _args, ctx) => {
try {
const cliBrowser = ctx.coreData.cliBrowser

if (!cliBrowser) {
return false
}

const browser = await ctx._apis.browserApi.ensureAndGetByNameOrPath(cliBrowser)
const shouldLaunch = Boolean(browser) && (ctx.actions.project.launchCount === 0)

return shouldLaunch
} catch (e) {
// if error is thrown, browser doesn't exist
return false
}
},
})

t.boolean('debugSlideshowComplete')
t.boolean('desktopNotificationsEnabled')
t.dateTime('dismissNotificationBannerUntil')
Expand Down
28 changes: 28 additions & 0 deletions packages/launchpad/cypress/e2e/choose-a-browser.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import type { FoundBrowser } from '@packages/types'
describe('Choose a browser page', () => {
beforeEach(() => {
cy.scaffoldProject('launchpad')
cy.withCtx((ctx, _) => {
ctx.actions.project.launchCount = 0
})
})

describe('System Browsers Detected', () => {
Expand All @@ -14,6 +17,24 @@ describe('Choose a browser page', () => {
})
})

it('launches when --browser is passed alone through the command line', () => {
cy.withCtx((ctx, o) => {
o.sinon.stub(ctx._apis.projectApi, 'launchProject').resolves()
})

cy.openProject('launchpad', ['--browser', 'edge'])
cy.visitLaunchpad()

cy.skipWelcome()
cy.get('[data-cy=card]').then(($buttons) => {
$buttons[0].click()
})

cy.withRetryableCtx((ctx, o) => {
expect(ctx._apis.projectApi.launchProject).to.be.calledOnce
})
})

it('preselects browser that is provided through the command line', () => {
cy.withCtx((ctx, o) => {
// stub launching project since we have `--browser --testingType --project` here
Expand All @@ -37,6 +58,10 @@ describe('Choose a browser page', () => {
})

it('shows warning when launched with --browser name that cannot be matched to found browsers', () => {
cy.withCtx((ctx, o) => {
o.sinon.stub(ctx._apis.projectApi, 'launchProject').resolves()
})

cy.openProject('launchpad', ['--e2e', '--browser', 'doesNotExist'])
cy.visitLaunchpad()
cy.skipWelcome()
Expand All @@ -55,6 +80,9 @@ describe('Choose a browser page', () => {
// Ensure warning can be dismissed
cy.get('[data-cy="alert-suffix-icon"]').click()
cy.get('[data-cy="alert-header"]').should('not.exist')
cy.withRetryableCtx((ctx, o) => {
expect(ctx._apis.projectApi.launchProject).not.to.be.called
})
})

it('shows warning when launched with --browser path option that cannot be matched to found browsers', () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/launchpad/src/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ fragment MainLaunchpadQueryData on Query {
preferences {
majorVersionWelcomeDismissed
wasBrowserSetInCLI
shouldLaunchBrowserFromOpenBrowser
}
}
currentProject {
Expand Down Expand Up @@ -246,11 +247,11 @@ watch(
function handleClearLandingPage () {
setMajorVersionWelcomeDismissed(MAJOR_VERSION_FOR_CONTENT)
const wasBrowserSetInCLI = query.data?.value?.localSettings.preferences?.wasBrowserSetInCLI
const shouldLaunchBrowser = query.data?.value?.localSettings?.preferences?.shouldLaunchBrowserFromOpenBrowser
const currentTestingType = currentProject.value?.currentTestingType
if (wasBrowserSetInCLI && currentTestingType) {
if (shouldLaunchBrowser && currentTestingType) {
launchProject.executeMutation({ testingType: currentTestingType })
}
}
Expand Down
24 changes: 23 additions & 1 deletion packages/launchpad/src/setup/OpenBrowser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import { useMutation, gql, useQuery } from '@urql/vue'
import OpenBrowserList from './OpenBrowserList.vue'
import WarningList from '../warning/WarningList.vue'
import { OpenBrowserDocument, OpenBrowser_CloseBrowserDocument, OpenBrowser_ClearTestingTypeDocument, OpenBrowser_LaunchProjectDocument, OpenBrowser_FocusActiveBrowserWindowDocument, OpenBrowser_ResetLatestVersionTelemetryDocument } from '../generated/graphql'
import { OpenBrowserDocument, OpenBrowser_CloseBrowserDocument, OpenBrowser_ClearTestingTypeDocument, OpenBrowser_LaunchProjectDocument, OpenBrowser_FocusActiveBrowserWindowDocument, OpenBrowser_ResetLatestVersionTelemetryDocument, OpenBrowser_LocalSettingsDocument } from '../generated/graphql'
import LaunchpadHeader from './LaunchpadHeader.vue'
import { useI18n } from '@cy/i18n'
import { computed, ref, onMounted } from 'vue'
Expand All @@ -42,7 +42,18 @@ query OpenBrowser {
}
`
gql`
query OpenBrowser_LocalSettings {
localSettings {
preferences {
shouldLaunchBrowserFromOpenBrowser
}
}
}
`
const query = useQuery({ query: OpenBrowserDocument })
const lsQuery = useQuery({ query: OpenBrowser_LocalSettingsDocument, requestPolicy: 'network-only' })
gql`
mutation OpenBrowser_ClearTestingType {
Expand Down Expand Up @@ -106,6 +117,16 @@ const launch = async () => {
}
}
const launchIfBrowserSetInCli = async () => {
const shouldLaunchBrowser = (await lsQuery).data.value?.localSettings?.preferences?.shouldLaunchBrowserFromOpenBrowser
if (shouldLaunchBrowser) {
await launch()
}
return
}
const backFn = () => {
clearCurrentTestingType.executeMutation({})
}
Expand All @@ -126,6 +147,7 @@ const setFocusToActiveBrowserWindow = () => {
onMounted(() => {
resetLatestVersionTelemetry.executeMutation({})
launchIfBrowserSetInCli()
})
</script>

5 comments on commit efe577a

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on efe577a Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.14.0/linux-x64/develop-efe577aa66920a8356888f81ef70bdd0431974ea/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on efe577a Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.14.0/linux-arm64/develop-efe577aa66920a8356888f81ef70bdd0431974ea/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on efe577a Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.14.0/win32-x64/develop-efe577aa66920a8356888f81ef70bdd0431974ea/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on efe577a Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.14.0/darwin-x64/develop-efe577aa66920a8356888f81ef70bdd0431974ea/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on efe577a Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.14.0/darwin-arm64/develop-efe577aa66920a8356888f81ef70bdd0431974ea/cypress.tgz

Please # to comment.