From efb686c33230c755c85b4f49a94b7fe44315d653 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Sat, 4 Dec 2021 01:21:02 +0200 Subject: [PATCH] chore(cloudcmd) lint --- client/dom/io/index.spec.js | 4 +++- client/dom/operations/rename-current.spec.js | 6 +++++- client/key/vim/index.spec.js | 16 ++-------------- client/load-module.js | 1 + client/modules/polyfill.spec.js | 4 ++++ client/modules/view/index.spec.js | 8 +++++++- server/cloudcmd.spec.js | 1 + server/root.spec.js | 4 +++- server/terminal.spec.js | 7 ++++++- server/validate.spec.js | 13 ++++++------- test/rest/move.js | 4 ++-- test/rest/rename.js | 4 +++- 12 files changed, 43 insertions(+), 29 deletions(-) diff --git a/client/dom/io/index.spec.js b/client/dom/io/index.spec.js index 23f002c0..80c9bee2 100644 --- a/client/dom/io/index.spec.js +++ b/client/dom/io/index.spec.js @@ -4,7 +4,7 @@ const test = require('supertape'); const stub = require('@cloudcmd/stub'); const mockRequire = require('mock-require'); -const {reRequire} = mockRequire; +const {reRequire, stopAll} = mockRequire; test('client: dom: io', (t) => { const sendRequest = stub(); @@ -22,6 +22,8 @@ test('client: dom: io', (t) => { url: '/fs/hello?dir', }; + stopAll(); + t.calledWith(sendRequest, [expected]); t.end(); }); diff --git a/client/dom/operations/rename-current.spec.js b/client/dom/operations/rename-current.spec.js index f438fa94..4aa6f7e6 100644 --- a/client/dom/operations/rename-current.spec.js +++ b/client/dom/operations/rename-current.spec.js @@ -4,7 +4,7 @@ const test = require('supertape'); const stub = require('@cloudcmd/stub'); const mockRequire = require('mock-require'); -const {reRequire} = mockRequire; +const {reRequire, stopAll} = mockRequire; test('cloudcmd: client: dom: renameCurrent: isCurrentFile', async (t) => { const current = {}; @@ -18,6 +18,8 @@ test('cloudcmd: client: dom: renameCurrent: isCurrentFile', async (t) => { const renameCurrent = reRequire('./rename-current'); await renameCurrent(current); + stopAll(); + t.calledWith(isCurrentFile, [current], 'should call isCurrentFile'); t.end(); }); @@ -55,6 +57,8 @@ test('cloudcmd: client: dom: renameCurrent: file exist', async (t) => { const expected = 'Directory "hello" already exists. Proceed?'; global.CloudCmd = CloudCmd; + stopAll(); + t.calledWith(confirm, [expected], 'should call confirm'); t.end(); }); diff --git a/client/key/vim/index.spec.js b/client/key/vim/index.spec.js index d211e04b..00cd1603 100644 --- a/client/key/vim/index.spec.js +++ b/client/key/vim/index.spec.js @@ -53,7 +53,6 @@ test('cloudcmd: client: key: set next file current', (t) => { vim('j', {}); t.calledWith(setCurrentFile, [nextSibling], 'should set next file'); - t.end(); }); @@ -73,7 +72,6 @@ test('cloudcmd: client: key: set next file current', (t) => { vim('j', {}); t.calledWith(setCurrentFile, [nextSibling], 'should set next file'); - t.end(); }); @@ -92,7 +90,6 @@ test('cloudcmd: client: key: set next file current: g', (t) => { vim('j', {}); t.calledWith(setCurrentFile, [nextSibling], 'should ignore g'); - t.end(); }); @@ -116,7 +113,6 @@ test('cloudcmd: client: key: set +2 file current', (t) => { vim('j', event); t.calledWith(setCurrentFile, [last], 'should set next file'); - t.end(); }); @@ -172,7 +168,6 @@ test('cloudcmd: client: key: delete +2 files from current', (t) => { vim('j', event); t.calledWith(show, ['delete'], 'should call delete'); - t.end(); }); @@ -201,7 +196,6 @@ test('cloudcmd: client: key: copy: no', (t) => { vim('y', {}); t.notOk(copy.called, 'should not copy files'); - t.end(); }); @@ -237,7 +231,6 @@ test('cloudcmd: client: key: paste', (t) => { vim('p', {}); t.ok(paste.calledWith(), 'should paste files'); - t.end(); }); @@ -286,7 +279,6 @@ test('cloudcmd: client: key: set last file current: shift + g', (t) => { vim('G', {}); t.calledWith(setCurrentFile, [last], 'should set last file'); - t.end(); }); @@ -307,7 +299,6 @@ test('cloudcmd: client: key: set last file current: $', (t) => { vim('$', {}); t.calledWith(setCurrentFile, [last], 'should set last file'); - t.end(); }); @@ -330,7 +321,6 @@ test('cloudcmd: client: key: set first file current: gg', (t) => { vim('g', {}); t.calledWith(setCurrentFile, [first], 'should set first file'); - t.end(); }); @@ -352,7 +342,6 @@ test('cloudcmd: client: key: set first file current: ^', (t) => { vim('^', {}); t.calledWith(setCurrentFile, [first], 'should set first file'); - t.end(); }); @@ -367,7 +356,6 @@ test('cloudcmd: client: key: visual', (t) => { vim('v', {}); t.calledWith(toggleSelectedFile, [element], 'should toggle selection'); - t.end(); }); @@ -431,7 +419,7 @@ test('cloudcmd: client: key: n', (t) => { vim('n', event); - stopAll(pathFind); + stopAll(); t.ok(findNext.calledWith(), 'should call findNext'); t.end(); @@ -449,7 +437,7 @@ test('cloudcmd: client: key: N', (t) => { vim('N', event); - stopAll(pathFind); + stopAll(); t.ok(findPrevious.calledWith(), 'should call findPrevious'); t.end(); diff --git a/client/load-module.js b/client/load-module.js index 5111259c..b9fb9f41 100644 --- a/client/load-module.js +++ b/client/load-module.js @@ -27,6 +27,7 @@ module.exports = function loadModule(params) { CloudCmd[name] = () => { exec(doBefore); + const {prefix} = CloudCmd; const pathFull = prefix + CloudCmd.DIRCLIENT_MODULES + path + '.js'; diff --git a/client/modules/polyfill.spec.js b/client/modules/polyfill.spec.js index ec2a17ac..5c31b27f 100644 --- a/client/modules/polyfill.spec.js +++ b/client/modules/polyfill.spec.js @@ -4,6 +4,8 @@ const test = require('supertape'); const mockRequire = require('mock-require'); const stub = require('@cloudcmd/stub'); +const {stopAll} = mockRequire; + test('cloudcmd: client: polyfill: scrollIntoViewIfNeaded', (t) => { const {DOM} = global; const scroll = stub(); @@ -26,6 +28,8 @@ test('cloudcmd: client: polyfill: scrollIntoViewIfNeaded', (t) => { block: 'nearest', }]; + stopAll(); + t.calledWith(scroll, args, 'should call scrollIntoViewIfNeaded'); t.end(); }); diff --git a/client/modules/view/index.spec.js b/client/modules/view/index.spec.js index 3d2c3ee7..8bb03493 100644 --- a/client/modules/view/index.spec.js +++ b/client/modules/view/index.spec.js @@ -6,7 +6,7 @@ const autoGlobals = require('auto-globals'); const test = autoGlobals(require('supertape')); const stub = require('@cloudcmd/stub'); const mockRequire = require('mock-require'); -const {reRequire} = mockRequire; +const {reRequire, stopAll} = mockRequire; test('cloudcmd: client: view: initConfig', (t) => { let config; @@ -78,6 +78,8 @@ test('cloudcmd: client: view: html', (t) => { const [first] = open.args; const [arg] = first; + stopAll(); + t.deepEqual(first, [arg, _Config]); t.end(); }); @@ -101,6 +103,8 @@ test('cloudcmd: client: view: createIframe', (t) => { width: '100%', }; + stopAll(); + t.calledWith(createElement, ['iframe', expected]); t.end(); }); @@ -118,6 +122,8 @@ test('cloudcmd: client: view: createIframe: returns', (t) => { const src = '/hello.html'; const result = _createIframe(src); + stopAll(); + t.equal(result, el); t.end(); }); diff --git a/server/cloudcmd.spec.js b/server/cloudcmd.spec.js index 32d6db24..1deaef42 100644 --- a/server/cloudcmd.spec.js +++ b/server/cloudcmd.spec.js @@ -112,6 +112,7 @@ test('cloudcmd: auth: reject', (t) => { const username = 'root'; const password = 'toor'; + config('auth', true); config('username', username); config('password', password); diff --git a/server/root.spec.js b/server/root.spec.js index 368ea6e5..af640fbd 100644 --- a/server/root.spec.js +++ b/server/root.spec.js @@ -3,7 +3,7 @@ const test = require('supertape'); const stub = require('@cloudcmd/stub'); const mockRequire = require('mock-require'); -const {reRequire} = mockRequire; +const {reRequire, stopAll} = mockRequire; const pathConfig = './config'; const pathRoot = './root'; @@ -29,6 +29,8 @@ test('cloudcmd: root: mellow', (t) => { mockRequire.stopAll(pathConfig); reRequire(pathRoot); + stopAll(); + t.calledWith(webToWin, [dir, dirRoot], 'should call mellow'); t.end(); }); diff --git a/server/terminal.spec.js b/server/terminal.spec.js index 18574189..d734b547 100644 --- a/server/terminal.spec.js +++ b/server/terminal.spec.js @@ -9,6 +9,8 @@ const terminalPath = './terminal'; const terminal = require('./terminal'); const {createConfigManager} = require('./cloudcmd'); +const {stopAll} = mockRequire; + test('cloudcmd: terminal: disabled', (t) => { const config = createConfigManager(); config('terminal', false); @@ -38,6 +40,8 @@ test('cloudcmd: terminal: enabled', (t) => { const terminal = require(terminalPath); terminal(arg); + stopAll(); + t.calledWith(term, [arg], 'should call terminal'); t.end(); }); @@ -67,12 +71,13 @@ test('cloudcmd: terminal: no arg', (t) => { mockRequire('gritty', gritty); const config = createConfigManager(); + config('terminal', true); config('terminalPath', 'gritty'); const result = terminal(config); - mockRequire.stop('gritty'); + stopAll(); t.equal(result, gritty); t.end(); diff --git a/server/validate.spec.js b/server/validate.spec.js index 29cf23e4..14868530 100644 --- a/server/validate.spec.js +++ b/server/validate.spec.js @@ -6,7 +6,7 @@ const test = require('supertape'); const stub = require('@cloudcmd/stub'); const tryCatch = require('try-catch'); const mockRequire = require('mock-require'); -const {reRequire} = mockRequire; +const {reRequire, stopAll} = mockRequire; const dir = '..'; @@ -64,7 +64,7 @@ test('validate: root: stat', (t) => { const msg = 'cloudcmd --root: %s'; fs.statSync = statSync; - mockRequire.stop(exitPath); + stopAll(); t.calledWith(fn, [msg, error], 'should call fn'); t.end(); @@ -80,7 +80,7 @@ test('validate: packer: not valid', (t) => { packer('hello'); - mockRequire.stop(exitPath); + stopAll(); t.calledWith(fn, [msg], 'should call fn'); t.end(); @@ -96,7 +96,7 @@ test('validate: editor: not valid', (t) => { editor('hello'); - mockRequire.stop(exitPath); + stopAll(); t.calledWith(fn, [msg], 'should call fn'); t.end(); @@ -110,7 +110,7 @@ test('validate: columns', (t) => { columns('name-size-date'); - mockRequire.stop(exitPath); + stopAll(); t.notOk(fn.called, 'should not call exit'); t.end(); @@ -130,8 +130,7 @@ test('validate: columns: wrong', (t) => { columns('hello'); - mockRequire.stop(exitPath); - mockRequire.stop(columnsPath); + stopAll(); t.calledWith(fn, [msg], 'should call exit'); t.end(); diff --git a/test/rest/move.js b/test/rest/move.js index 89985130..d36f2e04 100644 --- a/test/rest/move.js +++ b/test/rest/move.js @@ -7,7 +7,7 @@ const {Volume} = require('memfs'); const {ufs} = require('unionfs'); const mockRequire = require('mock-require'); -const {reRequire} = mockRequire; +const {reRequire, stopAll} = mockRequire; const serveOnce = require('serve-once'); const cloudcmdPath = '../../'; @@ -60,7 +60,7 @@ test('cloudcmd: rest: move', async (t) => { body: files, }); - mockRequire.stop('fs'); + stopAll(); t.equal(body, 'move: ok("["move.txt"]")', 'should move'); t.end(); diff --git a/test/rest/rename.js b/test/rest/rename.js index cdc7454f..ed7e11c5 100644 --- a/test/rest/rename.js +++ b/test/rest/rename.js @@ -7,7 +7,7 @@ const {Volume} = require('memfs'); const {ufs} = require('unionfs'); const mockRequire = require('mock-require'); -const {reRequire} = mockRequire; +const {reRequire, stopAll} = mockRequire; const serveOnce = require('serve-once'); const cloudcmdPath = '../../'; @@ -56,6 +56,8 @@ test('cloudcmd: rest: rename', async (t) => { const expected = 'rename: ok("{"from":"/fixture/mv.txt","to":"/fixture/tmp/mv.txt"}")'; + stopAll(); + t.equal(body, expected, 'should move'); t.end(); });