-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtest.js
More file actions
145 lines (125 loc) · 4.47 KB
/
test.js
File metadata and controls
145 lines (125 loc) · 4.47 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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
'use strict';
require('mocha');
const isTravis = process.env.TRAVIS || process.env.CLI;
const os = require('os');
const assert = require('assert');
const path = require('path');
const parse = require('..');
const cwd = (...args) => path.resolve(__dirname, ...args);
const fixture = name => cwd('fixtures', name);
describe('parse-git-config', function() {
describe('async', function() {
it('should return a promise when callback is not passed', function(cb) {
parse({ path: fixture('_gitconfig') })
.then(config => {
assert(config.hasOwnProperty('core'));
cb();
})
.catch(cb);
});
it('should parse .git/config', function(cb) {
parse({ path: fixture('_gitconfig') }, function(err, config) {
assert(!err);
assert(config.hasOwnProperty('core'));
cb();
});
});
it('should expand keys in config', function(cb) {
parse({ path: fixture('_gitconfig'), expandKeys: true })
.then(config => {
assert(config.hasOwnProperty('color'));
assert(config.color.hasOwnProperty('diff'));
cb();
})
.catch(cb);
});
it('should not expand dots in keys in config', function(cb) {
parse({ path: fixture('_gitconfig-branch'), expandKeys: true })
.then(config => {
assert.deepEqual(Object.keys(config.branch), ['devel', 'master', '2.0']);
cb();
})
.catch(cb);
});
it('should include other config sources', function(cb) {
parse({ path: fixture('_gitconfig'), include: true }, function(err, config) {
assert(!err);
assert.deepEqual(config, require('./expected/_gitconfig.js'));
cb();
});
});
it('should throw an error when .git/config does not exist', function(cb) {
parse({ path: 'foo' }, function(err, config) {
assert(err instanceof Error);
assert(/ENOENT.*parse-git-config/.test(err.message));
cb();
});
});
});
describe('promise', function() {
it('should return a promise', function(cb) {
parse.promise({ path: fixture('_gitconfig') })
.then(config => {
assert(config.hasOwnProperty('core'));
cb();
});
});
it('should include other config sources', function() {
return parse.promise({ path: fixture('_gitconfig'), include: true })
.then(config => {
assert.deepEqual(config, require('./expected/_gitconfig.js'));
});
});
});
describe('sync', function() {
it('should return an object', function() {
assert(parse.sync({path: fixture('_gitconfig') }).hasOwnProperty('core'));
});
});
describe('.expandKeys', function() {
it('should expand ini-style keys', function() {
const config = {
'foo "bar"': { doStuff: true },
'foo "baz"': { doStuff: true }
};
assert.deepEqual(parse.expandKeys(config), {
foo: {
bar: { doStuff: true },
baz: { doStuff: true }
}
});
});
it('should prevent prototype pollution', function() {
const config = {};
const key = '__proto__ "polluted"';
config[key] = true;
parse.expandKeys(config);
assert.equal({}.polluted, undefined);
})
});
describe('resolve', function() {
it('should resolve the git config in the cwd by default', function() {
assert.equal(parse.resolve(), path.resolve(process.cwd(), '.git/config'));
});
it('should allow override path', function() {
const fp = path.resolve(os.homedir(), '.gitconfig');
assert.equal(parse.resolve({ path: fp }), fp);
});
it('should include other config sources', function() {
const fp = path.join(__dirname, 'fixtures/_gitconfig');
const actual = parse.sync({ path: fp, include: true });
assert.deepEqual(actual, require('./expected/_gitconfig.js'));
});
it('should resolve relative path to cwd', function() {
assert.equal(parse.resolve({ path: '.config' }), path.resolve(process.cwd(), '.config'));
});
it('should resolve relative path to the global git config when `global` is passed', function() {
if (isTravis && os.platform() === 'darwin') return this.skip();
assert.equal(parse.resolve('global'), path.resolve(os.homedir(), '.gitconfig'));
});
it('should allow override of cwd', function() {
const actual = parse.resolve({ path: '.config', cwd: '/opt/config' });
assert.equal(actual, path.resolve('/opt/config/.config'));
});
});
});