mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-28 18:23:35 +00:00
test(cloudcmd) coverage
This commit is contained in:
parent
0dd475fcff
commit
ab83db8059
8 changed files with 74 additions and 153 deletions
|
|
@ -6,18 +6,24 @@ const test = require('tape');
|
|||
const diff = require('sinon-called-with-diff');
|
||||
const sinon = diff(require('sinon'));
|
||||
|
||||
const dir = path.join('..', '..', 'server');
|
||||
const dir = path.join(__dirname, '..', '..', 'server');
|
||||
|
||||
const pathConfig = path.join(dir, 'config');
|
||||
const pathRoot = `${dir}/root`;
|
||||
|
||||
const stub = require('mock-require');
|
||||
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 originalConfig = require(pathConfig);
|
||||
const config = sinon.stub().returns(false);
|
||||
|
||||
stub(pathConfig, config);
|
||||
|
|
@ -28,7 +34,9 @@ test('cloudcmd: root: config', (t) => {
|
|||
|
||||
t.ok(config.calledWith('root'), 'should call config');
|
||||
|
||||
stub(pathConfig, originalConfig);
|
||||
clean(pathConfig);
|
||||
clean(pathRoot);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
@ -42,8 +50,8 @@ test('cloudcmd: root: mellow', (t) => {
|
|||
pathToWin
|
||||
};
|
||||
|
||||
const originalMellow = stub('mellow', mellow);
|
||||
const originalConfig = stub(pathConfig, config);
|
||||
stub('mellow', mellow);
|
||||
stub(pathConfig, config);
|
||||
|
||||
const root = require(pathRoot);
|
||||
const dir = 'hello';
|
||||
|
|
@ -53,8 +61,9 @@ test('cloudcmd: root: mellow', (t) => {
|
|||
|
||||
t.ok(pathToWin.calledWith(dir, dirRoot), 'should call mellow');
|
||||
|
||||
stub('mellow', originalMellow);
|
||||
stub(pathConfig, originalConfig);
|
||||
clean('mellow');
|
||||
clean(pathConfig);
|
||||
clean(pathRoot);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue