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

fix: run-all-specs opens in new tab rather than new browser #25074

Merged
merged 5 commits into from Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
10 changes: 5 additions & 5 deletions packages/app/cypress/e2e/run-all-specs.cy.ts
Expand Up @@ -45,9 +45,10 @@ describe('run-all-specs', () => {

cy.waitForSpecToFinish({ passCount: 2 })

cy.withCtx((ctx, { specs }) => {
cy.withCtx((ctx, { specs, RUN_ALL_SPECS_KEY }) => {
expect(ctx.actions.project.launchProject).to.have.been.calledWith('e2e', { shouldLaunchNewTab: true }, RUN_ALL_SPECS_KEY)
expect(ctx.project.runAllSpecs).to.include.members(specs.map((spec) => spec.relative))
}, { specs: subDirectorySpecs })
}, { specs: subDirectorySpecs, RUN_ALL_SPECS_KEY })

for (const spec of subDirectorySpecs) {
cy.get('.runnable-title').contains(spec.name)
Expand Down Expand Up @@ -100,10 +101,9 @@ describe('run-all-specs', () => {

clickRunAllSpecs('all')

cy.withCtx((ctx, { specs, runAllSpecsKey }) => {
expect(ctx.actions.project.launchProject).to.have.been.calledWith('e2e', undefined, runAllSpecsKey)
cy.withCtx((ctx, { specs }) => {
expect(ctx.project.runAllSpecs).to.include.members(specs.map((spec) => spec.relative))
}, { specs: Object.values(ALL_SPECS), runAllSpecsKey: RUN_ALL_SPECS_KEY })
}, { specs: Object.values(ALL_SPECS) })

cy.waitForSpecToFinish({ passCount: 6 })

Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/store/run-all-specs-store.ts
Expand Up @@ -22,7 +22,7 @@ query RunAllSpecsData {
gql`
mutation RunAllSpecs ($specPath: String!, $runAllSpecs: [String!]!) {
setRunAllSpecs(runAllSpecs: $runAllSpecs)
launchOpenProject(specPath: $specPath) {
launchOpenProject(specPath: $specPath, shouldLaunchNewTab: true) {
id
}
}
Expand Down
12 changes: 10 additions & 2 deletions packages/data-context/src/actions/ProjectActions.ts
Expand Up @@ -22,7 +22,7 @@ export interface ProjectApiShape {
* order for CT to startup
*/
openProjectCreate(args: InitializeProjectOptions, options: OpenProjectLaunchOptions): Promise<unknown>
launchProject(browser: FoundBrowser, spec: Cypress.Spec, options?: OpenProjectLaunchOpts): Promise<void>
launchProject(browser: FoundBrowser, spec: Cypress.Spec, options?: Partial<OpenProjectLaunchOpts>): Promise<void>
insertProjectToCache(projectRoot: string): Promise<void>
removeProjectFromCache(projectRoot: string): Promise<void>
getProjectRootsFromCache(): Promise<ProjectShape[]>
Expand All @@ -46,6 +46,8 @@ export interface ProjectApiShape {
emitter: EventEmitter
}
isListening: (url: string) => Promise<void>
resetBrowserTabsForNextTest(shouldKeepTabOpen: boolean): Promise<void>
resetServer(): void
}

export interface FindSpecs<T> {
Expand Down Expand Up @@ -228,7 +230,7 @@ export class ProjectActions {
}
}

async launchProject (testingType: Cypress.TestingType | null, options?: OpenProjectLaunchOpts, specPath?: string | null) {
async launchProject (testingType: Cypress.TestingType | null, options?: Partial<OpenProjectLaunchOpts>, specPath?: string | null) {
if (!this.ctx.currentProject) {
return null
}
Expand Down Expand Up @@ -261,6 +263,12 @@ export class ProjectActions {
specType: testingType === 'e2e' ? 'integration' : 'component',
}

// Used for run-all-specs feature
if (options?.shouldLaunchNewTab) {
await this.api.resetBrowserTabsForNextTest(true)
this.api.resetServer()
}

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

return
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/schemas/schema.graphql
Expand Up @@ -1255,7 +1255,7 @@ type Mutation {
internal_clearProjectPreferencesCache(projectTitle: String!): Boolean

"""Launches project from open_project global singleton"""
launchOpenProject(specPath: String): CurrentProject
launchOpenProject(shouldLaunchNewTab: Boolean, specPath: String): CurrentProject
Copy link
Contributor

Choose a reason for hiding this comment

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

Something is strange here - the order of the arguments is the opposite on the client mutation? https://github.com/cypress-io/cypress/pull/25074/files#diff-4efefe4d3a02c250b8acd5d08fb87caf32cf883ccff71ea7965d0e6c0448fe68R25

Also, I think it makes sense for the specPath to be first arg, and shouldLaunchNewTab to be second - it follows the usual convention of putting the options as the second argument.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am surprised this works at all - GraphQL should be erroring, the types don't match.

Copy link
Contributor Author

@ZachJW34 ZachJW34 Dec 8, 2022

Choose a reason for hiding this comment

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

I think this is just sorted alphabetically (this is generated). Look at:

cloudProjectCreate(campaign: String, ciProviders: [String!], cohort: String, medium: String, name: String!, orgId: ID!, public: Boolean!, source: String): CloudProject

Order doesn't matter since all the args resolve to an args object.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, I see. I didn't realize that (and it's quite confusing - the order generally DOES matter in GraphQL, I guess not if you are using Nexus).


"""Sets the active browser"""
launchpadSetBrowser(
Expand Down
3 changes: 2 additions & 1 deletion packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts
Expand Up @@ -294,10 +294,11 @@ export const mutation = mutationType({
type: CurrentProject,
description: 'Launches project from open_project global singleton',
args: {
shouldLaunchNewTab: booleanArg(),
specPath: stringArg(),
},
resolve: async (_, args, ctx) => {
await ctx.actions.project.launchProject(ctx.coreData.currentTestingType, undefined, args.specPath)
await ctx.actions.project.launchProject(ctx.coreData.currentTestingType, { shouldLaunchNewTab: args.shouldLaunchNewTab ?? false }, args.specPath)

return ctx.lifecycleManager
},
Expand Down
6 changes: 6 additions & 0 deletions packages/server/lib/makeDataContext.ts
Expand Up @@ -155,6 +155,12 @@ export function makeDataContext (options: MakeDataContextOptions): DataContext {
return devServer
},
isListening,
resetBrowserTabsForNextTest (shouldKeepTabOpen: boolean) {
return openProject.resetBrowserTabsForNextTest(shouldKeepTabOpen)
},
resetServer () {
return openProject.getProject()?.reset()
ZachJW34 marked this conversation as resolved.
Show resolved Hide resolved
},
},
electronApi: {
openExternal (url: string) {
Expand Down
54 changes: 26 additions & 28 deletions tooling/v8-snapshot/cache/dev-darwin/snapshot-meta.cache.json
Expand Up @@ -4,10 +4,6 @@
"./get-stream/buffer-stream.js",
"./graceful-fs/polyfills.js",
"./lockfile/lockfile.js",
"./node_modules/@babel/traverse/lib/path/comments.js",
"./node_modules/@babel/traverse/lib/path/conversion.js",
"./node_modules/@babel/traverse/lib/path/family.js",
"./node_modules/@babel/traverse/lib/path/introspection.js",
"./node_modules/@cspotcode/source-map-support/source-map-support.js",
"./node_modules/@cypress/commit-info/node_modules/debug/src/node.js",
"./node_modules/@cypress/get-windows-proxy/node_modules/debug/src/node.js",
Expand Down Expand Up @@ -44,6 +40,10 @@
"./node_modules/tcp-port-used/node_modules/debug/src/node.js",
"./node_modules/trash/node_modules/make-dir/index.js",
"./node_modules/utif/UTIF.js",
"./packages/config/node_modules/@babel/traverse/lib/path/comments.js",
"./packages/config/node_modules/@babel/traverse/lib/path/conversion.js",
"./packages/config/node_modules/@babel/traverse/lib/path/family.js",
"./packages/config/node_modules/@babel/traverse/lib/path/introspection.js",
"./packages/data-context/node_modules/debug/src/node.js",
"./packages/data-context/node_modules/minimatch/minimatch.js",
"./packages/graphql/node_modules/debug/src/node.js",
Expand Down Expand Up @@ -73,17 +73,6 @@
"deferred": [
"./node_modules/@babel/generator/lib/node/index.js",
"./node_modules/@babel/generator/lib/node/whitespace.js",
"./node_modules/@babel/helper-environment-visitor/lib/index.js",
"./node_modules/@babel/traverse/lib/context.js",
"./node_modules/@babel/traverse/lib/index.js",
"./node_modules/@babel/traverse/lib/path/ancestry.js",
"./node_modules/@babel/traverse/lib/path/context.js",
"./node_modules/@babel/traverse/lib/path/index.js",
"./node_modules/@babel/traverse/lib/path/modification.js",
"./node_modules/@babel/traverse/lib/path/removal.js",
"./node_modules/@babel/traverse/lib/path/replacement.js",
"./node_modules/@babel/traverse/lib/scope/index.js",
"./node_modules/@babel/traverse/lib/traverse-node.js",
"./node_modules/@babel/types/lib/definitions/core.js",
"./node_modules/@babel/types/lib/definitions/experimental.js",
"./node_modules/@babel/types/lib/definitions/flow.js",
Expand Down Expand Up @@ -632,6 +621,15 @@
"./node_modules/xml2js/lib/xml2js.js",
"./node_modules/yauzl/index.js",
"./node_modules/zip-stream/index.js",
"./packages/config/node_modules/@babel/traverse/lib/context.js",
ZachJW34 marked this conversation as resolved.
Show resolved Hide resolved
"./packages/config/node_modules/@babel/traverse/lib/index.js",
"./packages/config/node_modules/@babel/traverse/lib/path/ancestry.js",
"./packages/config/node_modules/@babel/traverse/lib/path/context.js",
"./packages/config/node_modules/@babel/traverse/lib/path/index.js",
"./packages/config/node_modules/@babel/traverse/lib/path/modification.js",
"./packages/config/node_modules/@babel/traverse/lib/path/removal.js",
"./packages/config/node_modules/@babel/traverse/lib/path/replacement.js",
"./packages/config/node_modules/@babel/traverse/lib/scope/index.js",
"./packages/data-context/node_modules/chokidar/index.js",
"./packages/data-context/node_modules/chokidar/lib/constants.js",
"./packages/data-context/node_modules/chokidar/lib/fsevents-handler.js",
Expand Down Expand Up @@ -816,18 +814,6 @@
"./node_modules/@babel/template/lib/parse.js",
"./node_modules/@babel/template/lib/populate.js",
"./node_modules/@babel/template/lib/string.js",
"./node_modules/@babel/traverse/lib/cache.js",
"./node_modules/@babel/traverse/lib/hub.js",
"./node_modules/@babel/traverse/lib/path/evaluation.js",
"./node_modules/@babel/traverse/lib/path/inference/index.js",
"./node_modules/@babel/traverse/lib/path/inference/inferer-reference.js",
"./node_modules/@babel/traverse/lib/path/inference/inferers.js",
"./node_modules/@babel/traverse/lib/path/lib/hoister.js",
"./node_modules/@babel/traverse/lib/path/lib/removal-hooks.js",
"./node_modules/@babel/traverse/lib/path/lib/virtual-types.js",
"./node_modules/@babel/traverse/lib/scope/binding.js",
"./node_modules/@babel/traverse/lib/scope/lib/renamer.js",
"./node_modules/@babel/traverse/lib/visitors.js",
"./node_modules/@babel/types/lib/asserts/assertNode.js",
"./node_modules/@babel/types/lib/asserts/generated/index.js",
"./node_modules/@babel/types/lib/ast-types/generated/index.js",
Expand Down Expand Up @@ -3295,6 +3281,18 @@
"./node_modules/yallist/yallist.js",
"./node_modules/yn/index.js",
"./node_modules/yn/lenient.js",
"./packages/config/node_modules/@babel/traverse/lib/cache.js",
"./packages/config/node_modules/@babel/traverse/lib/hub.js",
"./packages/config/node_modules/@babel/traverse/lib/path/evaluation.js",
"./packages/config/node_modules/@babel/traverse/lib/path/inference/index.js",
"./packages/config/node_modules/@babel/traverse/lib/path/inference/inferer-reference.js",
"./packages/config/node_modules/@babel/traverse/lib/path/inference/inferers.js",
"./packages/config/node_modules/@babel/traverse/lib/path/lib/hoister.js",
"./packages/config/node_modules/@babel/traverse/lib/path/lib/removal-hooks.js",
"./packages/config/node_modules/@babel/traverse/lib/path/lib/virtual-types.js",
"./packages/config/node_modules/@babel/traverse/lib/scope/binding.js",
"./packages/config/node_modules/@babel/traverse/lib/scope/lib/renamer.js",
"./packages/config/node_modules/@babel/traverse/lib/visitors.js",
"./packages/data-context/node_modules/@babel/code-frame/lib/index.js",
"./packages/data-context/node_modules/@babel/parser/lib/index.js",
"./packages/data-context/node_modules/anymatch/index.js",
Expand Down Expand Up @@ -3542,5 +3540,5 @@
"./tooling/v8-snapshot/cache/dev-darwin/snapshot-entry.js"
],
"deferredHashFile": "yarn.lock",
"deferredHash": "7da54eecbd832d3cd8ba75441a83e8c69c033664f25df5a2e43c1794d9d149de"
"deferredHash": "468a4c5e1401d9b675a4c746744a49a330bc411d8427447dd1bfdbf7c6bc59d4"
}