Cypress: Provide mechanism to skip binary download/install during "npm install"

Created on 4 Dec 2017  路  8Comments  路  Source: cypress-io/cypress

  • Operating System: Win10 x64
  • Cypress Version: 1.1.2
  • Browser Version: Chrome 62

Is this a Feature or Bug?

Feature

Current behavior:

When running npm install with Cypress listed as a dependency, the binary is always downloaded, unzipped and installed.

Desired behavior:

Provide a mechanism (most likely an environment variable such as CYPRESS_SKIP_BINARY_INSTALL) where the user can manually skip the binary install process.

Impetus

We have a React project with Cypress tests that are run in our CI pipeline (currently Travis). We also have our project being built and deployed by a different service (currently Netlify). Cypress is not needed during the build/deploy process but is being installed anyway. This adds additional load and time to our build process.

Test code:

In /cli/test/lib/tasks/install_spec.js:

describe('skips install', function () {
  afterEach(function () {
    delete process.env.CYPRESS_SKIP_BINARY_INSTALL
  })

  it('when environment variable is set', function () {
    process.env.CYPRESS_SKIP_BINARY_INSTALL = true

    return install.start()
    .then(() => {
      expect(download.start).not.to.be.called

      snapshot(
        'skip installation',
        normalize(this.stdout.toString())
      )
    })
  })
})

Additional Info (images, stack traces, etc)

Possible implementation at cli/lib/tasks/install.js#L176:

if (process.env.CYPRESS_SKIP_BINARY_INSTALL) {
  logger.log('Skipping binary install.')
  return Promise.resolve()
}
cli enhancement

Most helpful comment

Released in 1.1.4.

All 8 comments

BTW you can do this right now with npm install --ignore-scripts

NPM has always supported this feature.

Can you just submit a PR for this? It looks like you've already written the code. Working in the CLI code is super easy.

--ignore-scripts would break other modules that are being installed.

Working on a PR now.

That is true. Just throwing it out there in case none of your other deps depended on them ;-)

Submitted a PR: #1008.

Released in 1.1.4.

Thanks! Updated and tested in our CI/CD pipeline and it works like a charm.

Really excited about Cypress. Y'all have a great product. Glad to contribute to an Atlanta startup 馃榿

@raygesualdo I can get the skip working just fine, but I get a complaint about "No version of Cypress is installed.". Looking into how I get that message, it looks like the path the CLI looks for is hard-coded to check node_modules/cypress/dist/. Obviously skipping the binary download didn't put it there. How did you set it up so that the binary could still be found? Do you symlink?

Actually I might have figured it out... If I call cypress from the CI command line, I'll hit the global one. If I call cypress from inside a package.json script, it will use the local one (which fails the check).

I wonder if an environment variable to the path to the binary should be supported...

I can't seem to make heroku skip the install. Cypress is installed as a dev dependency. and my "heroku-prebuild" is

    "heroku-prebuild": "export CYPRESS_INSTALL_BINARY=0"

I can see Cypress unzipping and installing when I push to heroku.

Was this page helpful?
0 / 5 - 0 ratings