mirror of
https://github.com/cypress-io/cypress.git
synced 2026-04-27 18:29:41 -05:00
cache commands, --no-exit (#1875)
* add --no-exit, cache commands * Manage -> Manages * fix run, run spec * remove comments
This commit is contained in:
@@ -67,6 +67,7 @@ exports['shows help for run --foo 1'] = `
|
||||
-c, --config <config> sets configuration values. separate multiple values with a comma. overrides any value in cypress.json.
|
||||
-b, --browser <browser-name> runs Cypress in the browser with the given name. note: using an external browser will not record a video.
|
||||
-P, --project <project-path> path to the project
|
||||
--no-exit keep the browser open after tests finish
|
||||
--dev runs cypress in development and bypasses binary check
|
||||
-h, --help output usage information
|
||||
-------
|
||||
@@ -105,6 +106,7 @@ exports['cli help command shows help 1'] = `
|
||||
open [options] Opens Cypress in the interactive GUI.
|
||||
install [options] Installs the Cypress executable matching this package's version
|
||||
verify Verifies that Cypress is installed correctly and executable
|
||||
cache [options] Manages the Cypress binary cache
|
||||
-------
|
||||
stderr:
|
||||
-------
|
||||
@@ -141,6 +143,7 @@ exports['cli help command shows help for -h 1'] = `
|
||||
open [options] Opens Cypress in the interactive GUI.
|
||||
install [options] Installs the Cypress executable matching this package's version
|
||||
verify Verifies that Cypress is installed correctly and executable
|
||||
cache [options] Manages the Cypress binary cache
|
||||
-------
|
||||
stderr:
|
||||
-------
|
||||
@@ -177,6 +180,7 @@ exports['cli help command shows help for --help 1'] = `
|
||||
open [options] Opens Cypress in the interactive GUI.
|
||||
install [options] Installs the Cypress executable matching this package's version
|
||||
verify Verifies that Cypress is installed correctly and executable
|
||||
cache [options] Manages the Cypress binary cache
|
||||
-------
|
||||
stderr:
|
||||
-------
|
||||
@@ -215,6 +219,7 @@ exports['cli unknown command shows usage and exits 1'] = `
|
||||
open [options] Opens Cypress in the interactive GUI.
|
||||
install [options] Installs the Cypress executable matching this package's version
|
||||
verify Verifies that Cypress is installed correctly and executable
|
||||
cache [options] Manages the Cypress binary cache
|
||||
-------
|
||||
stderr:
|
||||
-------
|
||||
@@ -224,31 +229,26 @@ exports['cli unknown command shows usage and exits 1'] = `
|
||||
`
|
||||
|
||||
exports['cli version and binary version 1'] = `
|
||||
|
||||
Cypress package version: 1.2.3
|
||||
Cypress binary version: X.Y.Z
|
||||
`
|
||||
|
||||
exports['cli version and binary version 2'] = `
|
||||
|
||||
Cypress package version: 1.2.3
|
||||
Cypress binary version: X.Y.Z
|
||||
`
|
||||
|
||||
exports['cli version no binary version 1'] = `
|
||||
|
||||
Cypress package version: 1.2.3
|
||||
Cypress binary version: not installed
|
||||
`
|
||||
|
||||
exports['cli --version no binary version 1'] = `
|
||||
|
||||
Cypress package version: 1.2.3
|
||||
Cypress binary version: not installed
|
||||
`
|
||||
|
||||
exports['cli -v no binary version 1'] = `
|
||||
|
||||
Cypress package version: 1.2.3
|
||||
Cypress binary version: not installed
|
||||
`
|
||||
|
||||
+31
-6
@@ -4,18 +4,20 @@ const { oneLine } = require('common-tags')
|
||||
const debug = require('debug')('cypress:cli')
|
||||
const util = require('./util')
|
||||
const logger = require('./logger')
|
||||
const cache = require('./tasks/cache')
|
||||
|
||||
// patch "commander" method called when a user passed an unknown option
|
||||
// we want to print help for the current command and exit with an error
|
||||
commander.Command.prototype.unknownOption = function (flag) {
|
||||
function unknownOption (flag, type = 'option') {
|
||||
if (this._allowUnknownOption) return
|
||||
logger.error()
|
||||
logger.error(' error: unknown option:', flag)
|
||||
logger.error(` error: unknown ${type}:`, flag)
|
||||
logger.error()
|
||||
this.outputHelp()
|
||||
logger.error()
|
||||
process.exit(1)
|
||||
}
|
||||
commander.Command.prototype.unknownOption = unknownOption
|
||||
|
||||
const coerceFalse = (arg) => {
|
||||
return arg !== 'false'
|
||||
@@ -25,7 +27,13 @@ const parseOpts = (opts) => {
|
||||
opts = _.pick(opts,
|
||||
'project', 'spec', 'reporter', 'reporterOptions', 'path', 'destination',
|
||||
'port', 'env', 'cypressVersion', 'config', 'record', 'key',
|
||||
'browser', 'detached', 'headed', 'global', 'dev', 'force')
|
||||
'browser', 'detached', 'headed', 'global', 'dev', 'force', 'exit',
|
||||
'cachePath', 'cacheList', 'cacheClear'
|
||||
)
|
||||
|
||||
if (opts.exit) {
|
||||
opts = _.omit(opts, 'exit')
|
||||
}
|
||||
|
||||
debug('parsed cli options', opts)
|
||||
|
||||
@@ -52,9 +60,13 @@ const descriptions = {
|
||||
headed: 'displays the Electron browser instead of running headlessly',
|
||||
dev: 'runs cypress in development and bypasses binary check',
|
||||
forceInstall: 'force install the Cypress binary',
|
||||
exit: 'keep the browser open after tests finish',
|
||||
cachePath: 'print the cypress binary cache path',
|
||||
cacheList: 'list the currently cached versions',
|
||||
cacheClear: 'delete the Cypress binary cache',
|
||||
}
|
||||
|
||||
const knownCommands = ['version', 'run', 'open', 'install', 'verify', '-v', '--version', 'help', '-h', '--help']
|
||||
const knownCommands = ['version', 'run', 'open', 'install', 'verify', '-v', '--version', 'help', '-h', '--help', 'cache']
|
||||
|
||||
const text = (description) => {
|
||||
if (!descriptions[description]) {
|
||||
@@ -122,6 +134,7 @@ module.exports = {
|
||||
.option('-c, --config <config>', text('config'))
|
||||
.option('-b, --browser <browser-name>', text('browser'))
|
||||
.option('-P, --project <project-path>', text('project'))
|
||||
.option('--no-exit', text('exit'))
|
||||
.option('--dev', text('dev'), coerceFalse)
|
||||
.action((opts) => {
|
||||
debug('running Cypress')
|
||||
@@ -173,7 +186,19 @@ module.exports = {
|
||||
.catch(util.logErrorExit1)
|
||||
})
|
||||
|
||||
logger.log()
|
||||
program
|
||||
.command('cache')
|
||||
.usage('[command]')
|
||||
.description('Manages the Cypress binary cache')
|
||||
.option('list', text('cacheList'))
|
||||
.option('path', text('cachePath'))
|
||||
.option('clear', text('cacheClear'))
|
||||
.action(function (opts) {
|
||||
if (opts.command || !_.includes(['list', 'path', 'clear'], opts)) {
|
||||
unknownOption.call(this, `cache ${opts}`, 'sub-command')
|
||||
}
|
||||
cache[opts]()
|
||||
})
|
||||
|
||||
debug('cli starts with arguments %j', args)
|
||||
util.printNodeOptions()
|
||||
@@ -189,7 +214,7 @@ module.exports = {
|
||||
|
||||
const firstCommand = args[2]
|
||||
if (!_.includes(knownCommands, firstCommand)) {
|
||||
debug('unknwon command %s', firstCommand)
|
||||
debug('unknown command %s', firstCommand)
|
||||
logger.error('Unknown command', `"${firstCommand}"`)
|
||||
program.outputHelp()
|
||||
return util.exit(1)
|
||||
|
||||
@@ -76,6 +76,10 @@ const processRunOptions = (options = {}) => {
|
||||
args.push('--headed', options.headed)
|
||||
}
|
||||
|
||||
if (options.exit === false) {
|
||||
args.push('--no-exit')
|
||||
}
|
||||
|
||||
return args
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
const state = require('./state')
|
||||
const logger = require('../logger')
|
||||
const fs = require('../fs')
|
||||
const util = require('../util')
|
||||
|
||||
const path = () => {
|
||||
logger.log(state.getCacheDir())
|
||||
return undefined
|
||||
}
|
||||
|
||||
const clear = () => {
|
||||
return fs.removeAsync(state.getCacheDir())
|
||||
}
|
||||
|
||||
const list = () => {
|
||||
return fs
|
||||
.readdirAsync(state.getCacheDir())
|
||||
.filter(util.isSemver)
|
||||
.then((versions) => {
|
||||
logger.log(versions.join(', '))
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
path,
|
||||
clear,
|
||||
list,
|
||||
}
|
||||
@@ -85,6 +85,7 @@
|
||||
"dependency-check": "^2.8.0",
|
||||
"dtslint": "0.2.0",
|
||||
"execa-wrap": "1.1.0",
|
||||
"mock-fs": "4.5.0",
|
||||
"nock": "^9.0.9",
|
||||
"nyc": "11.7.1",
|
||||
"proxyquire": "2.0.1",
|
||||
|
||||
@@ -121,6 +121,7 @@ describe('cli', function () {
|
||||
context('cypress run', function () {
|
||||
beforeEach(function () {
|
||||
sinon.stub(run, 'start').resolves(0)
|
||||
util.exit.withArgs(0)
|
||||
})
|
||||
|
||||
it('calls run.start with options + exits with code', function (done) {
|
||||
@@ -199,6 +200,11 @@ describe('cli', function () {
|
||||
expect(run.start).to.be.calledWith({ headed: true })
|
||||
})
|
||||
|
||||
it('calls run with --no-exit', function () {
|
||||
this.exec('run --no-exit')
|
||||
expect(run.start).to.be.calledWith({ exit: false })
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
context('cypress open', function () {
|
||||
|
||||
@@ -87,6 +87,15 @@ describe('exec run', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('spawns with --no-exit', function () {
|
||||
return run.start({ exit: false })
|
||||
.then(() => {
|
||||
expect(spawn.start).to.be.calledWith([
|
||||
'--run-project', process.cwd(), '--no-exit',
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
it('spawns with --output-path', function () {
|
||||
return run.start({ outputPath: '/path/to/output' })
|
||||
.then(() => {
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
require('../../spec_helper')
|
||||
|
||||
const mockfs = require('mock-fs')
|
||||
|
||||
const fs = require(`${lib}/fs`)
|
||||
const state = require(`${lib}/tasks/state`)
|
||||
const cache = require(`${lib}/tasks/cache`)
|
||||
const stdout = require('../../support/stdout')
|
||||
|
||||
describe('lib/tasks/cache', () => {
|
||||
beforeEach(() => {
|
||||
mockfs({
|
||||
'/.cache/Cypress': {
|
||||
'1.2.3': {
|
||||
'Cypress': {},
|
||||
},
|
||||
'2.3.4': {
|
||||
'Cypress.app': {},
|
||||
},
|
||||
},
|
||||
})
|
||||
sinon.stub(state, 'getCacheDir').returns('/.cache/Cypress')
|
||||
this.stdout = stdout.capture()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
stdout.restore()
|
||||
})
|
||||
|
||||
describe('.path', () => {
|
||||
it('lists path to cache', () => {
|
||||
cache.path()
|
||||
expect(this.stdout.toString()).to.eql('/.cache/Cypress\n')
|
||||
})
|
||||
})
|
||||
describe('.clear', () => {
|
||||
it('deletes cache folder and everything inside it', () => {
|
||||
return cache.clear()
|
||||
.then(() =>
|
||||
fs.pathExistsAsync('/.cache/Cypress')
|
||||
.then((exists) => expect(exists).to.eql(false))
|
||||
)
|
||||
})
|
||||
})
|
||||
describe('.list', () => {
|
||||
it('lists all versions of cached binary', () => {
|
||||
return cache.list()
|
||||
.then(() => {
|
||||
expect(this.stdout.toString()).to.eql('1.2.3, 2.3.4\n')
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -2,6 +2,7 @@ const _ = require('lodash')
|
||||
const os = require('os')
|
||||
const path = require('path')
|
||||
const sinon = require('sinon')
|
||||
const mockfs = require('mock-fs')
|
||||
const Promise = require('bluebird')
|
||||
const util = require('../lib/util')
|
||||
|
||||
@@ -86,4 +87,5 @@ beforeEach(function () {
|
||||
afterEach(function () {
|
||||
process.env = _.clone(env)
|
||||
sinon.restore()
|
||||
mockfs.restore()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user