Skip to content

Conversation

@lmiller1990
Copy link
Contributor

@lmiller1990 lmiller1990 commented Apr 6, 2022

note: forked from #20893
note: the generated file will be invalid until https://cypress-io.atlassian.net/browse/UNIFY-1386 lands, which bundles the mount commands in the binary.

User facing changelog

Scaffold correct supportFile for component testing, including adding custom mount command and type definitions, if using TypeScript.

Additional details

We register a convinient cy.mount command for CT when scaffolding a new project, or migrating an existing one.

Example for a project using React and TypeScript:

// ***********************************************************
// This example support/component.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************
// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
import { mount } from 'cypress/react'
import type { MountReturn } from 'cypress/react'

// Augment the Cypress namespace to include type definitions for
// your custom command.
// Alternatively, can be defined in cypress/support/component.d.ts
// with a <reference path="./component" /> at the top of your spec.
declare global {
  namespace Cypress {
    interface Chainable {
      mount(...): Cypress.Chainable<MountReturn>
    }
  }
}

Cypress.Commands.add('mount', mount)

// Example use:
// cy.mount(<MyComponent />)

How has the user experience changed?

Better scaffolding for CT based on your framework.

PR Tasks

  • Have tests been added/updated?
  • Has the original issue (or this PR, if no issue exists) been tagged with a release in ZenHub? (user-facing changes only)
  • Has a PR for user-facing changes been opened in cypress-documentation?
  • Have API changes been updated in the type definitions?
  • Have new configuration options been added to the cypress.schema.json?

@lmiller1990 lmiller1990 requested review from a team as code owners April 6, 2022 03:07
@lmiller1990 lmiller1990 requested review from jennifer-shehane and removed request for a team April 6, 2022 03:07
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Apr 6, 2022

Thanks for taking the time to open a PR!

@lmiller1990 lmiller1990 requested review from BlueWinds and ZachJW34 and removed request for a team and jennifer-shehane April 6, 2022 03:08
private ensureDir (type: 'component' | 'e2e' | 'fixtures') {
return this.ctx.fs.ensureDir(path.join(this.projectRoot, 'cypress', type))
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to packages/scaffold-config, trying to consolidate all the scaffolding code in one place.

@cypress
Copy link

cypress bot commented Apr 6, 2022



Test summary

17812 0 217 0Flakiness 1


Run details

Project cypress
Status Passed
Commit d304fba
Started Apr 7, 2022 1:35 AM
Ended Apr 7, 2022 1:46 AM
Duration 11:49 💡
OS Linux Debian - 10.10
Browser Multiple

View run in Cypress Dashboard ➡️


Flakiness

cypress/e2e/commands/xhr.cy.js Flakiness
1 ... > no status when request isnt forced 404

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@lmiller1990 lmiller1990 changed the title feat(launchpad): scaffold and register cy.mount command for CT feat: scaffold and register cy.mount command for CT Apr 6, 2022
@lmiller1990 lmiller1990 requested review from JessicaSachs and tgriesser and removed request for JessicaSachs and ryanthemanuel April 6, 2022 04:04
Copy link
Contributor

@ZachJW34 ZachJW34 left a comment

Choose a reason for hiding this comment

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

Straightforward, works great. Moving the remaining scaffolding logic is 🔥

declare global {
namespace Cypress {
interface Chainable {
mount(...): Cypress.Chainable<MountReturn>
Copy link
Member

Choose a reason for hiding this comment

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

This ... here isn't meant to be what we actually ship, I mostly meant it to indicate that it should be is supposed to be filled in with the appropriate mount signature dependent on the framework chosen

Copy link
Member

Choose a reason for hiding this comment

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

I guess it could be as simple as

declare global {
  namespace Cypress {
    interface Chainable {
      mount: typeof mount
    }
  }
}      

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤦‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. d304fba

@tgriesser tgriesser self-requested a review April 7, 2022 16:57
@lmiller1990 lmiller1990 merged commit 10c7f92 into lmiller1990/UNIFY-1402 Apr 13, 2022
@lmiller1990 lmiller1990 deleted the lmiller1990/UNIFY-1387 branch April 13, 2022 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants