forked from Netcentric/fe-build
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextendConfig.test.js
More file actions
44 lines (39 loc) · 1.77 KB
/
Copy pathextendConfig.test.js
File metadata and controls
44 lines (39 loc) · 1.77 KB
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
process.argv.push('--quiet');
const json = require('./../test/.febuild');
const minimal = require('./../test/src/minimal/.febuild');
const config = require('../config');
const extendConfig = require('./extendConfig');
const finalValues = json(config);
describe('Test utils/extendConfig.js', () => {
it('Should throw an error no .febuild file is found ', () => {
expect(() => extendConfig('.febuild', config)).toThrowError();
});
it('Should find a .febuild file, read and merge into defaults values', () => {
const newConfig = extendConfig('./test/.febuild', config);
const reducer = (o,f) => {
return Object.keys(o).reduce((v,k) => {
if (typeof o[k] === 'function') return v && true;
if (typeof o[k] !== 'object' || Array.isArray(o[k])) return v && JSON.stringify(f[k]) === JSON.stringify(o[k]);
return v && reducer(o[k],f[k]);
}, true);
}
const test = reducer(finalValues, newConfig);
expect(test).toBe(true);
});
it('should work even if no destination path or source paths are configured', () => {
delete config.general.destinationPath;
delete config.general.sourcesPath;
const newConfig = extendConfig('./test/src/minimal/.febuild', config);
const reducer = (o,f) => {
return Object.keys(o).reduce((v,k) => {
if (typeof o[k] === 'function') return v && true;
if (typeof o[k] !== 'object' || Array.isArray(o[k])) {
return v && JSON.stringify(f[k]) === JSON.stringify(o[k]);
}
return v && reducer(o[k],f[k]);
}, true);
}
const test = reducer(minimal, newConfig);
expect(test).toBe(true);
});
});