Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

Update cypress dependency #32

Closed
yagudaev opened this issue Jul 29, 2020 · 4 comments
Closed

Update cypress dependency #32

yagudaev opened this issue Jul 29, 2020 · 4 comments
Labels
dependencies Pull requests that update a dependency file

Comments

@yagudaev
Copy link

Can we change the dependency of cypress to be

"cypress": ">= 4.9.0"

So that it works for 4.10, 4.11 and so on.

As a workaround I did:

// package.json
{
  "devDependencies": {
    "cypress": "^4.11.0",
   } ,
  "resolutions": {
    "cypress": "^4.11.0"
   }
}
@ArturT
Copy link
Member

ArturT commented Jul 30, 2020

Hey @yagudaev

This change "cypress": ">= 4.9.0" is not needed but I did it and released a new version of @knapsack-pro/cypress where I applied your suggestion.

This "cypress": ">= 4.9.0" will make @knapsack-pro/cypress work also with Cypress 5.x if it will be ever released in the future.

Here is PR with my change: #33

After the fact. Once I released above change I realized that the "cypress": "^4.9.0" was already good enough so your suggestion was not needed.
https://docs.npmjs.com/misc/semver#caret-ranges-123-025-004
Caret range allows updating minor and patch version so any 4.x version of cypress should be possible to install.

What you did in package.json is expect. Programmer should be able to control what Cypress version he wants to use. You should explicitly specify Cypress version you want to use.

{
  "devDependencies": {
    "@knapsack-pro/cypress": "3.1.0",
    "cypress": "^4.11.0",
  },
}

Side thought. A while ago someone suggest to me to use peerDepenency https://docs.npmjs.com/files/package.json#peerdependencies so I'm thinking about it as a solution to make it more explicit for programmers to manage test runner like Cypress or Jest version that is used in their project.

@ArturT ArturT closed this as completed Jul 30, 2020
@ArturT ArturT added the dependencies Pull requests that update a dependency file label Jul 30, 2020
@ArturT
Copy link
Member

ArturT commented Aug 1, 2020

I consulted this bug with @rafaltrzop who initially helped develop the project.

It made me realized that I did not understand the full picture.

@yagudaev You are using https://www.npmjs.com/package/npm-force-resolutions package to force installing a specific version of Cypress. This explains why in your project you have resolutions.

// package.json of your project
{
  "devDependencies": {
    "cypress": "^4.11.0",
   } ,
  "resolutions": {
    "cypress": "^4.11.0"
   }
}

If you wouldn't use resolutions then the fact that I added "cypress": ">= 4.9.0" in package.json for @knapsack-pro/cypress it would do nothing. When you add @knapsack-pro/cypress to your project package.json then knapsack will be installed with cypress version exactly specified inside of package-lock.json of @knapsack-pro/cypress. Because of that when you will run tests with knapsack then it will use old Cypress version.
But when you use Cypress in development environment without knapsack then you will use newer version of cypress.

This could lead to bugs because someone in the development environment may use new cypress features but on CI he will use @knapsack-pro/cypress with older Cypress version.

To fix this problem we should use peerDepenency specified in package.json for @knapsack-pro/cypress. Then when someone will install @knapsack-pro/cypress he must also explicitly install Cypress in his project package.json (we could add info about it in our readme to make installation smooth because not every developer may be familiar with peerDependency). Thanks to that developer will control what version of Cypress is used and exactly the same Cypress version will be used in development when running tests without knapsack (only with cypress) and the same version of cypress will be used on CI when running tests with @knapsack-pro/cypress.

FYI @shadre

@yagudaev
Copy link
Author

yagudaev commented Aug 5, 2020

Thank you @ArturT for the quick and detailed response.

@ArturT
Copy link
Member

ArturT commented Aug 26, 2020

@yagudaev I've released a new version of @knapsack-pro/cypress 4.0.0. It uses peerDependency so it means your cypress version defined in your project package.json will be used by @knapsack-pro/cypress.

I also added support for Cypress 5.x so @knapsack-pro/cypress currently works with Cypress 3.x, 4.x, 5.x.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
dependencies Pull requests that update a dependency file
Projects
None yet
Development

No branches or pull requests

2 participants