Skip to content

Commit

Permalink
Allow skipping binary download during install (#1008)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
raygesualdo authored and brian-mann committed Dec 5, 2017
1 parent da374e3 commit 3a53860
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 16 deletions.
24 changes: 17 additions & 7 deletions cli/__snapshots__/install_spec.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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]
Expand All @@ -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.
`
7 changes: 7 additions & 0 deletions cli/lib/tasks/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
34 changes: 27 additions & 7 deletions cli/test/lib/tasks/install_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
})
})
})

Expand Down
10 changes: 8 additions & 2 deletions cli/test/support/normalize.js
Original file line number Diff line number Diff line change
@@ -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')
)
}

0 comments on commit 3a53860

Please sign in to comment.