-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper_config_file.test.js
61 lines (47 loc) · 1.23 KB
/
helper_config_file.test.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
#!/usr/bin/env node
const proxyquire = require('proxyquire');
const helper = require("./test/helper_test.js");
const test = helper.test(__filename);
test('read', function(t) {
t.plan(1);
var config_file = proxyquire("./helper_config_file.js", {
"fs": {
readFileSync: function(filename) {
return '{"hi": 5}';
},
}
});
t.deepEqual(config_file.read("config.json"),
{"hi": 5}, "config structure");
});
test('write', function(t) {
t.plan(2);
var config_file = proxyquire("./helper_config_file.js", {
"fs": {
writeFile: function(filename, content, callback) {
t.equal(filename, "config.json", "filename");
t.deepEqual(content, '{\n\t"hi": 7\n}\n', "content");
callback(null);
},
}
});
config_file.write("config.json", {"hi": 7});
});
test('read - not existing file', function(t) {
t.plan(1);
var config_file = proxyquire("./helper_config_file.js", {
"fs": {
readFileSync: function(filename) {
var e = new Error("Not existing");
e.code = "ENOENT";
throw e;
},
}
});
// do not show warn message
var console_warn = console.warn;
console.warn = function() {};
var c = config_file.read("notexisting");
console.warn = console_warn;
t.deepEqual(c, {}, "config structure");
});