mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-21 07:38:53 -05:00
cli: more comprehensive tests around cli + util, exits, rejected promises, etc
This commit is contained in:
+4
-4
@@ -58,7 +58,7 @@ module.exports = {
|
||||
require('./exec/run')
|
||||
.start(parseOpts(opts))
|
||||
.then(util.exit)
|
||||
.catch(util.exit1)
|
||||
.catch(util.logErrorExit1)
|
||||
})
|
||||
|
||||
program
|
||||
@@ -73,7 +73,7 @@ module.exports = {
|
||||
.action((opts) => {
|
||||
require('./exec/open')
|
||||
.start(parseOpts(opts))
|
||||
.catch(util.exit1)
|
||||
.catch(util.logErrorExit1)
|
||||
})
|
||||
|
||||
program
|
||||
@@ -82,7 +82,7 @@ module.exports = {
|
||||
.action(() => {
|
||||
require('./tasks/install')
|
||||
.start({ force: true })
|
||||
.catch(util.exit1)
|
||||
.catch(util.logErrorExit1)
|
||||
})
|
||||
|
||||
program
|
||||
@@ -91,7 +91,7 @@ module.exports = {
|
||||
.action(() => {
|
||||
require('./tasks/verify')
|
||||
.start({ force: true })
|
||||
.catch(util.exit1)
|
||||
.catch(util.logErrorExit1)
|
||||
})
|
||||
|
||||
debug('cli starts with arguments %j', process.argv)
|
||||
|
||||
@@ -18,10 +18,6 @@ module.exports = {
|
||||
process.exit(code)
|
||||
},
|
||||
|
||||
exit1 () {
|
||||
process.exit(1)
|
||||
},
|
||||
|
||||
logErrorExit1 (err) {
|
||||
logger.error(err.message)
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
require('../spec_helper')
|
||||
|
||||
const cli = require(`${lib}/cli`)
|
||||
const util = require(`${lib}/util`)
|
||||
const run = require(`${lib}/exec/run`)
|
||||
const open = require(`${lib}/exec/open`)
|
||||
const verify = require(`${lib}/tasks/verify`)
|
||||
@@ -9,20 +10,32 @@ const install = require(`${lib}/tasks/install`)
|
||||
describe('cli', function () {
|
||||
beforeEach(function () {
|
||||
this.sandbox.stub(process, 'exit')
|
||||
this.sandbox.stub(util, 'exit')
|
||||
this.sandbox.stub(util, 'logErrorExit1')
|
||||
this.exec = (args) => cli.init().parse(`node test ${args}`.split(' '))
|
||||
})
|
||||
|
||||
it('exits when done', function (done) {
|
||||
this.sandbox.stub(run, 'start').resolves()
|
||||
this.exec('run --port 7878')
|
||||
|
||||
process.exit.callsFake(done)
|
||||
})
|
||||
|
||||
it('run calls run.start with options', function () {
|
||||
this.sandbox.stub(run, 'start').resolves()
|
||||
it('run calls run.start with options + exits with code', function (done) {
|
||||
this.sandbox.stub(run, 'start').resolves(10)
|
||||
this.exec('run --port 7878')
|
||||
expect(run.start).to.be.calledWith({ port: '7878' })
|
||||
|
||||
util.exit.callsFake((code) => {
|
||||
expect(code).to.eq(10)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('run calls run.start with options + catches errors', function (done) {
|
||||
const err = new Error('foo')
|
||||
this.sandbox.stub(run, 'start').rejects(err)
|
||||
this.exec('run --port 7878')
|
||||
expect(run.start).to.be.calledWith({ port: '7878' })
|
||||
|
||||
util.logErrorExit1.callsFake((e) => {
|
||||
expect(e).to.eq(err)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('open calls open.start with options', function () {
|
||||
@@ -31,15 +44,51 @@ describe('cli', function () {
|
||||
expect(open.start).to.be.calledWith({ port: '7878' })
|
||||
})
|
||||
|
||||
it('open calls open.start + catches errors', function (done) {
|
||||
const err = new Error('foo')
|
||||
|
||||
this.sandbox.stub(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')
|
||||
expect(install.start).to.be.calledWith({ force: true })
|
||||
})
|
||||
|
||||
it('install calls install.start + catches errors', function (done) {
|
||||
const err = new Error('foo')
|
||||
|
||||
this.sandbox.stub(install, 'start').rejects(err)
|
||||
this.exec('install')
|
||||
|
||||
util.logErrorExit1.callsFake((e) => {
|
||||
expect(e).to.eq(err)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('verify calls verify.start with force: true', function () {
|
||||
this.sandbox.stub(verify, 'start').resolves()
|
||||
this.exec('verify')
|
||||
expect(verify.start).to.be.calledWith({ force: true })
|
||||
})
|
||||
|
||||
it('verify calls verify.start + catches errors', function (done) {
|
||||
const err = new Error('foo')
|
||||
|
||||
this.sandbox.stub(verify, 'start').rejects(err)
|
||||
this.exec('verify')
|
||||
|
||||
util.logErrorExit1.callsFake((e) => {
|
||||
expect(e).to.eq(err)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
require('../spec_helper')
|
||||
|
||||
const util = require(`${lib}/util`)
|
||||
const logger = require(`${lib}/logger`)
|
||||
|
||||
describe('util', function () {
|
||||
beforeEach(function () {
|
||||
this.sandbox.stub(process, 'exit')
|
||||
this.sandbox.stub(logger, 'error')
|
||||
})
|
||||
|
||||
it('.exit', function () {
|
||||
util.exit(2)
|
||||
expect(process.exit).to.be.calledWith(2)
|
||||
|
||||
util.exit(0)
|
||||
expect(process.exit).to.be.calledWith(0)
|
||||
})
|
||||
|
||||
it('.logErrorExit1', function () {
|
||||
const err = new Error('foo')
|
||||
|
||||
util.logErrorExit1(err)
|
||||
|
||||
expect(process.exit).to.be.calledWith(1)
|
||||
expect(logger.error).to.be.calledWith('foo')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user