Skip to content

Commit 199fe62

Browse files
authored
Merge pull request #2 from cypress-io/issue-1
fix mutations
2 parents a52cddc + 588121e commit 199fe62

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,15 @@ Xvfb.prototype = {
101101
},
102102

103103
_restoreDisplayEnvVariable: function () {
104-
process.env.DISPLAY = this._oldDisplay
104+
// https://github.com/cypress-io/xvfb/issues/1
105+
// only reset truthy backed' up values
106+
if (this._oldDisplay) {
107+
process.env.DISPLAY = this._oldDisplay
108+
} else {
109+
// else delete the values to get back
110+
// to undefined
111+
delete process.env.DISPLAY
112+
}
105113
},
106114

107115
_spawnProcess: function (lockFileExists, onAsyncSpawnError) {

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
"dependencies": {},
1414
"license": "MIT",
1515
"scripts": {
16-
"test": "standard --fix --verbose *.js",
16+
"test": "standard --fix --verbose *.js && mocha",
1717
"semantic-release": "semantic-release pre && npm publish --access public && semantic-release post",
1818
"commit": "commit-wizard"
1919
},
2020
"devDependencies": {
21+
"chai": "^4.1.2",
2122
"condition-circle": "^1.5.0",
23+
"mocha": "^3.5.0",
2224
"pre-git": "^3.15.0",
2325
"semantic-release": "^6.3.6",
2426
"simple-commit-message": "^3.0.2",

test/xvfb_spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const { expect } = require('chai')
2+
3+
const Xvfb = require('../')
4+
5+
describe('xvfb', function(){
6+
beforeEach(function(){
7+
this.xvfb = new Xvfb()
8+
})
9+
10+
context('issue: #1', function(){
11+
it('issue #1: does not mutate process.env.DISPLAY', function(){
12+
delete process.env.DISPLAY
13+
14+
expect(process.env.DISPLAY).to.be.undefined
15+
16+
this.xvfb._setDisplayEnvVariable()
17+
this.xvfb._restoreDisplayEnvVariable()
18+
19+
expect(process.env.DISPLAY).to.be.undefined
20+
})
21+
})
22+
})

0 commit comments

Comments
 (0)