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

CYPRESS_DOWNLOAD_PATH_TEMPLATE only replace placeholder once #23670

Closed
ChrisKuBa opened this issue Sep 2, 2022 · 9 comments · Fixed by #25531
Closed

CYPRESS_DOWNLOAD_PATH_TEMPLATE only replace placeholder once #23670

ChrisKuBa opened this issue Sep 2, 2022 · 9 comments · Fixed by #25531
Assignees
Labels
cli E2E Issue related to end-to-end testing good first issue Good for newcomers Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team.

Comments

@ChrisKuBa
Copy link

ChrisKuBa commented Sep 2, 2022

Current behavior

CYPRESS_DOWNLOAD_PATH_TEMPLATE=http://tkeasydev.dst.tk-inline.net/nodejs/cypress/v${version}/cypress-${version}-${platform}-${arch}.zip

npm ERR! [FAILED] URL: http://tkeasydev.dst.tk-inline.net/nodejs/cypress/v10.7.0/cypress-${version}-win32-x64.zip

Desired behavior

should replace all occurences of a value

CYPRESS_DOWNLOAD_PATH_TEMPLATE=http://tkeasydev.dst.tk-inline.net/nodejs/cypress/v${version}/cypress-${version}-${platform}-${arch}.zip

http://tkeasydev.dst.tk-inline.net/nodejs/cypress/v10.7.0/cypress-10.7.0-win32-x64.zip

Test code to reproduce

no test available
failed on npm i

Cypress Version

10.7.0

Node version

18.8.0

Operating System

Win 10

Debug Logs

No response

Other

No response

@lmiller1990
Copy link
Contributor

lmiller1990 commented Sep 7, 2022

Docs for this feature (didn't know this was a thing): https://docs.cypress.io/guides/references/advanced-installation

I'm still confused, though. What is the CYPRESS_DOWNLOAD_PATH_TEMPLATE=http://tkeasydev.dst.tk-inline.net URL? This host doesn't seem to exist.

@lmiller1990
Copy link
Contributor

lmiller1990 commented Sep 7, 2022

I think this works just fine, though. I installed the latest version (v10.7.0). Then I did

$ CYPRESS_DOWNLOAD_PATH_TEMPLATE="https://cdn.cypress.io/desktop/10.5.0/darwin-x64/cypress.zip" yarn cypress install --force
yarn run v1.22.19
$ /Users/lachlan/code/dump/foo/node_modules/.bin/cypress install --force

Cypress 10.6.0 is installed in /Users/lachlan/Library/Caches/Cypress/10.7.0

Installing Cypress (version: 10.7.0)

✔  Downloaded Cypress
✔  Unzipped Cypress
✔  Finished Installation /Users/lachlan/Library/Caches/Cypress/10.7.0

You can now open Cypress by running: node_modules/.bin/cypress open

https://on.cypress.io/installing-cypress

✨  Done in 39.26s.
$ vi /Users/lachlan/Library/Caches/Cypress/10.7.0/Cypress.app/Contents/Resources/app/package.json
$ cat /Users/lachlan/Library/Caches/Cypress/10.7.0/Cypress.app/Contents/Resources/app/package.json
{
  "name": "cypress",
  "productName": "Cypress",
  "description": "Cypress.io end to end testing tool",
  "version": "10.5.0",
  "electronVersion": "19.0.8",
  "electronNodeVersion": "16.14.2",
  "main": "index.js",
  "env": "production"
}%

It's weird since you are installing a specific binary - so you've got a different cli version (the thing in node_modules/cypress to the actual binary, but it does what it's supposed to do (installs a specific version of the binary).

Let me know if I'm missing something, but it looks like this works as expected. I will re-open if there's more information.

@ChrisKuBa
Copy link
Author

Hi,

Problem: I'm behind a firewall at our company. Automatic downloading of many binaries is prohibited.
So the only option is to manually request a special download, verify the binary and store it internally. This is the only way to have all additional binaries used by nodejs dependencies available at install time.

Also, we use an internal path/filename format used by other companies, e.g
/~https://github.com/electron/electron/releases/
to store these binaries internally on a separate host/domain.

So I can't use your mirror https://cdn.cypress.io inside the CYPRESS_DOWNLOAD_PATH_TEMPLATE.

http://tkeasydev.dst.tk-inline.net is an internal domain. You cannot access it from the outside.

Before CYPRESS_DOWNLOAD_PATH_TEMPLATE, we use CYPRESS_INSTALL_BINARY with a hard-coded URI and version, and we often forgot to update this path as well when newer versions of Cypess were installed. So I'm grateful to have an option with dynamic/viriable parameters.

If replacing using the same variable multiple times is not an option for you, the only workaround I see is to change our internal storage format.

Thx

@nagash77 nagash77 reopened this Sep 7, 2022
@lmiller1990
Copy link
Contributor

Right, I understand the problem now.

I think we just need to use a regex here instead of replace, and that should fix the problem.

If you'd like to make a PR, that'd be great! I'm going to mark this as an good first issue, so either someone can pick it up now, or it can go into our backlog for internal prioritization.

@ChrisKuBa
Copy link
Author

Hi,

forking and running the repo on my windows machine fails completely. And yes I'm looking at CONTRIBUTING.md.
It fails on yarn start, because many commands start with "./" and Windows quit this with an error
The command "." is either misspelled or could not be found.
Even when dependency checks were ignored, many tests initially failed.

The fix is very simple:
extending all regular expressions by a g (global modifier)

.replace(/\\?\$\{endpoint\}/, endpoint)
.replace(/\\?\$\{platform\}/, platform)
.replace(/\\?\$\{arch\}/, arch)
.replace(/\\?\$\{version\}/, version)

to this

        .replace(/\\?\$\{endpoint\}/g, endpoint)
        .replace(/\\?\$\{platform\}/g, platform)
        .replace(/\\?\$\{arch\}/g, arch)
        .replace(/\\?\$\{version\}/g, version)

Also a test should be add after this

it('returns custom url from template with version', () => {
process.env.CYPRESS_DOWNLOAD_PATH_TEMPLATE = 'https://mycompany/${version}/${platform}-${arch}/cypress.zip'
const url = download.getUrl('ARCH', '0.20.2')
snapshot('desktop url from template with version', normalize(url))
})

    it('returns custom url from template with multiple replacements', () => {
      process.env.CYPRESS_DOWNLOAD_PATH_TEMPLATE = '${endpoint}/v${version}/${platform}/${arch}/cypress-${version}-${platform}-${arch}.zip'
      const url = download.getUrl('ARCH', '0.20.2')

      snapshot('desktop url from template with multiple variables', normalize(url))
    })

Hope it helps.

@lmiller1990
Copy link
Contributor

I've done development on Windows (CI also running on windows).

If you'd like to become a contributor, happy to work through getting your environment setup - if you just want this fixed asap, I can grab your above fix and integrate it, if you like. Let me know what works for you!

@mahdikhashan
Copy link
Contributor

Hey @nagash77 , could you please assign it to me?

@lmiller1990
Copy link
Contributor

@mahdikhashan done, I also set the status to "Contributor PR in Progress" so someone should be able to review it for you.

@nagash77 nagash77 added E2E Issue related to end-to-end testing Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. and removed routed-to-e2e labels Apr 19, 2023
@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 9, 2023

Released in 12.12.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v12.12.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators May 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cli E2E Issue related to end-to-end testing good first issue Good for newcomers Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants