-
Notifications
You must be signed in to change notification settings - Fork 0
/
list-files-sync.js
74 lines (57 loc) · 1.77 KB
/
list-files-sync.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const { d, expect, tquire, uuid } = deps;
const proxyquire = require('proxyquire').noPreserveCache().noCallThru();
const me = __filename;
d(me, () => {
// An array of objects with an arg: [] and returnValue: <object>|<array>|<primitive>|etc.
let reduceToTypesSyncReturnList = [];
let reduceToTypesSync = null;
let mocks = null;
let listFilesSync = null;
const initializeListFilesSync = () => {
mocks = {};
reduceToTypesSync = (inp) =>
reduceToTypesSyncReturnList.find(({ args }) => args === inp).returnValue;
mocks['./reduce-to-types-sync'] = reduceToTypesSync;
listFilesSync = proxyquire(tquire(me, false), mocks);
};
describe('given a single folder with files', () => {
const args = { directory: Symbol() };
const file = `${uuid()}.js`;
const files = [file];
const returnValue = {
directories: [],
files,
};
beforeEach(() => {
reduceToTypesSyncReturnList.push({
args: args.directory,
returnValue,
});
initializeListFilesSync();
});
it('should return the files', () =>
expect(listFilesSync(args)).to.deep.equal(files));
});
describe('given /bla, /bla2/bla with initial dir /', () => {
const args = { directory: '/' };
beforeEach(() => {
reduceToTypesSyncReturnList.push({
args: args.directory,
returnValue: {
directories: ['/bla2'],
files: ['/bla'],
},
});
reduceToTypesSyncReturnList.push({
args: '/bla2',
returnValue: {
directories: [],
files: ['/bla2/bla'],
},
});
initializeListFilesSync();
});
it('should return the full list of files', () =>
expect(listFilesSync(args)).to.deep.equal(['/bla', '/bla2/bla']));
});
});