diff --git a/packages/app/cypress/e2e/cypress-in-cypress-component.cy.ts b/packages/app/cypress/e2e/cypress-in-cypress-component.cy.ts index 7d1ecdd045d6..46f3f72cff39 100644 --- a/packages/app/cypress/e2e/cypress-in-cypress-component.cy.ts +++ b/packages/app/cypress/e2e/cypress-in-cypress-component.cy.ts @@ -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$')), ) }) }) diff --git a/packages/app/cypress/e2e/run-all-specs.cy.ts b/packages/app/cypress/e2e/run-all-specs.cy.ts index 342de684b079..2acc735672f5 100644 --- a/packages/app/cypress/e2e/run-all-specs.cy.ts +++ b/packages/app/cypress/e2e/run-all-specs.cy.ts @@ -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) @@ -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 }) diff --git a/packages/app/cypress/e2e/top-nav.cy.ts b/packages/app/cypress/e2e/top-nav.cy.ts index 0a324de0360d..87819647e20a 100644 --- a/packages/app/cypress/e2e/top-nav.cy.ts +++ b/packages/app/cypress/e2e/top-nav.cy.ts @@ -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, ) }) }) diff --git a/packages/app/src/store/run-all-specs-store.ts b/packages/app/src/store/run-all-specs-store.ts index 066360cdf46a..d1f50b7bd218 100644 --- a/packages/app/src/store/run-all-specs-store.ts +++ b/packages/app/src/store/run-all-specs-store.ts @@ -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 } } diff --git a/packages/data-context/src/actions/ProjectActions.ts b/packages/data-context/src/actions/ProjectActions.ts index 605d499de02b..2a200c767a53 100644 --- a/packages/data-context/src/actions/ProjectActions.ts +++ b/packages/data-context/src/actions/ProjectActions.ts @@ -22,7 +22,7 @@ export interface ProjectApiShape { * order for CT to startup */ openProjectCreate(args: InitializeProjectOptions, options: OpenProjectLaunchOptions): Promise - launchProject(browser: FoundBrowser, spec: Cypress.Spec, options?: OpenProjectLaunchOpts): Promise + launchProject(browser: FoundBrowser, spec: Cypress.Spec, options?: Partial): Promise insertProjectToCache(projectRoot: string): Promise removeProjectFromCache(projectRoot: string): Promise getProjectRootsFromCache(): Promise @@ -46,6 +46,8 @@ export interface ProjectApiShape { emitter: EventEmitter } isListening: (url: string) => Promise + resetBrowserTabsForNextTest(shouldKeepTabOpen: boolean): Promise + resetServer(): void } export interface FindSpecs { @@ -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, specPath?: string | null) { if (!this.ctx.currentProject) { return null } @@ -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 diff --git a/packages/graphql/schemas/schema.graphql b/packages/graphql/schemas/schema.graphql index 42f5379c2919..2dc07eb675c1 100644 --- a/packages/graphql/schemas/schema.graphql +++ b/packages/graphql/schemas/schema.graphql @@ -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( diff --git a/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts b/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts index 52fc5dae1699..d47fe99f7413 100644 --- a/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts +++ b/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts @@ -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 }, diff --git a/packages/server/lib/makeDataContext.ts b/packages/server/lib/makeDataContext.ts index 466e2f52476d..82857e8bc6cb 100644 --- a/packages/server/lib/makeDataContext.ts +++ b/packages/server/lib/makeDataContext.ts @@ -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) {