Skip to content

Commit

Permalink
fix: run-all-specs opens in new tab rather than new browser (#25074)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZachJW34 committed Dec 12, 2022
1 parent 5c34841 commit 6c37403
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 12 deletions.
Expand Up @@ -147,7 +147,7 @@ describe('Cypress In Cypress CT', { viewportWidth: 1500, defaultCommandTimeout:
expect(ctx.actions.browser.setActiveBrowserById).to.have.been.calledWith(browserId)
expect(genId).to.eql('firefox-firefox-stable')
expect(ctx.actions.project.launchProject).to.have.been.calledWith(
ctx.coreData.currentTestingType, undefined, o.sinon.match(new RegExp('cypress\-in\-cypress\/src\/TestComponent\.spec\.jsx$')),
ctx.coreData.currentTestingType, { shouldLaunchNewTab: false }, o.sinon.match(new RegExp('cypress\-in\-cypress\/src\/TestComponent\.spec\.jsx$')),
)
})
})
Expand Down
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/cypress/e2e/top-nav.cy.ts
Expand Up @@ -110,7 +110,7 @@ describe('App Top Nav Workflows', () => {
expect(ctx.actions.browser.setActiveBrowserById).to.have.been.calledWith(browserId)
expect(genId).to.eql('edge-chromium-stable')
expect(ctx.actions.project.launchProject).to.have.been.calledWith(
ctx.coreData.currentTestingType, undefined, undefined,
ctx.coreData.currentTestingType, { shouldLaunchNewTab: false }, undefined,
)
})
})
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

"""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()?.server.reset()
},
},
electronApi: {
openExternal (url: string) {
Expand Down

5 comments on commit 6c37403

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 6c37403 Dec 12, 2022

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 platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.1.0/linux-arm64/develop-6c374031d7460cbf02a4973940482b4f3d30801a/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 6c37403 Dec 12, 2022

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 platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.1.0/linux-x64/develop-6c374031d7460cbf02a4973940482b4f3d30801a/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 6c37403 Dec 12, 2022

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 platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.1.0/darwin-x64/develop-6c374031d7460cbf02a4973940482b4f3d30801a/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 6c37403 Dec 12, 2022

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 platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.1.0/darwin-arm64/develop-6c374031d7460cbf02a4973940482b4f3d30801a/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 6c37403 Dec 12, 2022

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 platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.1.0/win32-x64/develop-6c374031d7460cbf02a4973940482b4f3d30801a/cypress.tgz

Please sign in to comment.