mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
test(validate) editor
This commit is contained in:
parent
668a0dad9a
commit
02e835eb06
2 changed files with 43 additions and 1 deletions
|
|
@ -12,7 +12,7 @@ function root(dir, fn) {
|
|||
|
||||
if (dir === '/')
|
||||
return;
|
||||
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
fs.stat(dir, (error) => {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue