mirror of
https://github.com/cypress-io/cypress.git
synced 2026-01-25 00:19:22 -06:00
* wip [skip ci] update * wip [skip ci] update test * [skip ci] fix env var * bump sinon, create helper utility to always throw when a stub is called without being given stubbed behavior * update failing specs * fix some error messages * update snapshot * warning -> note, add snapshot tests * change snapshot os.release, test env vars
93 lines
2.5 KiB
JavaScript
93 lines
2.5 KiB
JavaScript
require('../../spec_helper')
|
|
|
|
const os = require('os')
|
|
const xvfb = require(`${lib}/exec/xvfb`)
|
|
|
|
describe('lib/exec/xvfb', function () {
|
|
beforeEach(function () {
|
|
os.platform.returns('win32')
|
|
})
|
|
|
|
context('debugXvfb', function () {
|
|
it('outputs when enabled', function () {
|
|
sinon.stub(process.stderr, 'write').returns(undefined)
|
|
sinon.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 () {
|
|
sinon.stub(process.stderr, 'write')
|
|
sinon.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 () {
|
|
sinon.stub(xvfb._xvfb, 'startAsync').resolves()
|
|
return xvfb.start()
|
|
})
|
|
|
|
it('fails with error message', function () {
|
|
const message = 'nope'
|
|
sinon.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
|
|
|
|
sinon.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 () {
|
|
|
|
it('does not need xvfb on osx', function () {
|
|
os.platform.returns('darwin')
|
|
|
|
expect(xvfb.isNeeded()).to.be.false
|
|
})
|
|
|
|
it('does not need xvfb on linux when DISPLAY is set', function () {
|
|
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 () {
|
|
os.platform.returns('linux')
|
|
|
|
expect(xvfb.isNeeded()).to.be.true
|
|
})
|
|
})
|
|
})
|