-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
docs: add workaround for TS custom commands #5454
docs: add workaround for TS custom commands #5454
Conversation
|
Name | Link |
---|---|
🔨 Latest commit | 91572f5 |
✅ Deploy Preview for benevolent-cat-040f48 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
|
dc737a8
to
643621a
Compare
Hi @marmaladebacon you will need to sign the CLA before this PR can be merged. |
From [email protected], if you are using TypeScript and have `sideEffects:false` set in your package.json, custom Cypress commands will not be registered by the common pattern of writing the commands in one file and having them be run as a side effect of importing the file. For example: | ||
|
||
```typescript title="/cypress/support/commands.ts" | ||
Cypress.Commands.add("login", (email, password) => { ... }) | ||
``` | ||
|
||
```typescript title="/cypress/support/e2e.ts" | ||
import './commands' | ||
``` | ||
|
||
To work around this issue, you can wrap the Cypress commands in a function that will be imported by the support file. | ||
|
||
```typescript title="/cypress/support/commands.ts" | ||
export function registerCommands(){ | ||
Cypress.Commands.add("login", (email, password) => { ... }) | ||
} | ||
``` | ||
|
||
```typescript title="/cypress/support/e2e.ts" | ||
import { registerCommands } from './commands' | ||
registerCommands() | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "@" actually creates a mailto:
link in the markdown. Here are some edits to give more context
From [email protected], if you are using TypeScript and have `sideEffects:false` set in your package.json, custom Cypress commands will not be registered by the common pattern of writing the commands in one file and having them be run as a side effect of importing the file. For example: | |
```typescript title="/cypress/support/commands.ts" | |
Cypress.Commands.add("login", (email, password) => { ... }) | |
``` | |
```typescript title="/cypress/support/e2e.ts" | |
import './commands' | |
``` | |
To work around this issue, you can wrap the Cypress commands in a function that will be imported by the support file. | |
```typescript title="/cypress/support/commands.ts" | |
export function registerCommands(){ | |
Cypress.Commands.add("login", (email, password) => { ... }) | |
} | |
``` | |
```typescript title="/cypress/support/e2e.ts" | |
import { registerCommands } from './commands' | |
registerCommands() | |
``` | |
Cypress [12.17.4](/guides/references/changelog#12-17-4) includes a webpack upgrade (v4 to v5), which [tree shakes out](https://webpack.js.org/blog/2020-10-10-webpack-5-release/#inner-module-tree-shaking) any side-effects or files that only include side-effects. | |
If you are using TypeScript and have `sideEffects:false` set in your package.json, custom Cypress commands will not be registered by the common pattern of writing the commands in one file and having them be run as a side effect of importing the file. For example: | |
```typescript | |
// cypress/support/commands.ts | |
Cypress.Commands.add("login", (email, password) => { ... }) |
// cypress/support/e2e.ts
import './commands'
To support sideEffects:false
, you can wrap the Cypress commands in a function that will be imported by the support file.
// cypress/support/commands.ts
export function registerCommands(){
Cypress.Commands.add("login", (email, password) => { ... })
}
// cypress/support/e2e.ts
import { registerCommands } from './commands'
registerCommands()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, i've added the suggested changes in the latest commit. Let me know if i missed anything, i had to do it manually because the markdown syntax probably broke halfway through the suggestion.
d9a3be1
to
1d4f735
Compare
1d4f735
to
83ecd6a
Compare
Co-authored-by: Paul Jaffre <[email protected]>
Co-authored-by: Paul Jaffre <[email protected]>
Co-authored-by: Paul Jaffre <[email protected]>
Co-authored-by: Paul Jaffre <[email protected]>
Thank you for the contribution @marmaladebacon This was getting crazier and crazier with the formatting. Instead of wrestling with the markdown issues in the GH web UI, I just ported this over to this PR and merged it. Much appreciated! |
closes #27641