Skip to content

Commit

Permalink
fix: Detect CT framework when unconfigured project opened with `--com…
Browse files Browse the repository at this point in the history
…ponent` (#26306)

Co-authored-by: Ryan Manuel <[email protected]>
  • Loading branch information
mike-plummer and ryanthemanuel authored Mar 31, 2023
1 parent 849d4d3 commit 1c385e0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 23 deletions.
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

5 comments on commit 1c385e0

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1c385e0 Mar 31, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.9.1/linux-x64/develop-1c385e0d424f4c5ee50541626a6af994dcb45b49/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1c385e0 Mar 31, 2023

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 arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.9.1/linux-arm64/develop-1c385e0d424f4c5ee50541626a6af994dcb45b49/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1c385e0 Mar 31, 2023

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 arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.9.1/darwin-arm64/develop-1c385e0d424f4c5ee50541626a6af994dcb45b49/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1c385e0 Mar 31, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.9.1/darwin-x64/develop-1c385e0d424f4c5ee50541626a6af994dcb45b49/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1c385e0 Mar 31, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.9.1/win32-x64/develop-1c385e0d424f4c5ee50541626a6af994dcb45b49/cypress.tgz

Please sign in to comment.