From 08b72dc383bbe92853666864d971982050ac7d8e Mon Sep 17 00:00:00 2001 From: Zachary Williams Date: Wed, 25 May 2022 18:45:45 -0500 Subject: [PATCH] fix: switching from ct to e2e (non-configured) does not go through setup (#21607) --- .../app/cypress/e2e/sidebar_navigation.cy.ts | 4 +- .../src/actions/ProjectActions.ts | 14 ++++++ packages/graphql/schemas/schema.graphql | 3 -- .../schemaTypes/objectTypes/gql-Mutation.ts | 23 +--------- .../launchpad/cypress/e2e/project-setup.cy.ts | 45 +++++++++++++++++++ 5 files changed, 63 insertions(+), 26 deletions(-) diff --git a/packages/app/cypress/e2e/sidebar_navigation.cy.ts b/packages/app/cypress/e2e/sidebar_navigation.cy.ts index c8e937c94081..d1218d2a5e0b 100644 --- a/packages/app/cypress/e2e/sidebar_navigation.cy.ts +++ b/packages/app/cypress/e2e/sidebar_navigation.cy.ts @@ -321,16 +321,18 @@ describe('Sidebar Navigation', () => { cy.withCtx((ctx, o) => { o.sinon.stub(ctx.actions.project, 'setAndLoadCurrentTestingType') o.sinon.stub(ctx.actions.project, 'reconfigureProject').resolves() + o.sinon.stub(ctx.actions.wizard, 'scaffoldTestingType').resolves() }) cy.get('[data-cy-testingtype="e2e"]').within(() => { cy.contains('Not Configured') }).click() - cy.withCtx((ctx) => { + cy.withRetryableCtx((ctx) => { expect(ctx.coreData.app.relaunchBrowser).eq(false) expect(ctx.actions.project.setAndLoadCurrentTestingType).to.have.been.calledWith('e2e') expect(ctx.actions.project.reconfigureProject).to.have.been.called + expect(ctx.actions.wizard.scaffoldTestingType).to.have.been.called }) }) }) diff --git a/packages/data-context/src/actions/ProjectActions.ts b/packages/data-context/src/actions/ProjectActions.ts index 556bbc548acb..c66fd22591d5 100644 --- a/packages/data-context/src/actions/ProjectActions.ts +++ b/packages/data-context/src/actions/ProjectActions.ts @@ -489,4 +489,18 @@ export class ProjectActions { return this.api.isListening(baseUrl) .catch(() => this.ctx.onWarning(getError('CANNOT_CONNECT_BASE_URL_WARNING', baseUrl))) } + + async switchTestingTypesAndRelaunch (testingType: Cypress.TestingType): Promise { + const isTestingTypeConfigured = this.ctx.lifecycleManager.isTestingTypeConfigured(testingType) + + this.ctx.project.setRelaunchBrowser(isTestingTypeConfigured) + this.setAndLoadCurrentTestingType(testingType) + + await this.reconfigureProject() + + if (testingType === 'e2e' && !isTestingTypeConfigured) { + // E2E doesn't have a wizard, so if we have a testing type on load we just create/update their cypress.config.js. + await this.ctx.actions.wizard.scaffoldTestingType() + } + } } diff --git a/packages/graphql/schemas/schema.graphql b/packages/graphql/schemas/schema.graphql index f93ea0a6ff08..042cb3fedceb 100644 --- a/packages/graphql/schemas/schema.graphql +++ b/packages/graphql/schemas/schema.graphql @@ -1105,9 +1105,6 @@ type Mutation { """Save the prompt-shown state for this project""" setPromptShown(slug: String!): Boolean - """Set the selected testing type, and reconfigure the project""" - setTestingTypeAndReconfigureProject(isApp: Boolean!, testingType: TestingTypeEnum!): Query - """Switch Testing type and relaunch browser""" switchTestingTypeAndRelaunch(testingType: TestingTypeEnum!): Boolean diff --git a/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts b/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts index 9d5f44dec47b..7b41a2ffccda 100644 --- a/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts +++ b/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts @@ -606,33 +606,12 @@ export const mutation = mutationType({ testingType: nonNull(arg({ type: TestingTypeEnum })), }, resolve: async (source, args, ctx) => { - ctx.project.setRelaunchBrowser(ctx.lifecycleManager.isTestingTypeConfigured(args.testingType)) - ctx.actions.project.setAndLoadCurrentTestingType(args.testingType) - await ctx.actions.project.reconfigureProject() + await ctx.actions.project.switchTestingTypesAndRelaunch(args.testingType) return true }, }) - t.field('setTestingTypeAndReconfigureProject', { - description: 'Set the selected testing type, and reconfigure the project', - type: Query, - args: { - testingType: nonNull(arg({ type: TestingTypeEnum })), - isApp: nonNull(booleanArg()), - }, - resolve: async (source, args, ctx) => { - ctx.actions.project.setForceReconfigureProjectByTestingType({ forceReconfigureProject: true, testingType: args.testingType }) - ctx.actions.project.setAndLoadCurrentTestingType(args.testingType) - - if (args.isApp) { - await ctx.actions.project.reconfigureProject() - } - - return {} - }, - }) - t.field('dismissWarning', { type: Query, description: `Dismisses a warning displayed by the frontend`, diff --git a/packages/launchpad/cypress/e2e/project-setup.cy.ts b/packages/launchpad/cypress/e2e/project-setup.cy.ts index 966da15a4efd..a98ba2adae1c 100644 --- a/packages/launchpad/cypress/e2e/project-setup.cy.ts +++ b/packages/launchpad/cypress/e2e/project-setup.cy.ts @@ -629,4 +629,49 @@ describe('Launchpad: Setup Project', () => { .should('equal', 'https://on.cypress.io/guides/configuration') }) }) + + describe('switch testing types', () => { + it('takes the user to first step of e2e setup when switching from app', () => { + scaffoldAndOpenProject('pristine-with-ct-testing') + cy.visitLaunchpad() + verifyWelcomePage({ e2eIsConfigured: false, ctIsConfigured: true }) + + cy.get('[data-cy-testingtype="component"]').click() + cy.contains('h1', 'Choose a Browser') + + // Execute same function that is called in the browser to switch testing types + cy.withCtx(async (ctx, { sinon }) => { + sinon.stub(ctx.actions.browser, 'closeBrowser') + sinon.stub(ctx.actions.electron, 'refreshBrowserWindow') + sinon.stub(ctx.actions.electron, 'showBrowserWindow') + await ctx.actions.project.switchTestingTypesAndRelaunch('e2e') + }) + + cy.reload() + + cy.contains('h1', 'Configuration Files') + verifyScaffoldedFiles('e2e') + }) + + it('takes the user to first step of ct setup when switching from app', () => { + scaffoldAndOpenProject('pristine-with-e2e-testing') + cy.visitLaunchpad() + verifyWelcomePage({ e2eIsConfigured: true, ctIsConfigured: false }) + + cy.get('[data-cy-testingtype="e2e"]').click() + cy.contains('h1', 'Choose a Browser') + + // Execute same function that is called in the browser to switch testing types + cy.withCtx(async (ctx, { sinon }) => { + sinon.stub(ctx.actions.browser, 'closeBrowser') + sinon.stub(ctx.actions.electron, 'refreshBrowserWindow') + sinon.stub(ctx.actions.electron, 'showBrowserWindow') + await ctx.actions.project.switchTestingTypesAndRelaunch('component') + }) + + cy.reload() + + cy.contains('h1', 'Project Setup') + }) + }) })