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: Detect CT framework when unconfigured project opened with --component #26306

Merged
merged 6 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:**

Expand Down
4 changes: 4 additions & 0 deletions packages/data-context/src/actions/ProjectActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ export class ProjectActions {
this.ctx.lifecycleManager.setAndLoadCurrentTestingType(type)
}

async initializeProjectSetup (type: TestingType) {
await this.ctx.lifecycleManager.initializeProjectSetup(type)
}

async setCurrentProject (projectRoot: string) {
await this.updateProjectList(() => this.api.insertProjectToCache(projectRoot))

Expand Down
25 changes: 21 additions & 4 deletions packages/data-context/src/data/ProjectLifecycleManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -752,10 +752,27 @@ 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()
}
await 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()
}
}

Expand Down
12 changes: 1 addition & 11 deletions packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
await ctx.actions.project.initializeProjectSetup(args.testingType)

return {}
},
Expand Down
33 changes: 25 additions & 8 deletions packages/launchpad/cypress/e2e/open-mode.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down