fix(validate) root: crash when --no-root used

This commit is contained in:
coderaiser 2016-12-06 11:14:40 +02:00
parent 3931915ee8
commit 383f0ce39f
3 changed files with 32 additions and 4 deletions

View file

@ -97,7 +97,7 @@ if (args.version) {
readConfig(args.config);
const options = {
root: args.root,
root: args.root || '/', /* --no-root */
editor: args.editor,
packer: args.packer,
prefix: args.prefix

View file

@ -9,12 +9,16 @@ module.exports.packer = packer;
function root(dir, fn) {
var fs;
if (typeof dir !== 'string')
throw Error('dir should be a string');
if (dir !== '/') {
fs = require('fs');
fs = require('fs');
fs.stat(dir, function(error) {
if (error)
exit('cloudcmd --root: %s', error.message);
else if (typeof fn === 'function')
return exit('cloudcmd --root: %s', error.message);
if (typeof fn === 'function')
fn('root:', dir);
});
}

24
test/lib/validate.js Normal file
View file

@ -0,0 +1,24 @@
'use strict';
const test = require('tape');
const root = '../../';
const validate = require(root + 'lib/server/validate');
const before = require('../before');
test('validate: root: bad', (t) => {
const config = {
root: Math.random()
};
const fn = () => {
before({config}, (port, after) => {
t.fail('should not create server');
after();
t.end();
});
};
t.throws(fn, /dir should be a string/, 'should throw');
t.end();
});