-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.test.js
More file actions
81 lines (66 loc) · 2.08 KB
/
index.test.js
File metadata and controls
81 lines (66 loc) · 2.08 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
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
"use strict";
// This should be require first, otherwise fs-promise does not use it.
const mock = require("mock-fs");
const { afterEach, beforeEach, describe, it } = require("test");
const assert = require("assert");
const homedir = require("os").homedir;
const loadConfig = require(".").load;
// ===================================================================
describe("appConf", function () {
beforeEach(function () {
mock({
// Vendor config
"../../config.json": '{ "vendor": true, "foo": "vendor" }',
// System
"/etc/test-app-conf/config.json": '{ "system": true, "foo": "system" }',
// Global (user configuration)
// TODO
// Local
"../.test-app-conf.json": '{ "local.1": true, "foo": "local.1" }',
".test-app-conf.json": '{ "local.0": true, "foo": "local.0" }',
// Special vendor file to test paths resolution.
"../../config.paths-resolution.json": mock.symlink({
path: "/etc/paths-resolution.json",
}),
"/etc/paths-resolution.json": JSON.stringify({
pathWithCurrent: "./foo",
pathWithHome: "~/bar",
pathWithParent: "../baz",
}),
});
});
afterEach(function () {
mock.restore();
});
describe("#load()", function () {
it("works", function () {
return loadConfig("test-app-conf", {
appDir: "../..",
}).then(function (config) {
assert.deepStrictEqual(config, {
"local.0": true,
"local.1": true,
system: true,
vendor: true,
foo: "local.0",
pathWithCurrent: "/etc/foo",
pathWithHome: homedir() + "/bar",
pathWithParent: "/baz",
});
});
});
it("can load only specific entries", function () {
return loadConfig("test-app-conf", {
entries: ["local", "system"],
}).then(function (config) {
assert.deepStrictEqual(config, {
"local.0": true,
"local.1": true,
system: true,
// merging order is still the same though
foo: "local.0",
});
});
});
});
});