feature(cloudcmd) sinon, sinon-called-with-diff -> @cloudcmd/stub

This commit is contained in:
coderaiser 2018-11-23 11:42:15 +02:00
parent 2f56d2b5ca
commit 497f7bcd40
24 changed files with 182 additions and 222 deletions

View file

@ -1,10 +1,9 @@
'use strict';
const {join} = require('path');
const test = require('tape');
const diff = require('sinon-called-with-diff');
const sinon = diff(require('sinon'));
const tryTo = require('try-to-tape');
const test = tryTo(require('tape'));
const stub = require('@cloudcmd/stub');
const dir = join(__dirname, '..', '..');
const modulesPath = join(dir, 'json', 'modules.json');
@ -14,7 +13,12 @@ const localModules = require(modulesPath);
const modulas = require(`${dir}/server/modulas`);
const cloudcmd = require(cloudcmdPath);
const {request} = require('serve-once')(cloudcmd);
const {request} = require('serve-once')(cloudcmd, {
config: {
auth: false,
dropbox: false,
}
});
test('cloudcmd: modules', async (t) => {
const modules = {
@ -68,7 +72,7 @@ test('cloudcmd: modules: wrong route', async (t) => {
test('cloudcmd: modules: no', (t) => {
const fn = modulas();
const url = '/json/modules.json';
const send = sinon.stub();
const send = stub();
fn({url}, {send});

View file

@ -1,70 +0,0 @@
'use strict';
const path = require('path');
const test = require('tape');
const diff = require('sinon-called-with-diff');
const sinon = diff(require('sinon'));
const dir = path.join(__dirname, '..', '..', 'server');
const pathConfig = path.join(dir, 'config');
const pathRoot = `${dir}/root`;
const clean = require('clear-module');
const {cache, resolve} = require;
const stub = (name, exports) => {
require(name);
const resolved = resolve(name);
cache[resolved].exports = exports;
};
test('cloudcmd: root: config', (t) => {
clean(pathRoot);
const config = sinon.stub().returns(false);
stub(pathConfig, config);
const root = require(pathRoot);
root('hello');
t.ok(config.calledWith('root'), 'should call config');
clean(pathConfig);
clean(pathRoot);
t.end();
});
test('cloudcmd: root: mellow', (t) => {
clean(pathRoot);
const config = sinon.stub().returns('');
const pathToWin = sinon.stub();
const mellow = {
pathToWin
};
stub('mellow', mellow);
stub(pathConfig, config);
const root = require(pathRoot);
const dir = 'hello';
const dirRoot = '/';
root(dir);
t.ok(pathToWin.calledWith(dir, dirRoot), 'should call mellow');
clean('mellow');
clean(pathConfig);
clean(pathRoot);
t.end();
});

View file

@ -1,8 +1,7 @@
'use strict';
const test = require('tape');
const diff = require('sinon-called-with-diff');
const sinon = diff(require('sinon'));
const stub = require('@cloudcmd/stub');
const mockRequire = require('mock-require');
const {reRequire} = mockRequire;
@ -38,7 +37,7 @@ test('cloudcmd: terminal: disabled: listen', (t) => {
});
test('cloudcmd: terminal: enabled', (t) => {
const term = sinon.stub();
const term = stub();
const arg = 'hello';
mockRequire(configPath, () => '/terminal');
@ -56,7 +55,7 @@ test('cloudcmd: terminal: enabled', (t) => {
test('cloudcmd: terminal: enabled: no string', (t) => {
const {log:originalLog} = console;
const log = sinon.stub();
const log = stub();
mockRequire(configPath, () => 'hello');