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

Change in behaviour from 12.17.3 to 12.17.4 #27641

Closed
marmaladebacon opened this issue Aug 23, 2023 · 4 comments
Closed

Change in behaviour from 12.17.3 to 12.17.4 #27641

marmaladebacon opened this issue Aug 23, 2023 · 4 comments
Labels
stale no activity on this issue for a long period topic: typescript v 12.17.4 🐛

Comments

@marmaladebacon
Copy link

marmaladebacon commented Aug 23, 2023

Current behavior

Hi,
Upgrading from [email protected] to [email protected] introduces a breaking change whereby if you have sideEffects:false set in your package.json, and you're using TypeScript, custom cypress commands will not be registered using the recommended/scaffolded path mentioned in the docs: https://docs.cypress.io/api/cypress-api/custom-commands#__docusaurus_skipToContent_fallback

Should we add a note to the documentation so that users are aware of the need to either have sideEffects undefined, set to 'true', or set to the array containing the path for the command files eg ['cypress/**/*'] .

Alternatively, we liked wrapping the commands in a exported function and then importing and calling that function in the supportFile so that we don't rely on importing for side-effects in the first place.

// cypress/support/commands.ts
export function registerCommands() {
  Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... });
  //other commands here
}
// cypress/support/e2e.ts
import {registerCommands} from './commands';
registerCommands();

At the very least we think that a documentation update should be made to clarify this change in behavior regarding sideEffects: false in a package.json.

It might be nice if cypress would automatically flag the cypress directory for side effects.

Desired behavior

In this situation, Cypress should work even with sideEffects set to false in a TypeScript project, or it should be documented.

Test code to reproduce

forked from https://github.com/cypress-io/cypress-test-tiny
marmaladebacon/cypress-repo-tiny-sideeffects#1

git clone and run npm run cypress:run

Cypress Version

12.17.4

Node version

v18.16.1

Operating System

macOs 13.4.1

Debug Logs

No response

Other

No response

@nagash77
Copy link
Contributor

Hi @marmaladebacon , thanks for opening this issue. It may be helpful to add something in the documentation around this specific use case. If you are interested you could open a PR in https://github.com/cypress-io/cypress-documentation which we could look over.

cmnord added a commit to cmnord/jep that referenced this issue Sep 21, 2023
cmnord added a commit to cmnord/jep that referenced this issue Sep 21, 2023
luzat added a commit to luzat/remix-indie-stack that referenced this issue Sep 27, 2023
Newer versions of Cypress (12.17.4+) do not load commands.ts because
of sideEffects: false in package.json:

cypress-io/cypress#27641

This is probably caused by Webpack 5 skipping the import. The fix is to
explicitly register the commands without relying on side effects. This
allows upgrading Cypress to 12.17.4+ or 13+.
@blakek
Copy link

blakek commented Oct 3, 2023

IMO this is a breaking change that'd be helpful to list in the migration guide. Thanks @marmaladebacon cause I would have never found this as the issue.

@cypress-app-bot
Copy link
Collaborator

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label Jun 15, 2024
@cypress-app-bot
Copy link
Collaborator

This issue has been closed due to inactivity.

@cypress-app-bot cypress-app-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale no activity on this issue for a long period topic: typescript v 12.17.4 🐛
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants