Skip to content

Commit

Permalink
tests: prevent leaking changes to NODE_ENV
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Feb 8, 2022
1 parent 82de4de commit a39e409
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions test/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,49 @@ describe('app.path()', 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(){
process.env.NODE_ENV = 'development';
var app = express();
assert.ok(!app.enabled('view cache'))
process.env.NODE_ENV = 'test';
})
})

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(){
process.env.NODE_ENV = 'production';
var app = express();
assert.ok(app.enabled('view cache'))
process.env.NODE_ENV = 'test';
})
})

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(){
process.env.NODE_ENV = '';
var app = express();
assert.strictEqual(app.get('env'), 'development')
process.env.NODE_ENV = 'test';
})
})

0 comments on commit a39e409

Please sign in to comment.