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

feat: Passing --browser flag alone will launch after test selection #28538

Open
wants to merge 69 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
9c66b18
Add localSettings field to OpenBrowser query
raygdev Dec 16, 2023
92e9483
Add wasBrowserSetInCLI as OpenBrowserList prop
raygdev Dec 16, 2023
7063ecc
Emit launch on mount if --browser was passed
raygdev Dec 16, 2023
04d4056
Merge branch 'develop' of https://github.com/raygdev/cypress into iss…
raygdev Dec 16, 2023
289a1ee
Add entry to cli changelog
raygdev Dec 16, 2023
e57272c
Correct typo in changelog
raygdev Dec 16, 2023
51d5511
Add link to issue addressed
raygdev Dec 16, 2023
957bf56
Add pull request title
raygdev Dec 16, 2023
332602b
Check if browser is already open before launch
raygdev Dec 17, 2023
fea326b
Moved features section to top of file
raygdev Dec 17, 2023
845477d
Add reference to PR in changelog
raygdev Dec 17, 2023
65c22e2
Correct unintended completion
raygdev Dec 18, 2023
ab75b54
Merge branch 'cypress-io:develop' into issue-22003
raygdev Dec 20, 2023
46c9a32
Merge branch 'develop' of https://github.com/raygdev/cypress into iss…
raygdev Jan 6, 2024
b142339
Merge branch 'issue-22003' of https://github.com/raygdev/cypress into…
raygdev Jan 6, 2024
a806939
Add features to top of changelog
raygdev Jan 6, 2024
d172862
Change prop name for convention
raygdev Jan 6, 2024
95e0c9b
Merge branch 'develop' of https://github.com/raygdev/cypress into iss…
raygdev Jan 6, 2024
246436a
Merge develop and handle conflicts
raygdev Jan 22, 2024
91c2019
Merge branch 'issue-22003' of https://github.com/raygdev/cypress into…
raygdev Feb 21, 2024
54325c5
Add isValidBrowser
raygdev Mar 11, 2024
b7296be
Add isValidBrowser to schema
raygdev Mar 11, 2024
7c4c9bb
Use isValid browser
raygdev Mar 11, 2024
c5852c2
Merge branch 'develop' of https://github.com/raygdev/cypress into iss…
raygdev Mar 11, 2024
ccdd0b9
Add to changelog.md
raygdev Mar 11, 2024
3a03a71
Add global launch count to keep track project launch
raygdev Mar 13, 2024
e5cb959
Make global count available to the launchPad
raygdev Mar 13, 2024
0ed0e48
Add description for globalLaunchCount
raygdev Mar 13, 2024
7da6148
Add globalCounnt to schema
raygdev Mar 13, 2024
77376d2
Remove unused import and remove unused prop
raygdev Mar 13, 2024
4847cd9
Use launch function
raygdev Mar 13, 2024
07d6b9f
Import document and use query
raygdev Mar 13, 2024
2e4829a
Merge branch 'develop' of https://github.com/raygdev/cypress into iss…
raygdev Mar 13, 2024
6da369e
Add to changelog
raygdev Mar 13, 2024
d17bad1
Add to existing features section
raygdev Mar 13, 2024
a7baff4
Merge branch 'develop' of https://github.com/raygdev/cypress into iss…
raygdev Mar 13, 2024
42de35e
Add to changelog
raygdev Mar 13, 2024
fee655b
Merge branch 'develop' of https://github.com/raygdev/cypress into iss…
raygdev Mar 14, 2024
33bafa2
Merge branch 'develop' of https://github.com/raygdev/cypress into iss…
raygdev Mar 21, 2024
dcbe3eb
Merge branch 'develop' of https://github.com/raygdev/cypress into iss…
raygdev Mar 28, 2024
f69f548
Update changelog.md
raygdev Mar 28, 2024
9486b3f
Add setter for launchCount and add tests
raygdev Apr 7, 2024
b703611
Merge branch 'develop' of https://github.com/raygdev/cypress into iss…
raygdev Apr 7, 2024
31da795
Update changelog
raygdev Apr 8, 2024
48b3562
Merge branch 'develop' of https://github.com/raygdev/cypress into iss…
raygdev Apr 9, 2024
5633d82
Handle changelog merge conflict
raygdev Apr 10, 2024
be8e4fa
Merge branch 'develop' of https://github.com/raygdev/cypress into iss…
raygdev Apr 10, 2024
654c795
Merge changes
raygdev Apr 12, 2024
7a749d2
Remove extra bugfix title
raygdev Apr 12, 2024
66fa91e
Merge branch 'develop' of https://github.com/raygdev/cypress into iss…
raygdev Apr 12, 2024
414c50f
Merge branch 'develop' of https://github.com/raygdev/cypress into iss…
raygdev Apr 15, 2024
42152da
Update changelog
raygdev Apr 15, 2024
ba72ab9
Merge branch 'develop' of https://github.com/raygdev/cypress into iss…
raygdev Apr 16, 2024
f848ec0
Merge branch 'develop' of https://github.com/raygdev/cypress into iss…
raygdev Apr 30, 2024
7cc99df
Update changelog
raygdev Apr 30, 2024
06a8a1b
Merge branch 'develop' into issue-22003
marktnoonan May 4, 2024
c5514a9
Update changelog
raygdev May 4, 2024
543f827
Merge branch 'develop' into issue-22003
ryanthemanuel May 6, 2024
1dd266d
Merge branch 'develop' into issue-22003
raygdev May 7, 2024
9ee7ead
Merge branch 'develop' into issue-22003
raygdev May 8, 2024
9aa40f1
Update changelog
raygdev May 8, 2024
cb106a6
Merge branch 'develop' into issue-22003
mschile May 16, 2024
c9a88e9
Merge branch 'develop' into issue-22003
raygdev May 20, 2024
9eb31da
Merge issue-22003
raygdev Jun 4, 2024
b24c154
Merge branch 'develop' of https://github.com/raygdev/cypress into iss…
raygdev Jun 4, 2024
2beb57e
Update Changelog
raygdev Jun 4, 2024
461d256
Merge branch 'develop' into issue-22003
raygdev Jun 5, 2024
38211cb
Update changelog
raygdev Jun 5, 2024
8b045e4
Merge branch 'develop' into issue-22003
raygdev Jun 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ _Released 6/4/2024_

