mirror of
https://github.com/cypress-io/cypress.git
synced 2026-04-22 15:12:27 -05:00
working on installing from local binary file (#797)
for #701 * working on installing from local binary file * fix missing return * enabled skipped zip file test * test zip file and up in two folders * test direct zip file install on CircleCI * Remove artificial delays
This commit is contained in:
+9
-22
@@ -643,28 +643,15 @@ workflows:
|
||||
branches:
|
||||
only:
|
||||
- develop
|
||||
- bump-via-commit-537
|
||||
requires:
|
||||
- build-npm-package
|
||||
- build-binary
|
||||
# enable once we can point CYPRESS_BINARY_VERSION at an existing file
|
||||
# - test-next-version-locally:
|
||||
# filters:
|
||||
# branches:
|
||||
# only:
|
||||
# - develop
|
||||
# - bump-via-commit-537
|
||||
# requires:
|
||||
# - build-npm-package
|
||||
# - build-binary
|
||||
|
||||
#
|
||||
# things to run in the 4th CI container
|
||||
#
|
||||
# - run:
|
||||
# name: Example e2e tests
|
||||
# command: |
|
||||
# if [ $CIRCLE_NODE_INDEX == 3 ]; then
|
||||
# # ./bin/cypress --project=./packages/example --path-to-cypress
|
||||
# # npm start -- --project=./packages/example
|
||||
# fi
|
||||
- test-next-version-locally:
|
||||
filters:
|
||||
branches:
|
||||
only:
|
||||
- develop
|
||||
- binary-path-701
|
||||
requires:
|
||||
- build-npm-package
|
||||
- build-binary
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
exports['installs without existing installation 1'] = `
|
||||
Installing Cypress (version: 1.2.3)
|
||||
|
||||
✔ Downloaded Cypress ✔ Unzipped Cypress
|
||||
✔ Finished Installation /path/to/binary/dir/
|
||||
|
||||
You can now open Cypress by running: node_modules/.bin/cypress open
|
||||
|
||||
https://on.cypress.io/installing-cypress
|
||||
|
||||
`
|
||||
|
||||
exports['specify version in env vars 1'] = `
|
||||
Forcing a binary version different than the default.
|
||||
|
||||
@@ -37,18 +49,6 @@ https://on.cypress.io/installing-cypress
|
||||
|
||||
`
|
||||
|
||||
exports['installs without existing installation 1'] = `
|
||||
Installing Cypress (version: 1.2.3)
|
||||
|
||||
✔ Downloaded Cypress ✔ Unzipped Cypress
|
||||
✔ Finished Installation /path/to/binary/dir/
|
||||
|
||||
You can now open Cypress by running: node_modules/.bin/cypress open
|
||||
|
||||
https://on.cypress.io/installing-cypress
|
||||
|
||||
`
|
||||
|
||||
exports['installed version does not match needed version 1'] = `
|
||||
Installed version (x.x.x) does not match needed version (1.2.3).
|
||||
|
||||
|
||||
@@ -49,11 +49,21 @@ const prettyDownloadErr = (err, version) => {
|
||||
return throwFormErrorText(errors.failedDownload)(msg)
|
||||
}
|
||||
|
||||
const download = (options = {}) => {
|
||||
if (!options.version) {
|
||||
debug('empty Cypress version to download')
|
||||
// attention:
|
||||
// when passing relative path to NPM post install hook, the current working
|
||||
// directory is set to the `node_modules/cypress` folder
|
||||
// the user is probably passing relative path with respect to root package folder
|
||||
function formAbsolutePath (filename) {
|
||||
if (path.isAbsolute(filename)) {
|
||||
return filename
|
||||
}
|
||||
return path.join(process.cwd(), '..', '..', filename)
|
||||
}
|
||||
|
||||
// downloads from given url
|
||||
// return an object with
|
||||
// {filename: ..., downloaded: true}
|
||||
const downloadFromUrl = (options) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const url = getUrl(options.version)
|
||||
|
||||
@@ -120,11 +130,54 @@ const download = (options = {}) => {
|
||||
.on('finish', () => {
|
||||
debug('downloading finished')
|
||||
|
||||
resolve(options.downloadDestination)
|
||||
resolve({
|
||||
filename: options.downloadDestination,
|
||||
downloaded: true,
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// returns an object with zip filename
|
||||
// and a flag if the file was really downloaded
|
||||
// or not. Maybe it was already there!
|
||||
// {filename: ..., downloaded: true|false}
|
||||
const download = (options = {}) => {
|
||||
if (!options.version) {
|
||||
debug('empty Cypress version to download, will try latest')
|
||||
return downloadFromUrl(options)
|
||||
}
|
||||
|
||||
debug('need to download Cypress version %s', options.version)
|
||||
// first check the original filename
|
||||
return fs.pathExists(options.version)
|
||||
.then((exists) => {
|
||||
if (exists) {
|
||||
debug('found file right away', options.version)
|
||||
return {
|
||||
filename: options.version,
|
||||
downloaded: false,
|
||||
}
|
||||
}
|
||||
|
||||
const possibleFile = formAbsolutePath(options.version)
|
||||
debug('checking local file', possibleFile, 'cwd', process.cwd())
|
||||
return fs.pathExists(possibleFile)
|
||||
.then((exists) => {
|
||||
if (exists) {
|
||||
debug('found local file', possibleFile)
|
||||
debug('skipping download')
|
||||
return {
|
||||
filename: possibleFile,
|
||||
downloaded: false,
|
||||
}
|
||||
} else {
|
||||
return downloadFromUrl(options)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const start = (options) => {
|
||||
_.defaults(options, {
|
||||
version: null,
|
||||
|
||||
@@ -12,6 +12,8 @@ const util = require('../util')
|
||||
const info = require('./info')
|
||||
const unzip = require('./unzip')
|
||||
const logger = require('../logger')
|
||||
const la = require('lazy-ass')
|
||||
const is = require('check-more-types')
|
||||
|
||||
const alreadyInstalledMsg = (installedVersion, needVersion) => {
|
||||
logger.log(chalk.yellow(stripIndent`
|
||||
@@ -65,7 +67,8 @@ const downloadAndUnzip = (version) => {
|
||||
}
|
||||
|
||||
// let the user know what version of cypress we're downloading!
|
||||
logger.log(chalk.yellow(`Installing Cypress ${chalk.gray(`(version: ${version})`)}`))
|
||||
const message = chalk.yellow(`Installing Cypress ${chalk.gray(`(version: ${version})`)}`)
|
||||
logger.log(message)
|
||||
logger.log()
|
||||
|
||||
const progessify = (task, title) => {
|
||||
@@ -99,9 +102,10 @@ const downloadAndUnzip = (version) => {
|
||||
options.onProgress = progessify(task, 'Downloading Cypress')
|
||||
|
||||
return download.start(options)
|
||||
.then((downloadDestination) => {
|
||||
.then(({ filename, downloaded }) => {
|
||||
// save the download destination for unzipping
|
||||
ctx.downloadDestination = downloadDestination
|
||||
ctx.downloadDestination = filename
|
||||
ctx.downloaded = downloaded
|
||||
|
||||
util.setTaskTitle(
|
||||
task,
|
||||
@@ -131,13 +135,25 @@ const downloadAndUnzip = (version) => {
|
||||
{
|
||||
title: util.titleize('Finishing Installation'),
|
||||
task: (ctx, task) => {
|
||||
const { downloadDestination } = options
|
||||
const { downloadDestination, version } = options
|
||||
la(is.unemptyString(downloadDestination), 'missing download destination', options)
|
||||
la(is.bool(ctx.downloaded), 'missing downloaded flag', ctx)
|
||||
|
||||
debug('removing zip file %s', downloadDestination)
|
||||
const removeFile = () => {
|
||||
debug('removing zip file %s', downloadDestination)
|
||||
return fs.removeAsync(downloadDestination)
|
||||
}
|
||||
const skipFileRemoval = () => {
|
||||
debug('not removing file %s', downloadDestination)
|
||||
debug('because it was not downloaded (probably was local file already)')
|
||||
return Promise.resolve()
|
||||
}
|
||||
const cleanup = ctx.downloaded ? removeFile : skipFileRemoval
|
||||
|
||||
return fs.removeAsync(downloadDestination)
|
||||
return cleanup()
|
||||
.then(() => {
|
||||
const dir = info.getPathToUserExecutableDir()
|
||||
debug('finished installation in', dir)
|
||||
|
||||
util.setTaskTitle(
|
||||
task,
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
"@cypress/xvfb": "1.0.4",
|
||||
"bluebird": "3.5.0",
|
||||
"chalk": "2.1.0",
|
||||
"check-more-types": "2.24.0",
|
||||
"commander": "2.9.0",
|
||||
"common-tags": "1.4.0",
|
||||
"debug": "2.6.8",
|
||||
@@ -37,6 +38,7 @@
|
||||
"glob": "7.1.2",
|
||||
"is-ci": "1.0.10",
|
||||
"is-installed-globally": "0.1.0",
|
||||
"lazy-ass": "1.6.0",
|
||||
"listr": "0.12.0",
|
||||
"lodash": "4.17.4",
|
||||
"minimist": "1.2.0",
|
||||
|
||||
@@ -17,7 +17,10 @@ const util = require(`${lib}/util`)
|
||||
const normalize = require('../../support/normalize')
|
||||
|
||||
const packageVersion = '1.2.3'
|
||||
const downloadDestination = 'path/to/cypress.zip'
|
||||
const downloadDestination = {
|
||||
filename: 'path/to/cypress.zip',
|
||||
downloaded: true,
|
||||
}
|
||||
|
||||
describe('install', function () {
|
||||
beforeEach(function () {
|
||||
@@ -76,11 +79,10 @@ describe('install', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it.skip('can install local binary zip file without download', function () {
|
||||
it('can install local binary zip file without download', function () {
|
||||
const version = '/tmp/local/file.zip'
|
||||
process.env.CYPRESS_BINARY_VERSION = version
|
||||
this.sandbox.stub(fs, 'statAsync').withArgs(version).resolves()
|
||||
this.sandbox.stub(unzip, 'start').resolves()
|
||||
|
||||
return install.start()
|
||||
.then(() => {
|
||||
@@ -153,7 +155,9 @@ describe('install', function () {
|
||||
})
|
||||
|
||||
// cleans up the zip file
|
||||
expect(fs.removeAsync).to.be.calledWith(downloadDestination)
|
||||
expect(fs.removeAsync).to.be.calledWith(
|
||||
downloadDestination.filename
|
||||
)
|
||||
|
||||
snapshot(
|
||||
'installs without existing installation',
|
||||
|
||||
Reference in New Issue
Block a user