Skip to content

Commit

Permalink
fix: always get the executor's homedir (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngot authored and fengmk2 committed Oct 13, 2016
1 parent 5f3f862 commit 47dff28
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';

const interopRequire = require('interop-require');
const homedir = require('node-homedir');

module.exports = exports = {
module.exports = {

loadFile(filepath) {
let exports;
Expand All @@ -25,7 +26,7 @@ module.exports = exports = {
},

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

methods: [ 'head', 'options', 'get', 'put', 'patch', 'post', 'delete' ],
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"is-type-of": "^1.0.0",
"koa": "^1.2.1",
"koa-router": "^5.4.0",
"node-homedir": "^0.0.1",
"ready-callback": "^1.0.0",
"utility": "^1.8.0"
}
Expand Down
13 changes: 12 additions & 1 deletion test/utils/index.test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
'use strict';

const mm = require('mm');
const os = require('os');
const utils = require('../../lib/utils');
const should = require('should');

describe('test/utils/index.test.js', () => {

afterEach(mm.restore);

describe('utils.getHomedir()', () => {
it('should return process.env.HOME', () => {
if (os.userInfo && os.userInfo().homedir) {
const userInfo = os.userInfo();
delete userInfo.homedir;
mm(os, 'userInfo', () => userInfo);
}
utils.getHomedir().should.equal(process.env.HOME);
});

it('should return /home/admin when process.env.HOME is not exist', () => {
mm(process.env, 'HOME', '');
utils.getHomedir().should.equal('/home/admin');
if (os.userInfo && os.userInfo().homedir) {
should.ok(utils.getHomedir().indexOf(process.env.USER) > -1);
} else {
utils.getHomedir().should.equal('/home/admin');
}
});
});
});

0 comments on commit 47dff28

Please sign in to comment.