- Added support for [Next.js 14](https://nextjs.org/blog/next-14) for component testing. Addresses [#28185](https://github.com/cypress-io/cypress/issues/28185).
- Added an `IGNORE_CHROME_PREFERENCES` environment variable to ignore Chrome preferences when launching Chrome. Addresses [#29330](https://github.com/cypress-io/cypress/issues/29330).
- 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
Copy link
Author

Choose a reason for hiding this comment

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

This is only used to increment in launchProject and returned with a getter to use in gql-LocalSettings.ts

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) {
Copy link
Author

@raygdev raygdev Apr 8, 2024

Choose a reason for hiding this comment

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

I genuinely don't like this, but I don't see any other way to get the tests to pass for the changes I made. I have to provide a setter to reset the launch count before the tests are run. If I don't, the test I made will fail on a second run.

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++
Copy link
Author

Choose a reason for hiding this comment

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

We increment here when the project is launched


return
}
Expand Down
6 changes: 6 additions & 0 deletions packages/graphql/schemas/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1431,8 +1431,14 @@ type LocalSettingsPreferences {
debugSlideshowComplete: Boolean
desktopNotificationsEnabled: Boolean
dismissNotificationBannerUntil: DateTime

"""
A launch count to keep track of launchProject calls from projectActions
"""
globalLaunchCount: Int
isSideNavigationOpen: Boolean
isSpecsListOpen: Boolean
isValidBrowser: Boolean
majorVersionWelcomeDismissed: JSON
notifyWhenRunCompletes: JSON
notifyWhenRunStarts: Boolean
Expand Down
22 changes: 22 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,28 @@ export const LocalSettingsPreferences = objectType({
},
})

t.boolean('isValidBrowser', {
resolve: async (_source, _args, ctx) => {
try {
if (!ctx.coreData.cliBrowser) {
return false
}

const browser = await ctx._apis.browserApi.ensureAndGetByNameOrPath(ctx.coreData.cliBrowser)
Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure if this is acceptable. I am basically using the browserApi to ensure that the cli browser passed is a found browser... It will throw an error otherwise. So I wrap it in a try/catch. If it is caught, the browser is either invalid or something is wrong... so we don't launch if isValidBrowser is false. I believe that ensureAndGetByNameOrPath is just this utility function under the hood. I am not sure yet if there are side effects from this but would greatly appreciate some input on if this is ok or not.


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

t.int('globalLaunchCount', {
description: 'A launch count to keep track of launchProject calls from projectActions',
resolve: (_source, _args, ctx) => ctx.actions.project.launchCount,
Copy link
Author

Choose a reason for hiding this comment

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

Here I'm just resolving with the launchCount

})

t.boolean('debugSlideshowComplete')
t.boolean('desktopNotificationsEnabled')
t.dateTime('dismissNotificationBannerUntil')
Expand Down
24 changes: 24 additions & 0 deletions packages/launchpad/cypress/e2e/choose-a-browser.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import type { FoundBrowser } from '@packages/types'

describe('Choose a browser page', () => {
before(() => {
cy.withCtx((ctx, _) => {
ctx.actions.project.launchCount = 0
Copy link
Author

Choose a reason for hiding this comment

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

I have to set the launch count here before the tests start. I don't feel this is the best way to test it, but I'm out of ideas to get this going.

})
})

beforeEach(() => {
cy.scaffoldProject('launchpad')
})
Expand All @@ -14,6 +20,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 Down
29 changes: 28 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,20 @@ query OpenBrowser {
}
`

gql`
Copy link
Author

Choose a reason for hiding this comment

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

I created a separate query for LocalSettings

query OpenBrowser_LocalSettings {
localSettings {
preferences {
wasBrowserSetInCLI
isValidBrowser
globalLaunchCount
}
}
}
`

const query = useQuery({ query: OpenBrowserDocument })
const lsQuery = useQuery({ query: OpenBrowser_LocalSettingsDocument, requestPolicy: 'network-only' })
Copy link
Author

@raygdev raygdev Mar 13, 2024

Choose a reason for hiding this comment

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

Since the values were being cached by the urql client I couldn't get the information to sync. globalLaunchCount was always 0 even though the value on the server was updating.

I notice that this may not be the best choice but couldn't really find a better option. I do feel that since most values are cached anyway, having this as a network request when switching views is negligible. But if anyone has a better idea, I'll be more than happy to make the change.


gql`
mutation OpenBrowser_ClearTestingType {
Expand Down Expand Up @@ -106,6 +119,19 @@ const launch = async () => {
}
}

const launchIfBrowserSetInCli = async () => {
await lsQuery
Copy link
Author

Choose a reason for hiding this comment

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

I had to await lsQuery here to make sure that the data was available without passing as a prop.

const isValidBrowser = lsQuery.data.value?.localSettings.preferences.isValidBrowser
const wasBrowserSetInCli = lsQuery.data.value?.localSettings.preferences.wasBrowserSetInCLI
const globalLaunchCount = lsQuery.data.value?.localSettings.preferences.globalLaunchCount

if (wasBrowserSetInCli && isValidBrowser && (globalLaunchCount === 0)) {
await launch()
}

return
}

const backFn = () => {
clearCurrentTestingType.executeMutation({})
}
Expand All @@ -126,6 +152,7 @@ const setFocusToActiveBrowserWindow = () => {

onMounted(() => {
resetLatestVersionTelemetry.executeMutation({})
launchIfBrowserSetInCli()
})

</script>