test(validate) editor

This commit is contained in:
coderaiser 2017-03-24 16:41:34 +02:00
parent 668a0dad9a
commit 02e835eb06
2 changed files with 43 additions and 1 deletions

View file

@ -12,7 +12,7 @@ function root(dir, fn) {
if (dir === '/')
return;
const fs = require('fs');
fs.stat(dir, (error) => {

View file

@ -1,7 +1,15 @@
'use strict';
const test = require('tape');
const sinon = require('sinon');
const before = require('../before');
const dir = '../..';
const validatePath = `${dir}/server/validate`;
const exitPath = `${dir}/server/exit`;
const validate = require(validatePath);
test('validate: root: bad', (t) => {
const config = {
@ -19,3 +27,37 @@ test('validate: root: bad', (t) => {
t.end();
});
test('validate: root: /', (t) => {
const fn = sinon.stub();
validate.root('/', fn);
t.notOk(fn.called, 'should not call fn');
t.end();
});
test('validate: editor: not valid', (t) => {
const fn = sinon.stub();
clean();
require(exitPath);
stub(exitPath, fn);
const {editor} = require(validatePath);
const msg = 'cloudcmd --editor: could be "dword", "edward" or "deepword" only';
editor('hello');
t.ok(fn.calledWith(msg), 'should call fn');
t.end();
});
function clean() {
delete require.cache[require.resolve(validatePath)];
delete require.cache[require.resolve(exitPath)];
}
function stub(name, fn) {
require.cache[require.resolve(name)].exports = fn;
}