From e155ee6ccb1d39721b84d4555cc4f533d2938b63 Mon Sep 17 00:00:00 2001 From: Mike Plummer Date: Thu, 30 Mar 2023 08:46:00 -0500 Subject: [PATCH 1/4] fix: Detect CT framework when unconfigured project opened with `--component` --- .../src/data/ProjectLifecycleManager.ts | 11 +++++-- .../launchpad/cypress/e2e/open-mode.cy.ts | 33 ++++++++++++++----- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/packages/data-context/src/data/ProjectLifecycleManager.ts b/packages/data-context/src/data/ProjectLifecycleManager.ts index f163e804143a..248ef98d37d6 100644 --- a/packages/data-context/src/data/ProjectLifecycleManager.ts +++ b/packages/data-context/src/data/ProjectLifecycleManager.ts @@ -752,9 +752,14 @@ export class ProjectLifecycleManager { if (this._projectRoot && testingType && await this.waitForInitializeSuccess()) { this.setAndLoadCurrentTestingType(testingType) - if (testingType === 'e2e' && !this.ctx.migration.needsCypressJsonMigration() && !this.isTestingTypeConfigured(testingType)) { - // 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() + if (!this.isTestingTypeConfigured(testingType)) { + if (testingType === 'e2e' && !this.ctx.migration.needsCypressJsonMigration()) { + // 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() + } else if (testingType === 'component') { + await this.ctx.actions.wizard.detectFrameworks() + await this.ctx.actions.wizard.initialize() + } } } } diff --git a/packages/launchpad/cypress/e2e/open-mode.cy.ts b/packages/launchpad/cypress/e2e/open-mode.cy.ts index cf813aabeede..6cf172032231 100644 --- a/packages/launchpad/cypress/e2e/open-mode.cy.ts +++ b/packages/launchpad/cypress/e2e/open-mode.cy.ts @@ -109,14 +109,31 @@ describe('Launchpad: Open Mode', () => { }) }) - it('goes to component test onboarding when launched with --component and not configured', () => { - cy.scaffoldProject('launchpad') - cy.openProject('launchpad', ['--component']) - cy.visitLaunchpad() - cy.skipWelcome() - cy.get('[data-cy=header-bar-content]').contains('component testing', { matchCase: false }) - // Component testing is not configured for the todo project - cy.get('h1').should('contain', 'Project setup') + describe('when launched with --component and not configured', () => { + beforeEach(() => { + cy.scaffoldProject('react-vite-ts-unconfigured') + cy.openProject('react-vite-ts-unconfigured', ['--component']) + cy.visitLaunchpad() + cy.skipWelcome() + }) + + it('goes to component test onboarding', () => { + cy.get('[data-cy=header-bar-content]').contains('component testing', { matchCase: false }) + // Component testing is not configured for the todo project + cy.get('h1').should('contain', 'Project setup') + }) + + it('detects CT project framework', () => { + cy.get('[data-testid="select-framework"]').within(() => { + cy.contains('React.js').should('be.visible') + cy.contains('(detected)').should('be.visible') + }) + + cy.get('[data-testid="select-bundler"]').within(() => { + cy.contains('Vite').should('be.visible') + cy.contains('(detected)').should('be.visible') + }) + }) }) // since circle cannot have firefox installed by default, From 1554dc8875cae59080c089b3e77ec155ae6dd334 Mon Sep 17 00:00:00 2001 From: Mike Plummer Date: Thu, 30 Mar 2023 09:18:49 -0500 Subject: [PATCH 2/4] Add changelog entry --- cli/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 079fcd0db276..85e2cf6c665e 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -6,6 +6,7 @@ _Released 04/11/2023 (PENDING)_ **Bugfixes:** - Capture the [Azure](https://azure.microsoft.com/) CI provider's environment variable [`SYSTEM_PULLREQUEST_PULLREQUESTNUMBER`](https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml#system-variables-devops-services) to display the linked PR number in the Cloud. Addressed in [#26215](https://github.com/cypress-io/cypress/pull/26215). + - Fixed an issue in the onboarding wizard where project framework & bundler would not be auto-detected when opening directly into component testing mode using the `--component` CLI flag. Fixes [#22777](https://github.com/cypress-io/cypress/issues/22777). **Dependency Updates:** From a449fa108d250fd7c016b7d72c7dadc6c733f662 Mon Sep 17 00:00:00 2001 From: Mike Plummer Date: Fri, 31 Mar 2023 09:23:31 -0500 Subject: [PATCH 3/4] Refactor common logic into shared fn --- .../src/actions/ProjectActions.ts | 4 +++ .../src/data/ProjectLifecycleManager.ts | 30 +++++++++++++------ .../schemaTypes/objectTypes/gql-Mutation.ts | 12 +------- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/packages/data-context/src/actions/ProjectActions.ts b/packages/data-context/src/actions/ProjectActions.ts index a0d0e887dd61..1bc1cccc50e4 100644 --- a/packages/data-context/src/actions/ProjectActions.ts +++ b/packages/data-context/src/actions/ProjectActions.ts @@ -130,6 +130,10 @@ export class ProjectActions { this.ctx.lifecycleManager.setAndLoadCurrentTestingType(type) } + initializeProjectSetup (type: TestingType) { + this.ctx.lifecycleManager.initializeProjectSetup(type) + } + async setCurrentProject (projectRoot: string) { await this.updateProjectList(() => this.api.insertProjectToCache(projectRoot)) diff --git a/packages/data-context/src/data/ProjectLifecycleManager.ts b/packages/data-context/src/data/ProjectLifecycleManager.ts index 248ef98d37d6..edbb39a39a36 100644 --- a/packages/data-context/src/data/ProjectLifecycleManager.ts +++ b/packages/data-context/src/data/ProjectLifecycleManager.ts @@ -752,15 +752,27 @@ export class ProjectLifecycleManager { if (this._projectRoot && testingType && await this.waitForInitializeSuccess()) { this.setAndLoadCurrentTestingType(testingType) - if (!this.isTestingTypeConfigured(testingType)) { - if (testingType === 'e2e' && !this.ctx.migration.needsCypressJsonMigration()) { - // 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() - } else if (testingType === 'component') { - await this.ctx.actions.wizard.detectFrameworks() - await this.ctx.actions.wizard.initialize() - } - } + this.initializeProjectSetup(testingType) + } + } + + /** + * Prepare the setup process for a project if one exists, otherwise complete setup + * + * @param testingType + * @returns + */ + async initializeProjectSetup (testingType: TestingType) { + if (this.isTestingTypeConfigured(testingType)) { + return + } + + if (testingType === 'e2e' && !this.ctx.migration.needsCypressJsonMigration()) { + // 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() + } else if (testingType === 'component') { + await this.ctx.actions.wizard.detectFrameworks() + await this.ctx.actions.wizard.initialize() } } diff --git a/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts b/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts index 9da9fe8c3724..77eea72f7574 100644 --- a/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts +++ b/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts @@ -178,17 +178,7 @@ export const mutation = mutationType({ resolve: async (source, args, ctx) => { ctx.actions.project.setAndLoadCurrentTestingType(args.testingType) - // if necessary init the wizard for configuration - if (ctx.coreData.currentTestingType && !ctx.lifecycleManager.isTestingTypeConfigured(ctx.coreData.currentTestingType)) { - // Component Testing has a wizard to help users configure their project - if (ctx.coreData.currentTestingType === 'component') { - await ctx.actions.wizard.detectFrameworks() - await ctx.actions.wizard.initialize() - } else { - // E2E doesn't have such a wizard, we just create/update their cypress.config.js. - await ctx.actions.wizard.scaffoldTestingType() - } - } + ctx.actions.project.initializeProjectSetup(args.testingType) return {} }, From 43d208fdcf5f34f76f8e3b32159a56f72c65fe00 Mon Sep 17 00:00:00 2001 From: Mike Plummer Date: Fri, 31 Mar 2023 09:57:56 -0500 Subject: [PATCH 4/4] Add missing awaits --- packages/data-context/src/actions/ProjectActions.ts | 4 ++-- packages/data-context/src/data/ProjectLifecycleManager.ts | 2 +- packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/data-context/src/actions/ProjectActions.ts b/packages/data-context/src/actions/ProjectActions.ts index 1bc1cccc50e4..e0f52325c0b1 100644 --- a/packages/data-context/src/actions/ProjectActions.ts +++ b/packages/data-context/src/actions/ProjectActions.ts @@ -130,8 +130,8 @@ export class ProjectActions { this.ctx.lifecycleManager.setAndLoadCurrentTestingType(type) } - initializeProjectSetup (type: TestingType) { - this.ctx.lifecycleManager.initializeProjectSetup(type) + async initializeProjectSetup (type: TestingType) { + await this.ctx.lifecycleManager.initializeProjectSetup(type) } async setCurrentProject (projectRoot: string) { diff --git a/packages/data-context/src/data/ProjectLifecycleManager.ts b/packages/data-context/src/data/ProjectLifecycleManager.ts index edbb39a39a36..fdce2f5c1fa0 100644 --- a/packages/data-context/src/data/ProjectLifecycleManager.ts +++ b/packages/data-context/src/data/ProjectLifecycleManager.ts @@ -752,7 +752,7 @@ export class ProjectLifecycleManager { if (this._projectRoot && testingType && await this.waitForInitializeSuccess()) { this.setAndLoadCurrentTestingType(testingType) - this.initializeProjectSetup(testingType) + await this.initializeProjectSetup(testingType) } } diff --git a/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts b/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts index 77eea72f7574..058f9e01e1e5 100644 --- a/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts +++ b/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts @@ -178,7 +178,7 @@ export const mutation = mutationType({ resolve: async (source, args, ctx) => { ctx.actions.project.setAndLoadCurrentTestingType(args.testingType) - ctx.actions.project.initializeProjectSetup(args.testingType) + await ctx.actions.project.initializeProjectSetup(args.testingType) return {} },