Skip to content

Commit

Permalink
fix: update dependencies and replace tape with tap
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes J. Schmidt committed Feb 9, 2016
1 parent 4ec3603 commit ca2f9eb
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 57 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
.nyc_output
12 changes: 5 additions & 7 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

var configure = require('./')


var args = process.argv.slice(2);
var args = process.argv.slice(2)
if (!args.length) {
return console.log('Usage: \ncouchdb-configure URL [SOURCE]')
console.log('Usage: \ncouchdb-configure URL [SOURCE]')
process.exit()
}

var url = args[0];
var url = args[0]
var source = args[1] || process.cwd()



configure(url, source, function(error, response) {
configure(url, source, function (error, response) {
if (error) return console.error(error)

console.log(JSON.stringify(response, null, ' '))
Expand Down
20 changes: 12 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ var async = require('async')
var compile = require('couchdb-compile')
var assert = require('assert')

module.exports = function configure(url, source, callback) {
module.exports = function configure (url, source, callback) {
var couch = nanoOption(url)

assert(typeof couch.request === 'function',
'URL must point to the root of a CouchDB server (not to a database).')

compile(source, { index: true }, function(error, config) {
compile(source, { index: true }, function (error, config) {
if (error) {
return callback(error)
}

var settings = Object.keys(config)
.reduce(function(memo, key) {
.reduce(function (memo, key) {
if (typeof config[key] !== 'object') return memo

var section = Object.keys(config[key])
.map(function(k) {
.map(function (k) {
return {
path: encodeURIComponent(key) + '/' + encodeURIComponent(k),
value: config[key][k].toString()
Expand All @@ -25,12 +29,12 @@ module.exports = function configure(url, source, callback) {
return memo.concat(section)
}, [])

async.map(settings, function(setting, next) {
async.map(settings, function (setting, next) {
couch.request({
method: 'PUT',
path: '_config/' + setting.path,
body: setting.value
}, function(error, oldValue) {
}, function (error, oldValue) {
if (error) return next(error)

next(null, {
Expand All @@ -39,10 +43,10 @@ module.exports = function configure(url, source, callback) {
oldValue: oldValue
})
})
}, function(error, responses) {
}, function (error, responses) {
if (error) return callback(error)

var response = responses.reduce(function(memo, response) {
var response = responses.reduce(function (memo, response) {
memo[response.path] = {
ok: true,
value: response.value
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"main": "index.js",
"bin": "cli.js",
"scripts": {
"test": "tape test/index.js | tap-spec",
"test": "standard && tap --coverage test/index.js",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
"repository": {
Expand All @@ -28,8 +28,8 @@
},
"devDependencies": {
"nano": "^6.1.5",
"tap-spec": "^4.1.0",
"tape": "^4.2.1",
"semantic-release": "^6.0.3"
"semantic-release": "^6.0.3",
"standard": "^6.0.4",
"tap": "^5.4.3"
}
}
78 changes: 40 additions & 38 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@ var nano = require('nano')

var configure = require('../')


var url = process.env.COUCH || 'http://localhost:5984'
var couch = nano(url)


// There is an issue with section deletion in CouchDB.
// You cannot delete an entire section:
// $ curl -XDELETE http://localhost:5984/_config/couchdb-bootstrap
// {"error":"method_not_allowed","reason":"Only GET,PUT,DELETE allowed"}
function clear(callback) {
function clear (callback) {
couch.request({
path: '_config/couchdb-configure'
}, function(error, config) {
}, function (error, config) {
if (error) return callback(error)

async.map(Object.keys(config), function(key, next) {
async.map(Object.keys(config), function (key, next) {
couch.request({
method: 'DELETE',
path: '_config/couchdb-configure/' + encodeURIComponent(key)
Expand All @@ -29,88 +27,92 @@ function clear(callback) {
})
}

test('use url', function(t) {
configure(url, path.join(__dirname, 'fixtures', 'config.json'), function(error, responses) {
t.error(error, 'no error occured')
test('use url', function (t) {
configure(url, path.join(__dirname, 'fixtures', 'config.json'), function (error, responses) {
t.error(error)
t.end()
})
})

test('use url with trailing slash', function(t) {
configure(url + '/', path.join(__dirname, 'fixtures', 'config.json'), function(error, responses) {
t.error(error, 'no error occured')
test('use url with trailing slash', function (t) {
configure(url + '/', path.join(__dirname, 'fixtures', 'config.json'), function (error, responses) {
t.error(error)
t.end()
})
})

test('use nano object', function(t) {
configure(couch, path.join(__dirname, 'fixtures', 'config.json'), function(error, responses) {
t.error(error, 'no error occured')
test('use nano object', function (t) {
configure(couch, path.join(__dirname, 'fixtures', 'config.json'), function (error, responses) {
t.error(error)
t.end()
})
})

test('configure from json', function(t) {
clear(function(error) {
t.error(error, 'no error occured')
test('configure from json', function (t) {
clear(function (error) {
t.error(error)

configure(url, path.join(__dirname, 'fixtures', 'config.json'), function(error, responses) {
t.error(error, 'no error occured')
configure(url, path.join(__dirname, 'fixtures', 'config.json'), function (error, responses) {
t.error(error)

couch.request({
path: '_config/couchdb-configure/foo'
}, function(error, config) {
}, function (error, config) {
t.error(error)
t.equal(config, 'bar')
t.end()
})
})
})
})

test('configure from commonjs', function(t) {
clear(function(error) {
t.error(error, 'no error occured')
test('configure from commonjs', function (t) {
clear(function (error) {
t.error(error)

configure(url, path.join(__dirname, 'fixtures', 'config.js'), function(error, responses) {
t.error(error, 'no error occured')
configure(url, path.join(__dirname, 'fixtures', 'config.js'), function (error, responses) {
t.error(error)

couch.request({
path: '_config/couchdb-configure/baz'
}, function(error, config) {
}, function (error, config) {
t.error(error)
t.equal(config, 'foo')
t.end()
})
})
})
})

test('configure from commonjs/index', function(t) {
clear(function(error) {
t.error(error, 'no error occured')
test('configure from commonjs/index', function (t) {
clear(function (error) {
t.error(error)

configure(url, path.join(__dirname, 'fixtures', 'commonjs'), function(error, responses) {
t.error(error, 'no error occured')
configure(url, path.join(__dirname, 'fixtures', 'commonjs'), function (error, responses) {
t.error(error)

couch.request({
path: '_config/couchdb-configure/bar'
}, function(error, config) {
}, function (error, config) {
t.error(error)
t.equal(config, 'baz')
t.end()
})
})
})
})

test('configure from filesystem', function(t) {
clear(function(error) {
t.error(error, 'no error occured')
test('configure from filesystem', function (t) {
clear(function (error) {
t.error(error)

configure(url, path.join(__dirname, 'fixtures', 'config'), function(error, responses) {
t.error(error, 'no error occured')
configure(url, path.join(__dirname, 'fixtures', 'config'), function (error, responses) {
t.error(error)

couch.request({
path: '_config/couchdb-configure/foo'
}, function(error, config) {
}, function (error, config) {
t.error(error)
t.equal(config, 'bar')
t.end()
})
Expand Down

0 comments on commit ca2f9eb

Please sign in to comment.