Skip to content

Commit

Permalink
Merge pull request #2 from cypress-io/issue-1
Browse files Browse the repository at this point in the history
fix mutations
  • Loading branch information
brian-mann committed Sep 2, 2017
2 parents a52cddc + 588121e commit 199fe62
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
10 changes: 9 additions & 1 deletion index.js
Expand Up @@ -101,7 +101,15 @@ Xvfb.prototype = {
},

_restoreDisplayEnvVariable: function () {
process.env.DISPLAY = this._oldDisplay
// https://github.com/cypress-io/xvfb/issues/1
// only reset truthy backed' up values
if (this._oldDisplay) {
process.env.DISPLAY = this._oldDisplay
} else {
// else delete the values to get back
// to undefined
delete process.env.DISPLAY
}
},

_spawnProcess: function (lockFileExists, onAsyncSpawnError) {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -13,12 +13,14 @@
"dependencies": {},
"license": "MIT",
"scripts": {
"test": "standard --fix --verbose *.js",
"test": "standard --fix --verbose *.js && mocha",
"semantic-release": "semantic-release pre && npm publish --access public && semantic-release post",
"commit": "commit-wizard"
},
"devDependencies": {
"chai": "^4.1.2",
"condition-circle": "^1.5.0",
"mocha": "^3.5.0",
"pre-git": "^3.15.0",
"semantic-release": "^6.3.6",
"simple-commit-message": "^3.0.2",
Expand Down
22 changes: 22 additions & 0 deletions test/xvfb_spec.js
@@ -0,0 +1,22 @@
const { expect } = require('chai')

const Xvfb = require('../')

describe('xvfb', function(){
beforeEach(function(){
this.xvfb = new Xvfb()
})

context('issue: #1', function(){
it('issue #1: does not mutate process.env.DISPLAY', function(){
delete process.env.DISPLAY

expect(process.env.DISPLAY).to.be.undefined

this.xvfb._setDisplayEnvVariable()
this.xvfb._restoreDisplayEnvVariable()

expect(process.env.DISPLAY).to.be.undefined
})
})
})

0 comments on commit 199fe62

Please sign in to comment.