From dc5867b006edbd47d4a9061199976b1eeca26b27 Mon Sep 17 00:00:00 2001 From: coderiaser Date: Sun, 25 Jan 2026 21:41:24 +0200 Subject: [PATCH] feature: client: key: vim: get rid of mock-require --- client/key/vim/index.js | 16 +++++++++++----- client/key/vim/index.spec.js | 20 +++++++------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/client/key/vim/index.js b/client/key/vim/index.js index ddfe49c3..707fe777 100644 --- a/client/key/vim/index.js +++ b/client/key/vim/index.js @@ -40,12 +40,16 @@ const getOperations = (event, deps) => { toggleSelectedFile, Buffer = {}, createFindNext = _createFindNext, + createFindPrevious = _createFindPrevious, } = deps; return { findNext: createFindNext({ setCurrentByName, }), + findPrevious: createFindPrevious({ + setCurrentByName, + }), escape: unselectFiles, remove: () => { @@ -122,16 +126,18 @@ const getOperations = (event, deps) => { setCurrentByName(result); }, - - findPrevious: () => { - const name = finder.findPrevious(); - setCurrentByName(name); - }, }; }; module.exports.selectFile = selectFileNotParent; +const _createFindPrevious = (overrides = {}) => () => { + const {setCurrentByName} = overrides; + const name = finder.findPrevious(); + + setCurrentByName(name); +}; + const _createFindNext = (overrides = {}) => () => { const {setCurrentByName} = overrides; const name = finder.findNext(); diff --git a/client/key/vim/index.spec.js b/client/key/vim/index.spec.js index 6fcad11e..57f40a49 100644 --- a/client/key/vim/index.spec.js +++ b/client/key/vim/index.spec.js @@ -2,7 +2,6 @@ const {join} = require('node:path'); const {test, stub} = require('supertape'); -const mockRequire = require('mock-require'); const dir = '../'; @@ -18,8 +17,8 @@ const vim = require('./index.js'); const {assign} = Object; const {DOM} = globalThis; const {Buffer} = DOM; -const pathFind = join(dir, 'vim', 'find'); -const {reRequire, stopAll} = mockRequire; + +const {reRequire, stopAll} = require('mock-require'); test('cloudcmd: client: key: set next file: no', (t) => { const element = {}; @@ -584,19 +583,14 @@ test('cloudcmd: client: key: n', (t) => { test('cloudcmd: client: key: N', (t) => { const findPrevious = stub(); - - mockRequire(pathFind, { - findPrevious, - }); - - const vim = reRequire(`${dir}vim`); + const createFindPrevious = stub().returns(findPrevious); const event = {}; - vim('N', event); + vim('N', event, { + createFindPrevious, + }); - stopAll(); - - t.calledWithNoArgs(findPrevious, 'should call findPrevious'); + t.calledWithNoArgs(findPrevious); t.end(); });