This is an automated email from the ASF dual-hosted git repository. glynnbird pushed a commit to branch standard in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git
commit 5b982e8e1b579273bcce9a8db01944c0419d147b Merge: 0c8764b 28acda4 Author: Glynn Bird <[email protected]> AuthorDate: Wed Aug 15 14:03:59 2018 +0100 merged master package.json | 3 -- tests/helpers/harness.js | 70 ++++++++++++++++++++++++++++++++++++++++++++ tests/helpers/integration.js | 9 +++--- tests/unit/document/get.js | 6 ++-- 4 files changed, 77 insertions(+), 11 deletions(-) diff --cc package.json index f2d9cd8,7981af2..1473fad --- a/package.json +++ b/package.json @@@ -28,16 -28,17 +28,13 @@@ "async": "^2.1.2", "tape": "^4.6.2", "istanbul": "^0.4.5", - "nock": "^9.0.0", - "endswith": "^0.0.0", - "tape-it": "^0.3.1", - "jshint": "^2.9.4", - "jscs": "^3.0.7", - "nock": "^9.0.0" + "standard": "^11.0.1" }, "scripts": { - "test": "bash scripts/run_couchdb_on_travis.sh; npm run mocha; bash scripts/stop_couchdb_on_travis.sh", - "mocha": "DEBUG=* NOCK_OFF=true istanbul cover tape tests/*/*/*.js", + "test": "standard; bash scripts/run_couchdb_on_travis.sh; npm run mocha; bash scripts/stop_couchdb_on_travis.sh", + "mocha": "NOCK_OFF=true istanbul cover tape tests/*/*/*.js", "unmocked": "NOCK_OFF=true tape tests/*/*/*.js", "mocked": "tape tests/*/*/*.js", - "jshint": "jshint tests/*/*/*.js lib/*.js", - "codestyle": "jscs -p google tests/*/*/*.js lib/*.js", "coverage": "open coverage/lcov-report/index.html", "checkcoverage": "istanbul check-coverage --statements 100 --functions 100 --lines 100 --branches 100" }, diff --cc tests/helpers/harness.js index 0000000,4f04f6b..1e7e127 mode 000000,100644..100644 --- a/tests/helpers/harness.js +++ b/tests/helpers/harness.js @@@ -1,0 -1,72 +1,70 @@@ -'use strict'; ++'use strict' + -var test = require('tape'); ++var test = require('tape') + -var nextTick = typeof setImmediate !== 'undefined' ? - setImmediate : process.nextTick; ++var nextTick = typeof setImmediate !== 'undefined' ++ ? setImmediate : process.nextTick + -function noop(){} ++function noop () {} + + module.exports = function (opts) { - var invoked = false; - var id = opts.id; - var testPrefix = id || ''; ++ var invoked = false ++ var id = opts.id ++ var testPrefix = id || '' + - var harness = {}; ++ var harness = {} + - harness.tests = []; - harness.checkLeaks = typeof opts.checkLeaks === 'boolean' ? - opts.checkLeaks : true; - harness.globalCount = Object.keys(global).length; ++ harness.tests = [] ++ harness.checkLeaks = typeof opts.checkLeaks === 'boolean' ++ ? opts.checkLeaks : true ++ harness.globalCount = Object.keys(global).length + - harness.timeout = +(opts.timeout || 200); - harness.locals = opts.locals || {}; ++ harness.timeout = +(opts.timeout || 200) ++ harness.locals = opts.locals || {} + + // + // locals must be available here + // - harness.setup = opts.setup || noop; - harness.teardown = opts.teardown || noop; ++ harness.setup = opts.setup || noop ++ harness.teardown = opts.teardown || noop + - function runTest(name, next, onEnd) { ++ function runTest (name, next, onEnd) { + test(testPrefix + '\n## ' + name, function (assert) { - - nextTick(function() { next.call(harness.locals, assert) }); ++ nextTick(function () { next.call(harness.locals, assert) }) + + var tmout = setTimeout(function () { - assert.fail('timed out'); - assert.end(); - }, harness.timeout); ++ assert.fail('timed out') ++ assert.end() ++ }, harness.timeout) + + assert.on('end', function () { - if(onEnd) { - onEnd(assert); ++ if (onEnd) { ++ onEnd(assert) + } - clearTimeout(tmout); - }); - }); ++ clearTimeout(tmout) ++ }) ++ }) + } + + harness.it = function (name, next) { - harness.tests.push({name: name, next: next}); ++ harness.tests.push({name: name, next: next}) + if (!invoked) { - invoked = true; - nextTick(function() { - runTest('setup', harness.setup); - harness.tests.forEach(function(elem) { - runTest(elem.name, elem.next); - }); ++ invoked = true ++ nextTick(function () { ++ runTest('setup', harness.setup) ++ harness.tests.forEach(function (elem) { ++ runTest(elem.name, elem.next) ++ }) + runTest('teardown', harness.teardown, function (assert) { + if (harness.checkLeaks) { + assert.deepEqual(Object.keys(global) + .splice(harness.globalCount, Number.MAX_VALUE), - [], 'No leaks'); ++ [], 'No leaks') + } - }); - }); ++ }) ++ }) + } - }; - - return harness; ++ } + -}; ++ return harness ++} diff --cc tests/helpers/integration.js index 7fc4999,6f4a1a5..82d086b --- a/tests/helpers/integration.js +++ b/tests/helpers/integration.js @@@ -7,57 -7,56 +7,56 @@@ // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the --// License for the specific language governing permissions and limitations under ++// License for the specific end governing permissions and limitations under // the License. -'use strict'; - -const async = require('async'); -const debug = require('debug'); -const path = require('path'); -const harness = require('./harness'); -const cfg = require('../fixtures/cfg'); -const nano = require('../../lib/nano'); -const helpers = require('./'); - -helpers.setup = function() { - const self = this; - const args = Array.prototype.slice.call(arguments); - - return function(assert) { - args.push(function(err) { - assert.equal(err, null, 'create database'); - assert.end(); - }); - - self.nano.db.create.apply(this, args); - }; -}; - -helpers.teardown = function() { - const self = this; - const args = Array.prototype.slice.call(arguments); - - return function(assert) { - args.push(function(err) { - assert.equal(err, null, 'destroy database'); - assert.ok(self.mock.isDone(), 'mocks didn\'t run'); - assert.end(); - }); - - self.nano.db.destroy.apply(this, args); - }; -}; - -helpers.harness = function(name, setup, teardown) { - const parent = name || module.parent.filename; - const fileName = path.basename(parent).split('.')[0]; +'use strict' + +const async = require('async') +const debug = require('debug') +const path = require('path') - const harness = require('tape-it') - const endsWith = require('endswith') ++const harness = require('./harness') +const cfg = require('../fixtures/cfg') +const nano = require('../../lib/nano') +const helpers = require('./') + +helpers.setup = function () { + const self = this + const args = Array.prototype.slice.call(arguments) + + return function (assert) { + args.push(function (err) { + assert.equal(err, null, 'create database') + assert.end() + }) + + self.nano.db.create.apply(this, args) + } +} + +helpers.teardown = function () { + const self = this + const args = Array.prototype.slice.call(arguments) + + return function (assert) { + args.push(function (err) { + assert.equal(err, null, 'destroy database') + assert.ok(self.mock.isDone(), 'mocks didn\'t run') + assert.end() + }) + + self.nano.db.destroy.apply(this, args) + } +} + +helpers.harness = function (name, setup, teardown) { + const parent = name || module.parent.filename + const fileName = path.basename(parent).split('.')[0] const parentDir = path.dirname(parent) - .split(path.sep).reverse()[0]; - const shortPath = path.join(parentDir, fileName); - const log = debug(path.join('nano', 'tests', 'integration', shortPath)); - const dbName = shortPath.replace('/', '_'); + .split(path.sep).reverse()[0] + const shortPath = path.join(parentDir, fileName) + const log = debug(path.join('nano', 'tests', 'integration', shortPath)) + const dbName = shortPath.replace('/', '_') const nanoLog = nano({ url: cfg.couch, log: log @@@ -76,45 -75,45 +75,45 @@@ timeout: helpers.timeout, checkLeaks: !!process.env.LEAKS, locals: locals, - setup: setup ? setup : helpers.setup.call(locals, dbName), - teardown: teardown ? teardown : helpers.teardown.call(locals, dbName) - }); -}; - -helpers.nock = function helpersNock(url, fixture, log) { - const nock = require('nock'); - const nockDefs = require('../fixtures/' + fixture + '.json'); - - nockDefs.forEach(function(n) { - let headers = n.headers || {}; - const response = n.buffer ? n.buffer.endsWith('.png') ? - helpers.loadFixture(n.buffer) : new Buffer(n.buffer, 'base64') : - n.response || ''; - const body = n.base64 ? new Buffer(n.base64, 'base64').toString() : - n.body || ''; + setup: setup || helpers.setup.call(locals, dbName), + teardown: teardown || helpers.teardown.call(locals, dbName) + }) +} + +helpers.nock = function helpersNock (url, fixture, log) { + const nock = require('nock') + const nockDefs = require('../fixtures/' + fixture + '.json') + + nockDefs.forEach(function (n) { + let headers = n.headers || {} - const response = n.buffer ? endsWith(n.buffer, '.png') ++ const response = n.buffer ? n.buffer.endsWith('.png') + ? helpers.loadFixture(n.buffer) : Buffer.from(n.buffer, 'base64') + : n.response || '' + const body = n.base64 ? Buffer.from(n.base64, 'base64').toString() + : n.body || '' - if (typeof headers === 'string' && endsWith(headers, '.json')) { + if (typeof headers === 'string' && headers.endsWith('.json')) { - headers = require(path.join(fixture, headers)); + headers = require(path.join(fixture, headers)) } - n.method = n.method || 'get'; - n.options = {log: log}; - n.scope = url; - n.headers = headers; - n.response = response; - n.body = body; + n.method = n.method || 'get' + n.options = {log: log} + n.scope = url + n.headers = headers + n.response = response + n.body = body - return n; - }); + return n + }) - nock.define(nockDefs); + nock.define(nockDefs) - return nock(url); -}; + return nock(url) +} -helpers.prepareAView = function(assert, search, db) { - search = search || ''; - db = db || this.db; +helpers.prepareAView = function (assert, search, db) { + search = search || '' + db = db || this.db db.insert({ views: { diff --cc tests/unit/document/get.js index 8f93a24,cccb5bf..e02c52b --- a/tests/unit/document/get.js +++ b/tests/unit/document/get.js @@@ -10,32 -10,32 +10,32 @@@ // License for the specific language governing permissions and limitations under // the License. -'use strict'; +'use strict' -const helpers = require('../../helpers/unit'); -const test = require('tape'); -const debug = require('debug')('nano/tests/unit/shared/error'); +const helpers = require('../../helpers/unit') +const test = require('tape') +const debug = require('debug')('nano/tests/unit/shared/error') -const cli = helpers.mockClientDb(debug); -const db = cli.use('foo'); +const cli = helpers.mockClientDb(debug) +const db = cli.use('foo') -test('it should not return db info if docName undefined', function(assert) { - db.get(undefined, function(err) { - assert.equal(err, 'Invalid doc id'); - assert.end(); - }); -}); +test('it should not return db info if docName undefined', function (assert) { + db.get(undefined, function (err) { - assert.equal(err, 'Invalid doc id') ++ assert.equal(err.toString(), 'Invalid doc id') + assert.end() + }) +}) -test('it should not return db info if docName null', function(assert) { - db.get(null, function(err) { - assert.equal(err, 'Invalid doc id'); - assert.end(); - }); -}); +test('it should not return db info if docName null', function (assert) { + db.get(null, function (err) { - assert.equal(err, 'Invalid doc id') ++ assert.equal(err.toString(), 'Invalid doc id') + assert.end() + }) +}) -test('it should not return db info if docName empty string', function(assert) { - db.get('', function(err) { - assert.equal(err, 'Invalid doc id'); - assert.end(); - }); -}); +test('it should not return db info if docName empty string', function (assert) { + db.get('', function (err) { - assert.equal(err, 'Invalid doc id') ++ assert.equal(err.toString(), 'Invalid doc id') + assert.end() + }) +})
