mirror of
https://github.com/cypress-io/cypress.git
synced 2026-02-25 10:30:39 -06:00
fixes #661, accept --project for cypress open
This commit is contained in:
@@ -10,9 +10,19 @@ const coerceFalse = (arg) => {
|
||||
return arg !== 'false'
|
||||
}
|
||||
|
||||
const parseOpts = (opts) => _.pick(opts,
|
||||
'project', 'spec', 'reporter', 'reporterOptions', 'path', 'destination',
|
||||
'port', 'env', 'cypressVersion', 'config', 'record', 'key', 'browser', 'detached', 'headed')
|
||||
const parseOpts = (opts) => {
|
||||
opts = _.pick(opts,
|
||||
'project', 'spec', 'reporter', 'reporterOptions', 'path', 'destination',
|
||||
'port', 'env', 'cypressVersion', 'config', 'record', 'key', 'browser', 'detached', 'headed')
|
||||
|
||||
if (opts.project) {
|
||||
opts.project = path.resolve(opts.project)
|
||||
}
|
||||
|
||||
debug('parsed cli options', opts)
|
||||
|
||||
return opts
|
||||
}
|
||||
|
||||
const descriptions = {
|
||||
record: 'records the run. sends test results, screenshots and videos to your Cypress Dashboard.',
|
||||
@@ -92,13 +102,8 @@ module.exports = {
|
||||
.option('-b, --browser <browser-name>', text('browser'))
|
||||
.option('-P, --project <project-path>', text('project'))
|
||||
.action((opts) => {
|
||||
const parsedOptions = parseOpts(opts)
|
||||
if (parsedOptions.project) {
|
||||
parsedOptions.project = path.resolve(parsedOptions.project)
|
||||
}
|
||||
debug('parsed cli options', parsedOptions)
|
||||
require('./exec/run')
|
||||
.start(parsedOptions)
|
||||
.start(parseOpts(opts))
|
||||
.then(util.exit)
|
||||
.catch(util.logErrorExit1)
|
||||
})
|
||||
|
||||
@@ -5,7 +5,7 @@ const verify = require('../tasks/verify')
|
||||
|
||||
module.exports = {
|
||||
start (options = {}) {
|
||||
if (!util.isInstalledGlobally()) {
|
||||
if (!util.isInstalledGlobally() && !options.project) {
|
||||
options.project = process.cwd()
|
||||
}
|
||||
|
||||
|
||||
@@ -160,24 +160,43 @@ describe('cli', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('open calls open.start with options', function () {
|
||||
this.sandbox.stub(open, 'start').resolves()
|
||||
this.exec('open --port 7878')
|
||||
expect(open.start).to.be.calledWith({ port: '7878' })
|
||||
})
|
||||
context('cypress open', function () {
|
||||
beforeEach(function () {
|
||||
this.sandbox.stub(open, 'start').resolves(0)
|
||||
})
|
||||
|
||||
it('open calls open.start + catches errors', function (done) {
|
||||
const err = new Error('foo')
|
||||
it('calls open.start with relative --project folder', function () {
|
||||
this.sandbox.stub(path, 'resolve')
|
||||
.withArgs('foo/bar').returns('/mock/absolute/foo/bar')
|
||||
this.exec('open --project foo/bar')
|
||||
expect(open.start).to.be.calledWith({ project: '/mock/absolute/foo/bar' })
|
||||
})
|
||||
|
||||
this.sandbox.stub(open, 'start').rejects(err)
|
||||
this.exec('open --port 7878')
|
||||
it('calls open.start with absolute --project folder', function () {
|
||||
this.exec('open --project /tmp/foo/bar')
|
||||
expect(open.start).to.be.calledWith({ project: '/tmp/foo/bar' })
|
||||
})
|
||||
|
||||
util.logErrorExit1.callsFake((e) => {
|
||||
expect(e).to.eq(err)
|
||||
done()
|
||||
it('calls open.start with options', function () {
|
||||
// this.sandbox.stub(open, 'start').resolves()
|
||||
this.exec('open --port 7878')
|
||||
expect(open.start).to.be.calledWith({ port: '7878' })
|
||||
})
|
||||
|
||||
it('calls open.start + catches errors', function (done) {
|
||||
const err = new Error('foo')
|
||||
|
||||
open.start.rejects(err)
|
||||
this.exec('open --port 7878')
|
||||
|
||||
util.logErrorExit1.callsFake((e) => {
|
||||
expect(e).to.eq(err)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
it('install calls install.start with force: true', function () {
|
||||
this.sandbox.stub(install, 'start').resolves()
|
||||
this.exec('install')
|
||||
|
||||
@@ -66,6 +66,17 @@ describe('exec open', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('spawns with --project passed in as options even when not installed globally', function () {
|
||||
util.isInstalledGlobally.returns(false)
|
||||
|
||||
return open.start({ project: '/path/to/project' })
|
||||
.then(() => {
|
||||
expect(spawn.start).to.be.calledWith(
|
||||
['--project', '/path/to/project']
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
it('spawns with --project if specified and installed globally', function () {
|
||||
return open.start({ project: '/path/to/project' })
|
||||
.then(() => {
|
||||
|
||||
Reference in New Issue
Block a user