Skip to content

Commit

Permalink
feature(fileop) read: persistent
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Sep 25, 2020
1 parent da96704 commit d884109
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions server/listen.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const fullstore = require('fullstore');
const operate = require('./operate');
const extract = require('./extract');
const pack = currify(require('./pack'));
const reader = require('./reader');
const read = require('./read');
const getValue = require('./get-value');

const connectionWraped = wraptile(connection);
Expand Down Expand Up @@ -68,7 +68,7 @@ function getOperation(name) {
return extract;

if (name === 'read')
return reader;
return read;

if (name === 'copy')
return operate('copy');
Expand Down
8 changes: 3 additions & 5 deletions server/reader.js → server/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,16 @@ async function readDirectory(id, socket, path) {

async function watchDirectory(id, socket, path) {
const watcher = watch(path, {
//persistent: false
persistent: false
});

watcher.on('all', async () => {
const [error] = await tryToCatch(readDirectory, id, socket, path);
const [error, info] = await tryToCatch(readDirectory, id, socket, path);

if (error)
return socket.emit(`${id}#error`, error.message);
});

watcher.on('error', (error) => {
socket.emit(`${id}#error`, error.message);
socket.emit(`${id}#directory`, info);
});
}

1 change: 1 addition & 0 deletions test/lib/clear.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = () => {
clear('../../server/operate');
clear('../../server/pack');
clear('../../server/extract');
clear('../../server/read');
clear('../../server/is-root-win32');
};

16 changes: 14 additions & 2 deletions test/server/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ test('operate: read: chokidar', async (t) => {

done();

t.ok(watch.calledWith(path));
const expected = [
path, {
persistent: false,
},
];

t.ok(watch.calledWith(...expected));
t.end();
});

Expand Down Expand Up @@ -135,7 +141,13 @@ test('operate: read change: directory', async (t) => {

done();

t.ok(watch.calledWith('/root'));
const expected = [
'/root', {
persistent: false,
},
];

t.ok(watch.calledWith(...expected));
t.end();
});

Expand Down

0 comments on commit d884109

Please sign in to comment.