Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以后发模块,先发 1.0.0

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

收到

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接改了吧 ^ 享受不到 patch 吧

"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');
}
});
});
});