diff --git a/index.js b/index.js index 0f1e551c..d9b8ec36 100644 --- a/index.js +++ b/index.js @@ -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) { diff --git a/package.json b/package.json index 73e32cf9..b4de87fd 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/xvfb_spec.js b/test/xvfb_spec.js new file mode 100644 index 00000000..39e118fb --- /dev/null +++ b/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 + }) + }) +})