Skip to content

Commit

Permalink
feat: add EGG_HOME to getHomedir for test (#25)
Browse files Browse the repository at this point in the history
Use process.env.EGG_HOME to mock `home`

Ref eggjs/egg#129
  • Loading branch information
popomore authored and dead-horse committed Oct 24, 2016
1 parent afca35a commit 023007c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ module.exports = {
},

getHomedir() {
return homedir() || '/home/admin';
// EGG_HOME for test
return process.env.EGG_HOME || homedir() || '/home/admin';
},

methods: [ 'head', 'options', 'get', 'put', 'patch', 'post', 'delete' ],
Expand Down
5 changes: 5 additions & 0 deletions test/utils/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@ describe('test/utils/index.test.js', () => {
mm(os, 'homedir', null);
utils.getHomedir().should.equal('/home/admin');
});

it('should return when EGG_HOME exists', () => {
mm(process.env, 'EGG_HOME', '/path/to/home');
utils.getHomedir().should.equal('/path/to/home');
});
});
});

0 comments on commit 023007c

Please sign in to comment.