tests: prevent leaking changes to NODE_ENV

This commit is contained in:
Douglas Christopher Wilson 2022-02-08 18:40:07 -05:00
parent 82de4de5ab
commit a39e409cf3

View File

@ -83,28 +83,49 @@ describe('app.path()', function(){
}) })
describe('in development', function(){ describe('in development', function(){
before(function () {
this.env = process.env.NODE_ENV
process.env.NODE_ENV = 'development'
})
after(function () {
process.env.NODE_ENV = this.env
})
it('should disable "view cache"', function(){ it('should disable "view cache"', function(){
process.env.NODE_ENV = 'development';
var app = express(); var app = express();
assert.ok(!app.enabled('view cache')) assert.ok(!app.enabled('view cache'))
process.env.NODE_ENV = 'test';
}) })
}) })
describe('in production', function(){ describe('in production', function(){
before(function () {
this.env = process.env.NODE_ENV
process.env.NODE_ENV = 'production'
})
after(function () {
process.env.NODE_ENV = this.env
})
it('should enable "view cache"', function(){ it('should enable "view cache"', function(){
process.env.NODE_ENV = 'production';
var app = express(); var app = express();
assert.ok(app.enabled('view cache')) assert.ok(app.enabled('view cache'))
process.env.NODE_ENV = 'test';
}) })
}) })
describe('without NODE_ENV', function(){ describe('without NODE_ENV', function(){
before(function () {
this.env = process.env.NODE_ENV
process.env.NODE_ENV = ''
})
after(function () {
process.env.NODE_ENV = this.env
})
it('should default to development', function(){ it('should default to development', function(){
process.env.NODE_ENV = '';
var app = express(); var app = express();
assert.strictEqual(app.get('env'), 'development') assert.strictEqual(app.get('env'), 'development')
process.env.NODE_ENV = 'test';
}) })
}) })