From 3a538601e117947c9632a5263633caf7a139ac98 Mon Sep 17 00:00:00 2001 From: Ray Gesualdo Date: Tue, 5 Dec 2017 11:39:29 -0500 Subject: [PATCH] Allow skipping binary download during install (#1008) * added CYPRESS_SKIP_BINARY_INSTALL env var check before installing * cli: provide reason binary installation is being skipped - more linting, why not * cli: prettify snapshots by removing whitespace at end of line --- cli/__snapshots__/install_spec.js | 24 +++++++++++++++------ cli/lib/tasks/install.js | 7 ++++++ cli/test/lib/tasks/install_spec.js | 34 ++++++++++++++++++++++++------ cli/test/support/normalize.js | 10 +++++++-- 4 files changed, 59 insertions(+), 16 deletions(-) diff --git a/cli/__snapshots__/install_spec.js b/cli/__snapshots__/install_spec.js index 648f27115997..31370b247efc 100644 --- a/cli/__snapshots__/install_spec.js +++ b/cli/__snapshots__/install_spec.js @@ -1,7 +1,8 @@ exports['installs without existing installation 1'] = ` Installing Cypress (version: 1.2.3) - ✔ Downloaded Cypress ✔ Unzipped Cypress + ✔ Downloaded Cypress + ✔ Unzipped Cypress ✔ Finished Installation /path/to/binary/dir/ You can now open Cypress by running: node_modules/.bin/cypress open @@ -21,7 +22,8 @@ Note: there is no guarantee these versions will work properly together. Installing Cypress (version: 0.12.1) - ✔ Downloaded Cypress ✔ Unzipped Cypress + ✔ Downloaded Cypress + ✔ Unzipped Cypress ✔ Finished Installation /path/to/binary/dir/ You can now open Cypress by running: node_modules/.bin/cypress open @@ -40,7 +42,8 @@ Pass the --force option if you'd like to reinstall anyway. exports['continues installing on failure 1'] = ` Installing Cypress (version: 1.2.3) - ✔ Downloaded Cypress ✔ Unzipped Cypress + ✔ Downloaded Cypress + ✔ Unzipped Cypress ✔ Finished Installation /path/to/binary/dir/ You can now open Cypress by running: node_modules/.bin/cypress open @@ -54,7 +57,8 @@ Installed version (x.x.x) does not match needed version (1.2.3). Installing Cypress (version: 1.2.3) - ✔ Downloaded Cypress ✔ Unzipped Cypress + ✔ Downloaded Cypress + ✔ Unzipped Cypress ✔ Finished Installation /path/to/binary/dir/ You can now open Cypress by running: node_modules/.bin/cypress open @@ -66,7 +70,8 @@ https://on.cypress.io/installing-cypress exports['forcing true always installs 1'] = ` Installing Cypress (version: 1.2.3) - ✔ Downloaded Cypress ✔ Unzipped Cypress + ✔ Downloaded Cypress + ✔ Unzipped Cypress ✔ Finished Installation /path/to/binary/dir/ You can now open Cypress by running: node_modules/.bin/cypress open @@ -80,7 +85,8 @@ Installed version (x.x.x) does not match needed version (1.2.3). Installing Cypress (version: 1.2.3) - ✔ Downloaded Cypress ✔ Unzipped Cypress + ✔ Downloaded Cypress + ✔ Unzipped Cypress ✔ Finished Installation /path/to/binary/dir/ It looks like you've installed Cypress globally. @@ -101,7 +107,7 @@ Installed version (x.x.x) does not match needed version (1.2.3). Installing Cypress (version: 1.2.3) -[xx:xx:xx] Downloading Cypress [started] +[xx:xx:xx] Downloading Cypress [started] [xx:xx:xx] Downloading Cypress [completed] [xx:xx:xx] Unzipping Cypress [started] [xx:xx:xx] Unzipping Cypress [completed] @@ -113,3 +119,7 @@ You can now open Cypress by running: node_modules/.bin/cypress open https://on.cypress.io/installing-cypress ` +exports['skip installation 1'] = ` +Skipping binary installation. Env var 'CYPRESS_SKIP_BINARY_INSTALL' was found. + +` diff --git a/cli/lib/tasks/install.js b/cli/lib/tasks/install.js index 37a4119a877d..3f1da95214ec 100644 --- a/cli/lib/tasks/install.js +++ b/cli/lib/tasks/install.js @@ -172,6 +172,13 @@ const downloadAndUnzip = (version) => { } const start = (options = {}) => { + if (process.env.CYPRESS_SKIP_BINARY_INSTALL) { + logger.log( + chalk.yellow('Skipping binary installation. Env var \'CYPRESS_SKIP_BINARY_INSTALL\' was found.') + ) + return Promise.resolve() + } + debug('installing with options %j', options) _.defaults(options, { diff --git a/cli/test/lib/tasks/install_spec.js b/cli/test/lib/tasks/install_spec.js index baff9a52924e..fe8ce26977de 100644 --- a/cli/test/lib/tasks/install_spec.js +++ b/cli/test/lib/tasks/install_spec.js @@ -53,6 +53,26 @@ describe('install', function () { this.sandbox.stub(info, 'clearVersionState').resolves() }) + 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()) + ) + }) + }) + }) + describe('override version', function () { afterEach(function () { delete process.env.CYPRESS_BINARY_VERSION @@ -85,14 +105,14 @@ describe('install', function () { this.sandbox.stub(fs, 'statAsync').withArgs(version).resolves() return install.start() - .then(() => { - expect(unzip.start).calledWith({ - zipDestination: version, - destination: info.getInstallationDir(), - executable: info.getPathToUserExecutableDir(), - }) - expect(info.writeInstalledVersion).calledWith('unknown') + .then(() => { + expect(unzip.start).calledWith({ + zipDestination: version, + destination: info.getInstallationDir(), + executable: info.getPathToUserExecutableDir(), }) + expect(info.writeInstalledVersion).calledWith('unknown') + }) }) }) diff --git a/cli/test/support/normalize.js b/cli/test/support/normalize.js index bbf0566ed932..528ea4834fe2 100644 --- a/cli/test/support/normalize.js +++ b/cli/test/support/normalize.js @@ -1,16 +1,22 @@ const stripAnsi = require('strip-ansi') -const excessWhitespaceRe = /(\s{3,})/ +const whitespaceAtEndOfLineRe = /\s+$/g const datesRe = /(\d+:\d+:\d+)/g const downloadQueryRe = /(\?platform=(darwin|linux|win32)&arch=(x64|ia32))/ +const removeExcessWhiteSpace = (str) => { + return str.replace(whitespaceAtEndOfLineRe, '') +} + module.exports = (str) => { // strip dates and ansi codes // and excess whitespace return stripAnsi( str .replace(datesRe, 'xx:xx:xx') - .replace(excessWhitespaceRe, ' ') + .split('\n') + .map(removeExcessWhiteSpace) + .join('\n') .replace(downloadQueryRe, '?platform=OS&arch=ARCH') ) }