diff --git a/client/client.js b/client/client.js index 3b394457..c2fda214 100644 --- a/client/client.js +++ b/client/client.js @@ -40,13 +40,6 @@ load.addErrorListener((e, src) => { function CloudCmdProto(DOM) { let Listeners; - const log = (...a) => { - if (!isDev) - return; - - console.log(...a); - }; - Emitify.call(this); const CloudCmd = this; @@ -57,7 +50,12 @@ function CloudCmdProto(DOM) { Files, } = DOM; - this.log = log; + this.log = (...a) => { + if (!isDev) + return; + + console.log(...a); + }; this.prefix = ''; this.prefixSocket = ''; this.prefixURL = ''; @@ -67,8 +65,7 @@ function CloudCmdProto(DOM) { this.MIN_ONE_PANEL_WIDTH = 1155; this.HOST = location.origin || location.protocol + '//' + location.host; - const TITLE = 'Cloud Commander'; - this.TITLE = TITLE; + this.TITLE = 'Cloud Commander'; this.sort = { left: 'name', diff --git a/client/cloudcmd.js b/client/cloudcmd.js index 854bcf06..bb65a790 100644 --- a/client/cloudcmd.js +++ b/client/cloudcmd.js @@ -22,9 +22,7 @@ module.exports = window.CloudCmd = async (config) => { window.Util = require('../common/util'); window.CloudFunc = require('../common/cloudfunc'); - const DOM = require('./dom'); - - window.DOM = DOM; + window.DOM = require('./dom'); window.CloudCmd = require('./client'); await register(config); diff --git a/client/dom/index.js b/client/dom/index.js index abc1c607..5785fd32 100644 --- a/client/dom/index.js +++ b/client/dom/index.js @@ -5,12 +5,8 @@ const Util = require('../../common/util'); const Images = require('./images'); -const load = require('./load'); -const Files = require('./files'); const RESTful = require('./rest'); -const IO = require('./io'); const Storage = require('./storage'); -const Dialog = require('./dialog'); const renameCurrent = require('./operations/rename-current'); const CurrentFile = require('./current-file'); @@ -26,12 +22,12 @@ const DOM = { const CurrentInfo = {}; DOM.Images = Images; -DOM.load = load; -DOM.Files = Files; +DOM.load = require('./load'); +DOM.Files = require('./files'); DOM.RESTful = RESTful; -DOM.IO = IO; +DOM.IO = require('./io'); DOM.Storage = Storage; -DOM.Dialog = Dialog; +DOM.Dialog = require('./dialog'); DOM.CurrentInfo = CurrentInfo; module.exports = DOM; @@ -791,7 +787,6 @@ module.exports.updateCurrentInfo = (currentFile) => { const info = DOM.CurrentInfo; const current = currentFile || DOM.getCurrentFile(); const files = current.parentElement; - const panel = files.parentElement || DOM.getPanel(); const panelPassive = DOM.getPanel({ active: false, @@ -814,7 +809,7 @@ module.exports.updateCurrentInfo = (currentFile) => { info.mode = DOM.getCurrentMode(current); info.name = name; info.path = DOM.getCurrentPath(current); - info.panel = panel; + info.panel = files.parentElement || DOM.getPanel(); info.panelPassive = panelPassive; info.size = DOM.getCurrentSize(current); info.isDir = DOM.isCurrentIsDir(); diff --git a/client/dom/operations/rename-current.spec.js b/client/dom/operations/rename-current.spec.js index 4aa6f7e6..ae60adf5 100644 --- a/client/dom/operations/rename-current.spec.js +++ b/client/dom/operations/rename-current.spec.js @@ -29,12 +29,10 @@ test('cloudcmd: client: dom: renameCurrent: file exist', async (t) => { const name = 'hello'; const {CloudCmd} = global; - const CloudCmdStub = { + global.CloudCmd = { refresh: stub(), }; - global.CloudCmd = CloudCmdStub; - const prompt = stub().returns([null, name]); const confirm = stub().returns([true]); diff --git a/client/key/index.spec.js b/client/key/index.spec.js index 78e42ce7..acc8d15d 100644 --- a/client/key/index.spec.js +++ b/client/key/index.spec.js @@ -13,19 +13,15 @@ const { getCloudCmd, } = require('./vim/globals.fixture'); -const DOM = getDOM(); -const CloudCmd = getCloudCmd(); - -global.DOM = DOM; -global.CloudCmd = CloudCmd; +global.DOM = getDOM(); +global.CloudCmd = getCloudCmd(); test('cloudcmd: client: key: enable vim', async (t) => { const vim = stub(); - const configStub = stub().returns(true); const {CloudCmd} = global; const {config} = CloudCmd; - CloudCmd.config = configStub; + CloudCmd.config = stub().returns(true); mockRequire('./vim', vim); const {_listener, setBind} = reRequire('.'); diff --git a/client/key/vim/index.spec.js b/client/key/vim/index.spec.js index 00cd1603..886eb578 100644 --- a/client/key/vim/index.spec.js +++ b/client/key/vim/index.spec.js @@ -235,10 +235,9 @@ test('cloudcmd: client: key: paste', (t) => { }); test('cloudcmd: client: key: selectFile: ..', (t) => { - const selectFile = stub(); const getCurrentName = stub(); - DOM.selectFile = selectFile; + DOM.selectFile = stub(); DOM.getCurrentName = () => '..'; const current = {}; diff --git a/client/modules/markdown.js b/client/modules/markdown.js index e5810300..759805c5 100644 --- a/client/modules/markdown.js +++ b/client/modules/markdown.js @@ -22,7 +22,6 @@ module.exports.hide = () => { }; async function show(name, options = {}) { - const relativeQuery = '?relative'; const { positionLoad, relative, @@ -31,7 +30,7 @@ async function show(name, options = {}) { Images.show.load(positionLoad); if (relative) - name += relativeQuery; + name += '?relative'; const [error, innerHTML] = await Markdown.read(name); Images.hide(); diff --git a/client/modules/view/types.spec.js b/client/modules/view/types.spec.js index fc93fa97..9f157841 100644 --- a/client/modules/view/types.spec.js +++ b/client/modules/view/types.spec.js @@ -38,14 +38,12 @@ test('cloudcmd: client: view: types: detectType', async (t) => { }); test('cloudcmd: client: view: types: detectType: found', async (t) => { - const fetch = stub().returns({ + const originalFetch = global.fetch; + global.fetch = stub().returns({ headers: [ ['content-type', 'image/png'], ], }); - - const originalFetch = global.fetch; - global.fetch = fetch; const result = await _detectType('/hello'); global.fetch = originalFetch; diff --git a/common/datetime.spec.js b/common/datetime.spec.js index 2d8f529e..cdf221ba 100644 --- a/common/datetime.spec.js +++ b/common/datetime.spec.js @@ -19,15 +19,14 @@ test('common: datetime: no arg', (t) => { const {Date} = global; let called = false; - const myDate = class extends Date { + + global.Date = class extends Date { constructor() { super(); called = true; } }; - global.Date = myDate; - datetime(); global.Date = Date; diff --git a/test/common/cloudfunc.js b/test/common/cloudfunc.js index a9987f10..af701540 100644 --- a/test/common/cloudfunc.js +++ b/test/common/cloudfunc.js @@ -68,7 +68,6 @@ let Expect = '
' + test('cloudfunc: render', (t) => { const template = readFilesSync(FS_DIR, TMPL, 'utf8'); - const expect = fs.readFileSync(EXPECT_PATH, 'utf8'); time('CloudFunc.buildFromJSON'); const result = CloudFunc.buildFromJSON({ @@ -77,7 +76,7 @@ test('cloudfunc: render', (t) => { template, }); - Expect += expect; + Expect += fs.readFileSync(EXPECT_PATH, 'utf8'); let i; const isNotOk = Expect