-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
base: develop
Are you sure you want to change the base?
Changes from all commits
9c66b18
92e9483
7063ecc
04d4056
289a1ee
e57272c
51d5511
957bf56
332602b
fea326b
845477d
65c22e2
ab75b54
46c9a32
b142339
a806939
d172862
95e0c9b
246436a
91c2019
54325c5
b7296be
7c4c9bb
c5852c2
ccdd0b9
3a03a71
e5cb959
0ed0e48
7da6148
77376d2
4847cd9
07d6b9f
2e4829a
6da369e
d17bad1
a7baff4
42de35e
fee655b
33bafa2
dcbe3eb
f69f548
9486b3f
b703611
31da795
48b3562
5633d82
be8e4fa
654c795
7a749d2
66fa91e
414c50f
42152da
ba72ab9
f848ec0
7cc99df
06a8a1b
c5514a9
543f827
1dd266d
9ee7ead
9aa40f1
cb106a6
c9a88e9
9eb31da
b24c154
2beb57e
461d256
38211cb
8b045e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 () { | ||
|
@@ -127,6 +134,14 @@ export class ProjectActions { | |
}) | ||
} | ||
|
||
get launchCount () { | ||
return this.globalLaunchCount | ||
} | ||
|
||
set launchCount (count) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}`) | ||
|
||
|
@@ -284,6 +299,7 @@ export class ProjectActions { | |
} | ||
|
||
await this.api.launchProject(browser, activeSpec ?? emptySpec, options) | ||
this.globalLaunchCount++ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We increment here when the project is launched |
||
|
||
return | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here I'm just resolving with the |
||
}) | ||
|
||
t.boolean('debugSlideshowComplete') | ||
t.boolean('desktopNotificationsEnabled') | ||
t.dateTime('dismissNotificationBannerUntil') | ||
|
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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') | ||
}) | ||
|
@@ -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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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' | ||
|
@@ -42,7 +42,20 @@ query OpenBrowser { | |
} | ||
` | ||
|
||
gql` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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' }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. 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 { | ||
|
@@ -106,6 +119,19 @@ const launch = async () => { | |
} | ||
} | ||
|
||
const launchIfBrowserSetInCli = async () => { | ||
await lsQuery | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to await |
||
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({}) | ||
} | ||
|
@@ -126,6 +152,7 @@ const setFocusToActiveBrowserWindow = () => { | |
|
||
onMounted(() => { | ||
resetLatestVersionTelemetry.executeMutation({}) | ||
launchIfBrowserSetInCli() | ||
}) | ||
|
||
</script> |
There was a problem hiding this comment.
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