You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
3.0 KiB
JavaScript
109 lines
3.0 KiB
JavaScript
10 years ago
|
/*!
|
||
|
* parse-git-config <https://github.com/jonschlinkert/parse-git-config>
|
||
|
*
|
||
7 years ago
|
* Copyright (c) 2015-2018 Jon Schlinkert.
|
||
10 years ago
|
* Licensed under the MIT license.
|
||
|
*/
|
||
|
|
||
|
'use strict';
|
||
|
|
||
9 years ago
|
require('mocha');
|
||
8 years ago
|
var isTravis = process.env.TRAVIS || process.env.CLI;
|
||
7 years ago
|
var fs = require('fs');
|
||
8 years ago
|
var os = require('os');
|
||
9 years ago
|
var assert = require('assert');
|
||
|
var path = require('path');
|
||
8 years ago
|
var homedir = require('homedir-polyfill');
|
||
7 years ago
|
var parse = require('..');
|
||
|
|
||
|
function read(filepath) {
|
||
|
return fs.readFileSync(path.join(__dirname, filepath), 'utf8');
|
||
|
}
|
||
10 years ago
|
|
||
9 years ago
|
describe('sync:', function() {
|
||
|
it('should return an object', function() {
|
||
9 years ago
|
assert(parse.sync().hasOwnProperty('core'));
|
||
10 years ago
|
});
|
||
|
});
|
||
|
|
||
9 years ago
|
describe('async:', function() {
|
||
7 years ago
|
it('should throw a callback is not passed:', function() {
|
||
|
assert.throws(function() {
|
||
9 years ago
|
parse();
|
||
7 years ago
|
}, /expected/);
|
||
10 years ago
|
});
|
||
|
|
||
9 years ago
|
it('should parse .git/config', function(cb) {
|
||
9 years ago
|
parse(function(err, config) {
|
||
9 years ago
|
assert(!err);
|
||
|
assert(config.hasOwnProperty('core'));
|
||
10 years ago
|
cb();
|
||
10 years ago
|
});
|
||
|
});
|
||
|
|
||
7 years ago
|
it('should include other config sources', function() {
|
||
|
var fp = path.join(__dirname, 'fixtures/_gitconfig');
|
||
|
|
||
|
parse({ path: fp, include: true }, function(err, config) {
|
||
|
assert(!err);
|
||
|
assert.deepEqual(config, require('./expected/_gitconfig.js'));
|
||
|
cb();
|
||
|
});
|
||
|
});
|
||
|
|
||
9 years ago
|
it('should throw an error when .git/config does not exist:', function(cb) {
|
||
7 years ago
|
parse({ path: 'foo' }, function(err, config) {
|
||
9 years ago
|
assert(err instanceof Error);
|
||
|
assert(/ENOENT.*parse-git-config/.test(err.message));
|
||
10 years ago
|
cb();
|
||
10 years ago
|
});
|
||
|
});
|
||
|
});
|
||
10 years ago
|
|
||
9 years ago
|
describe('resolve:', function() {
|
||
|
it('should resolve the git config in the cwd by default', function() {
|
||
9 years ago
|
assert.equal(parse.resolve(), path.resolve(process.cwd(), '.git/config'));
|
||
9 years ago
|
});
|
||
9 years ago
|
|
||
9 years ago
|
it('should allow override path', function() {
|
||
8 years ago
|
var fp = path.resolve(homedir(), '.gitconfig');
|
||
7 years ago
|
assert.equal(parse.resolve({ path: fp }), fp);
|
||
|
});
|
||
|
|
||
|
it('should include other config sources', function() {
|
||
|
var fp = path.join(__dirname, 'fixtures/_gitconfig');
|
||
|
var actual = parse.sync({ path: fp, include: true });
|
||
|
assert.deepEqual(actual, require('./expected/_gitconfig.js'));
|
||
9 years ago
|
});
|
||
9 years ago
|
|
||
9 years ago
|
it('should resolve relative path to cwd', function() {
|
||
7 years ago
|
assert.equal(parse.resolve({ path: '.config' }), path.resolve(process.cwd(), '.config'));
|
||
9 years ago
|
});
|
||
9 years ago
|
|
||
9 years ago
|
it('should resolve relative path to the global git config when `global` is passed', function() {
|
||
8 years ago
|
if (isTravis && os.platform() === 'darwin') return this.skip();
|
||
8 years ago
|
assert.equal(parse.resolve('global'), path.resolve(homedir(), '.gitconfig'));
|
||
9 years ago
|
});
|
||
|
|
||
9 years ago
|
it('should allow override of cwd', function() {
|
||
7 years ago
|
var actual = parse.resolve({ path: '.config', cwd: '/opt/config' });
|
||
9 years ago
|
assert.equal(actual, path.resolve('/opt/config/.config'));
|
||
9 years ago
|
});
|
||
|
});
|
||
|
|
||
|
describe('.keys:', function() {
|
||
|
it('should parse ini-style keys', function() {
|
||
|
var config = {
|
||
|
'foo "bar"': { doStuff: true },
|
||
|
'foo "baz"': { doStuff: true }
|
||
|
};
|
||
|
|
||
9 years ago
|
assert.deepEqual(parse.keys(config), {
|
||
9 years ago
|
foo: {
|
||
|
bar: { doStuff: true },
|
||
|
baz: { doStuff: true }
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
});
|