diff --git a/cli/lib/cli.js b/cli/lib/cli.js index 0b5a352b8a..24aac5bda7 100644 --- a/cli/lib/cli.js +++ b/cli/lib/cli.js @@ -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 ', text('browser')) .option('-P, --project ', 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) }) diff --git a/cli/lib/exec/open.js b/cli/lib/exec/open.js index 98127bc297..336e33a886 100644 --- a/cli/lib/exec/open.js +++ b/cli/lib/exec/open.js @@ -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() } diff --git a/cli/test/lib/cli_spec.js b/cli/test/lib/cli_spec.js index 5b5fb99b44..72babf9234 100644 --- a/cli/test/lib/cli_spec.js +++ b/cli/test/lib/cli_spec.js @@ -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') diff --git a/cli/test/lib/exec/open_spec.js b/cli/test/lib/exec/open_spec.js index b9880fbf96..1e0a35e2af 100644 --- a/cli/test/lib/exec/open_spec.js +++ b/cli/test/lib/exec/open_spec.js @@ -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(() => {