-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest-new.js
123 lines (104 loc) · 3.09 KB
/
test-new.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
var testName = 'new';
var test = require('tape');
var path = require('path');
var config = require('../configure');
var parsers = require('../parsers');
var configDir = path.join(__dirname, 'fixtures/config/' + testName);
// custom parsers
var ini = require('ini');
var yaml = require('js-yaml');
var json5 = require('json5');
test('new', function(t)
{
var data;
t.plan(8);
// -- default instance
data = config({ directories: configDir });
t.deepEqual(data, {
fields: {
field_1: '1 from js',
field_2: '2 from json',
field_3: '3 from json'
}
}, 'expect to get js and json files combined');
data = config({ directories: configDir, parsers: {ini: ini.parse, json: null}});
t.deepEqual(data, {
fields: {
field_0: '0 from ini',
field_1: '1 from js',
field_2: '2 from js'
}
}, 'expect to get ini and js files combined');
// -- first level, no `js`
config = config.new({parsers: {js: null}});
data = config({ directories: configDir });
t.deepEqual(data, {
fields: {
field_2: '2 from json',
field_3: '3 from json'
}
}, 'expect to get just json file');
data = config({ directories: configDir, parsers: {ini: ini.parse}});
t.deepEqual(data, {
fields: {
field_0: '0 from ini',
field_1: '1 from ini',
field_2: '2 from json',
field_3: '3 from json'
}
}, 'expect to get ini and json files combined');
// -- second level, with `json5` and `yaml`
config = config.new({parsers: {
json5: json5.parse,
yaml : function(str) { return yaml.safeLoad(str); }
}});
data = config({ directories: configDir });
t.deepEqual(data, {
fields: {
field_2: '2 from json',
field_3: '3 from json5',
field_4: '4 from yaml',
field_5: '5 from yaml'
}
}, 'expect to get json, json5 and yaml files combined');
data = config({ directories: configDir, parsers: {ini: ini.parse}});
t.deepEqual(data, {
fields: {
field_0: '0 from ini',
field_1: '1 from ini',
field_2: '2 from json',
field_3: '3 from json5',
field_4: '4 from yaml',
field_5: '5 from yaml'
}
}, 'expect to get ini, json, json5 and yaml files combined');
// -- three levels deep, with `ini` and `yml`
config = config.new({parsers: {
ini: ini.parse,
yml: config.parsers.yaml
}});
data = config({ directories: configDir });
t.deepEqual(data, {
fields: {
field_0: '0 from ini',
field_1: '1 from ini',
field_2: '2 from json',
field_3: '3 from json5',
field_4: '4 from yaml',
field_5: '5 from yml',
field_6: '6 from yml'
}
}, 'expect to get ini, json, json5, yaml and yml files combined');
data = config({ directories: configDir, parsers: {js: parsers.js}});
t.deepEqual(data, {
fields: {
field_0: '0 from ini',
field_1: '1 from js',
field_2: '2 from json',
field_3: '3 from json5',
field_4: '4 from yaml',
field_5: '5 from yml',
field_6: '6 from yml'
}
}, 'expect to get ini, js, json, json5, yaml and yml files combined');
});