mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-22 18:29:26 +00:00
feature: root: get rid of mock-require
This commit is contained in:
parent
1bef0d4381
commit
c7f9090126
2 changed files with 9 additions and 25 deletions
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
const mellow = require('mellow');
|
||||
|
||||
module.exports = (dir, root) => {
|
||||
return mellow.webToWin(dir, root || '/');
|
||||
module.exports = (dir, root, {webToWin = mellow.webToWin} = {}) => {
|
||||
return webToWin(dir, root || '/');
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,34 +3,18 @@
|
|||
const {test, stub} = require('supertape');
|
||||
|
||||
const mockRequire = require('mock-require');
|
||||
const {reRequire, stopAll} = mockRequire;
|
||||
|
||||
const pathConfig = './config';
|
||||
const pathRoot = './root';
|
||||
const root = require('./root');
|
||||
|
||||
test('cloudcmd: root: mellow', (t) => {
|
||||
const config = stub().returns('');
|
||||
const webToWin = stub();
|
||||
|
||||
const mellow = {
|
||||
webToWin,
|
||||
};
|
||||
|
||||
mockRequire('mellow', mellow);
|
||||
mockRequire(pathConfig, config);
|
||||
|
||||
const root = reRequire(pathRoot);
|
||||
|
||||
const dir = 'hello';
|
||||
const dirRoot = '/';
|
||||
|
||||
root(dir);
|
||||
|
||||
mockRequire.stop('mellow');
|
||||
mockRequire.stopAll(pathConfig);
|
||||
reRequire(pathRoot);
|
||||
|
||||
stopAll();
|
||||
|
||||
|
||||
root(dir, '', {
|
||||
webToWin,
|
||||
});
|
||||
|
||||
t.calledWith(webToWin, [dir, dirRoot], 'should call mellow');
|
||||
t.end();
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue