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: switching from ct to e2e (non-configured) does not go through setup #21607

Merged
merged 6 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -503,4 +503,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', {
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this dead code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'll add more comments in the future when making changes like this

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')
})
})
})