Skip to content

Commit

Permalink
fix: switching from ct to e2e (non-configured) does not go through se…
Browse files Browse the repository at this point in the history
…tup (#21607)
  • Loading branch information
ZachJW34 authored May 25, 2022
1 parent f2bce02 commit 08b72dc
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 26 deletions.
4 changes: 3 additions & 1 deletion packages/app/cypress/e2e/sidebar_navigation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})
})
Expand Down
14 changes: 14 additions & 0 deletions packages/data-context/src/actions/ProjectActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
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()
}
}
}
3 changes: 0 additions & 3 deletions packages/graphql/schemas/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 1 addition & 22 deletions packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down
45 changes: 45 additions & 0 deletions packages/launchpad/cypress/e2e/project-setup.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})
})

3 comments on commit 08b72dc

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 08b72dc May 25, 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/10.0.0/linux-x64/develop-08b72dc383bbe92853666864d971982050ac7d8e/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 08b72dc May 26, 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/10.0.0/darwin-x64/develop-08b72dc383bbe92853666864d971982050ac7d8e/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 08b72dc May 26, 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/10.0.0/win32-x64/develop-08b72dc383bbe92853666864d971982050ac7d8e/cypress.tgz

Please sign in to comment.