feature: root: get rid of mock-require

This commit is contained in:
coderaiser 2024-03-21 08:49:14 +02:00
parent 1bef0d4381
commit c7f9090126
2 changed files with 9 additions and 25 deletions

View file

@ -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 || '/');
};

View file

@ -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();
});