Files
cypress/cli/test/lib/exec/xvfb_spec.js
Brian Mann d54156e2f2 cli, fixes #921, #1113, #1126, #1127, make DEBUG logs work, show error when xvfb exits with status code 1, force tty in linux, handle colors in windows, enable logging cypress:xvfb stderr
* cli: fixes #838 start cypress in dev by routing through the CLI

- matches how we run in production better to keep parity and consistency

* cli: add coerceFalse for clarity

* cli: add global flag, update to work with windows

* server: bring into parity with root scripts

* cli: just execute start script directly to work with windows

* cli: if colors are supported then force them via env vars

- this fixes windows not displaying colors from electron because by
default isTTY is false (due to electron)

* cli: fixes #921 don't ignore stderr, inherit stdio on everything except when linux + xvfb

- filter out stderr messages coming from Xlib or libudev (from xvfb)

* cli, server: force stderr tty so that normalize tty behavior when piping

* server: drop in supports color so debug outputs more colors!

* server: remove empty line

* root: refer to cypress not monorepo

* cli: make util.supportsColor return boolean

* cl: add tests around spawn behavior with forcing colors, tty, and stdio configuration

* cli: handle xvfb onStderrData callback to output debug information

* cli: handle non zero exit code error from xvfb with special message
2017-12-24 19:03:57 -05:00

89 lines
2.5 KiB
JavaScript

require('../../spec_helper')
const os = require('os')
const xvfb = require(`${lib}/exec/xvfb`)
describe('exec xvfb', function () {
context('debugXvfb', function () {
it('outputs when enabled', function () {
this.sandbox.stub(process.stderr, 'write')
this.sandbox.stub(xvfb._debugXvfb, 'enabled').value(true)
xvfb._xvfb._onStderrData('asdf')
expect(process.stderr.write).to.be.calledWithMatch('cypress:xvfb')
expect(process.stderr.write).to.be.calledWithMatch('asdf')
})
it('does not output when disabled', function () {
this.sandbox.stub(process.stderr, 'write')
this.sandbox.stub(xvfb._debugXvfb, 'enabled').value(false)
xvfb._xvfb._onStderrData('asdf')
expect(process.stderr.write).not.to.be.calledWithMatch('cypress:xvfb')
expect(process.stderr.write).not.to.be.calledWithMatch('asdf')
})
})
context('#start', function () {
it('passes', function () {
this.sandbox.stub(xvfb._xvfb, 'startAsync').resolves()
return xvfb.start()
})
it('fails with error message', function () {
const message = 'nope'
this.sandbox.stub(xvfb._xvfb, 'startAsync').rejects(new Error(message))
return xvfb.start()
.then(() => {
throw new Error('Should have thrown an error')
})
.catch((err) => {
expect(err.message).to.include(message)
})
})
it('fails when xvfb exited with non zero exit code', function () {
const e = new Error('something bad happened')
e.nonZeroExitCode = true
this.sandbox.stub(xvfb._xvfb, 'startAsync').rejects(e)
return xvfb.start()
.then(() => {
throw new Error('Should have thrown an error')
})
.catch((err) => {
expect(err.known).to.be.true
expect(err.message).to.include('something bad happened')
expect(err.message).to.include('XVFB exited with a non zero exit code.')
})
})
})
context('#isNeeded', function () {
afterEach(() => delete process.env.DISPLAY)
it('does not need xvfb on osx', function () {
this.sandbox.stub(os, 'platform').returns('darwin')
expect(xvfb.isNeeded()).to.be.false
})
it('does not need xvfb on linux when DISPLAY is set', function () {
this.sandbox.stub(os, 'platform').returns('linux')
process.env.DISPLAY = ':99'
expect(xvfb.isNeeded()).to.be.false
})
it('does need xvfb on linux when no DISPLAY is set', function () {
this.sandbox.stub(os, 'platform').returns('linux')
expect(xvfb.isNeeded()).to.be.true
})
})
})