feature: client: key: vim: get rid of mock-require

This commit is contained in:
coderiaser 2026-01-25 21:41:24 +02:00
parent 77b70b2142
commit dc5867b006
2 changed files with 18 additions and 18 deletions

View file

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

View file

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