Skip to content

Commit 556796d

Browse files
committed
test(fileop) server: copy: improve coverage
1 parent 765fc06 commit 556796d

File tree

4 files changed

+70
-2
lines changed

4 files changed

+70
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
.nyc_output
12
yarn-error.log
23
yarn.lock
34
package-lock.json
45
node_modules
56
npm-debug.log
6-
.nyc_output
7+
coverage
78

89
dist
910
dist-dev

.nycrc.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"check-coverage": true,
3+
"all": true,
4+
"exclude": [
5+
"**/dist**",
6+
"**/*.spec.js",
7+
"**/fixture",
8+
"test",
9+
".*.{js,mjs}",
10+
"webpack**",
11+
"coverage"
12+
],
13+
"branches": 100,
14+
"lines": 100,
15+
"functions": 100,
16+
"statements": 100
17+
}

test/lib/emitters.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const {EventEmitter} = require('events');
4+
const wraptile = require('wraptile');
45

56
module.exports.rawErrorEmitter = (from) => {
67
const emitter = new EventEmitter();
@@ -66,3 +67,16 @@ module.exports.endEmitter = () => {
6667

6768
return emitter;
6869
};
70+
71+
module.exports.customEmitter = wraptile((fns) => {
72+
const emitter = new EventEmitter();
73+
74+
emitter.pause = fns.pause;
75+
emitter.continue = fns.continue;
76+
77+
process.nextTick(() => {
78+
emitter.emit('end');
79+
});
80+
81+
return emitter;
82+
});

test/server/copy.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const {once} = require('events');
44

5-
const test = require('supertape');
5+
const {test, stub} = require('supertape');
66
const mock = require('mock-require');
77
const clear = require('clear-module');
88

@@ -11,6 +11,7 @@ const {
1111
errorEmitter,
1212
progressEmitter,
1313
fileEmitter,
14+
customEmitter,
1415
} = require('../lib/emitters');
1516

1617
const clearFileop = require('../lib/clear');
@@ -176,6 +177,41 @@ test('operate: copy: continue', async (t) => {
176177
t.end();
177178
});
178179

180+
test('operate: copy: pause', async (t) => {
181+
clearFileop();
182+
clear(copyPath);
183+
184+
const from = '/';
185+
const to = '/world';
186+
const names = ['abc'];
187+
188+
const pause = stub();
189+
mock(copyPath, customEmitter({
190+
pause,
191+
continue: stub(),
192+
}));
193+
194+
const connect = require(connectPath);
195+
196+
const {
197+
socket,
198+
done,
199+
} = await connect();
200+
201+
socket.emit('operation', 'copy', from, to, names);
202+
203+
const [id] = await once(socket, 'id');
204+
socket.emit(`${id}#start`);
205+
socket.emit(`${id}#pause`);
206+
socket.emit(`${id}#continue`);
207+
await once(socket, `${id}#end`);
208+
209+
done();
210+
211+
t.calledWithNoArgs(pause);
212+
t.end();
213+
});
214+
179215
test('operate: copy: error: root', async (t) => {
180216
clearFileop();
181217
clear(isRootPath);

0 commit comments

Comments
 (0)