diff --git a/packages/storage-mixin/.travis.yml b/packages/storage-mixin/.travis.yml index a6bf723ffa5..49659261878 100644 --- a/packages/storage-mixin/.travis.yml +++ b/packages/storage-mixin/.travis.yml @@ -7,8 +7,8 @@ node_js: env: global: - NO_AT_BRIDGE=1 # Needed for dbus to work. - - CC=clang - - CXX=clang++ + - CC=clang + - CXX=clang++ - npm_config_clang=1 # matrix: @@ -31,7 +31,7 @@ before_script: eval $(/usr/bin/gnome-keyring-daemon --components=secrets --start); /usr/bin/python -c "import gnomekeyring;gnomekeyring.create_sync('login', '');"; script: - - npm run test:electron + - npm run ci # - if [ -n "$NODE" ]; then npm run test:node; fi # - if [ -n "$ELECTRON" ]; then npm run test:electron; fi @@ -41,7 +41,7 @@ addons: - ubuntu-toolchain-r-test packages: - libsecret-1-dev - # TODO (@imlucas) Are all of these gnome keyring + # TODO (@imlucas) Are all of these gnome keyring # packages really needed? - gnome-keyring - python-gnomekeyring diff --git a/packages/storage-mixin/lib/backends/errback.js b/packages/storage-mixin/lib/backends/errback.js index 6d59337d93f..1a290afbb11 100644 --- a/packages/storage-mixin/lib/backends/errback.js +++ b/packages/storage-mixin/lib/backends/errback.js @@ -1,3 +1,5 @@ +const debug = require('debug')('mongodb-storage-mixin:backends:errback'); + /** * Helper so you can just use errbacks `function(err, res)` * when calling ampersand sync methods instead of forgetting @@ -14,13 +16,13 @@ function wrapOptions(method, model, options) { if (options.error) { return options.error(res, err); } - console.error('An error ocurred with no handler specified!', err); + debug('An error ocurred with no handler specified!', err); throw err; } if (options.success) { return options.success(res); - } + } }; } diff --git a/packages/storage-mixin/lib/backends/secure-ipc.js b/packages/storage-mixin/lib/backends/secure-ipc.js index f5e551e00e2..07d6b98818f 100644 --- a/packages/storage-mixin/lib/backends/secure-ipc.js +++ b/packages/storage-mixin/lib/backends/secure-ipc.js @@ -97,7 +97,6 @@ if (typeof window !== 'undefined') { * @param {ampersand-model} model * @param {Object} options * @param {Function} done - * @return {None} * * @see http://ampersandjs.com/docs#ampersand-model-fetch */ @@ -139,7 +138,6 @@ if (typeof window !== 'undefined') { * @param {ampersand-collection} collection * @param {Object} options * @param {Function} done - * @return {None} * * @see http://ampersandjs.com/docs#ampersand-collection-fetch */ @@ -150,8 +148,8 @@ if (typeof window !== 'undefined') { if (result.namespace === this.namespace) { const attributes = collection.reduce((attrs, model) => { const modelId = model.getId(); - const credential = result.credentials.find((credential) => { - return credential.account === modelId; + const credential = result.credentials.find((iteratee) => { + return iteratee.account === modelId; }); const attr = {}; attr[model.idAttribute] = modelId; @@ -170,7 +168,7 @@ if (typeof window !== 'undefined') { ipc.on('storage-mixin:find:result', listener); ipc.call('storage-mixin:find', { - namespace: this.namespace, + namespace: this.namespace }); }; } diff --git a/packages/storage-mixin/lib/backends/secure-main.js b/packages/storage-mixin/lib/backends/secure-main.js index 3c07e9115b4..fe8ab053056 100644 --- a/packages/storage-mixin/lib/backends/secure-main.js +++ b/packages/storage-mixin/lib/backends/secure-main.js @@ -12,40 +12,43 @@ if (process && process.type === 'browser') { */ ipc.respondTo('storage-mixin:clear', (evt, meta) => { debug('Clearing all secure values for', meta.serviceName); + + let promise; try { - const promise = keytar.findCredentials(meta.serviceName); - } catch(e) { - console.error('Error calling findCredentials', e); + promise = keytar.findCredentials(meta.serviceName); + } catch (e) { + debug('Error calling findCredentials', e); throw e; } + promise.then(function(accounts) { return Promise.all( accounts.map(function(entry) { const accountName = entry.account; return keytar - .deletePassword(serviceName, accountName) + .deletePassword(meta.serviceName, accountName) .then(function() { debug('Deleted account %s successfully', accountName); return accountName; }) .catch(function(err) { - console.error('Failed to delete', accountName, err); + debug('Failed to delete', accountName, err); throw err; }); }) ); }) - .then(function(accountNames) { - debug( - 'Cleared %d accounts for serviceName %s', - accountNames.length, - meta.serviceName, - accountNames - ); - }) - .catch(function(err) { - console.error('Failed to clear credentials!', err); - }); + .then(function(accountNames) { + debug( + 'Cleared %d accounts for serviceName %s', + accountNames.length, + meta.serviceName, + accountNames + ); + }) + .catch(function(err) { + debug('Failed to clear credentials!', err); + }); }); /** @@ -84,7 +87,7 @@ if (process && process.type === 'browser') { }); }) .catch(function(err) { - debug('Error updating password', error); + debug('Error updating password', err); }); }); @@ -104,7 +107,7 @@ if (process && process.type === 'browser') { }); }) .catch(function(err) { - debug('Error creating password', error); + debug('Error creating password', err); }); }); @@ -124,7 +127,7 @@ if (process && process.type === 'browser') { }); }) .catch(function(err) { - debug('Error finding one', error); + debug('Error finding one', err); }); }); @@ -144,7 +147,7 @@ if (process && process.type === 'browser') { }); }) .catch(function(err) { - debug('Error finding', error); + debug('Error finding', err); }); }); } diff --git a/packages/storage-mixin/lib/backends/secure.js b/packages/storage-mixin/lib/backends/secure.js index c551db2c5d8..797c40bdb18 100644 --- a/packages/storage-mixin/lib/backends/secure.js +++ b/packages/storage-mixin/lib/backends/secure.js @@ -27,36 +27,39 @@ inherits(SecureBackend, BaseBackend); SecureBackend.clear = function(namespace, done) { var serviceName = `storage-mixin/${namespace}`; debug('Clearing all secure values for', serviceName); + + var promise; + try { - var promise = keytar.findCredentials(serviceName); - } catch(e) { - console.error('Error calling findCredentials', e); + promise = keytar.findCredentials(serviceName); + } catch (e) { + debug('Error calling findCredentials', e); throw e; } - - promise.then(function(accounts) { - debug( - 'Found credentials', - accounts.map(function(credential) { - return credential.account; - }) - ); - return Promise.all( - accounts.map(function(entry) { - var accountName = entry.account; - return keytar - .deletePassword(serviceName, accountName) - .then(function() { - debug('Deleted account %s successfully', accountName); - return accountName; - }) - .catch(function(err) { - console.error('Failed to delete', accountName, err); - throw err; - }); - }) - ); - }) + + promise.then(function(accounts) { + debug( + 'Found credentials', + accounts.map(function(credential) { + return credential.account; + }) + ); + return Promise.all( + accounts.map(function(entry) { + var accountName = entry.account; + return keytar + .deletePassword(serviceName, accountName) + .then(function() { + debug('Deleted account %s successfully', accountName); + return accountName; + }) + .catch(function(err) { + debug('Failed to delete', accountName, err); + throw err; + }); + }) + ); + }) .then(function(accountNames) { debug( 'Cleared %d accounts for serviceName %s', @@ -67,7 +70,7 @@ SecureBackend.clear = function(namespace, done) { done(); }) .catch(function(err) { - console.error('Failed to clear credentials!', err); + debug('Failed to clear credentials!', err); done(err); }); }; @@ -160,7 +163,6 @@ SecureBackend.prototype.create = function(model, options, done) { * @param {ampersand-model} model * @param {Object} options * @param {Function} done - * @return {None} * * @see http://ampersandjs.com/docs#ampersand-model-fetch */ @@ -203,7 +205,6 @@ SecureBackend.prototype.findOne = function(model, options, done) { * @param {ampersand-collection} collection * @param {Object} options * @param {Function} done - * @return {None} * * @see http://ampersandjs.com/docs#ampersand-collection-fetch */ @@ -214,8 +215,8 @@ SecureBackend.prototype.find = function(collection, options, done) { .then(function(credentials) { var attributes = collection.reduce(function(attrs, model) { var modelId = model.getId(); - var credential = credentials.find(function(credential) { - return credential.account === modelId; + var credential = credentials.find(function(iteratee) { + return iteratee.account === modelId; }); var attr = {}; attr[model.idAttribute] = modelId; @@ -226,7 +227,7 @@ SecureBackend.prototype.find = function(collection, options, done) { attrs.push(attr); return attrs; }, []); - return(done(null, attributes)); + return (done(null, attributes)); }) .catch(done); }; diff --git a/packages/storage-mixin/lib/backends/splice-disk-ipc.js b/packages/storage-mixin/lib/backends/splice-disk-ipc.js index ecf414cb94a..23f0983a35d 100644 --- a/packages/storage-mixin/lib/backends/splice-disk-ipc.js +++ b/packages/storage-mixin/lib/backends/splice-disk-ipc.js @@ -8,7 +8,6 @@ var wrapOptions = require('./errback').wrapOptions; var wrapErrback = require('./errback').wrapErrback; var mergeSpliceResults = require('./util').mergeSpliceResults; var inherits = require('util').inherits; -var assert = require('assert'); var debug = require('debug')('mongodb-storage-mixin:backends:splice-disk'); @@ -83,7 +82,7 @@ SpliceDiskIpcBackend.prototype.exec = function(method, model, options, done) { if (!_.isEmpty(diskRes)) { mergeSpliceResults(diskRes, res, model, cb); } else { - cb(null, model.isCollection ? []: {}); + return cb(null, model.isCollection ? [] : {}); } }) ); diff --git a/packages/storage-mixin/lib/backends/splice.js b/packages/storage-mixin/lib/backends/splice.js index 70ce292f795..b37eab91b6f 100644 --- a/packages/storage-mixin/lib/backends/splice.js +++ b/packages/storage-mixin/lib/backends/splice.js @@ -8,7 +8,6 @@ var wrapOptions = require('./errback').wrapOptions; var wrapErrback = require('./errback').wrapErrback; var mergeSpliceResults = require('./util').mergeSpliceResults; var inherits = require('util').inherits; -var assert = require('assert'); var debug = require('debug')('mongodb-storage-mixin:backends:splice'); @@ -82,7 +81,7 @@ SpliceBackend.prototype.exec = function(method, model, options, done) { if (!_.isEmpty(localRes)) { mergeSpliceResults(localRes, res, model, cb); } else { - cb(null, model.isCollection ? []: {}); + return cb(null, model.isCollection ? [] : {}); } }) ); diff --git a/packages/storage-mixin/lib/backends/util.js b/packages/storage-mixin/lib/backends/util.js index eb5a2dd79fe..daade645de3 100644 --- a/packages/storage-mixin/lib/backends/util.js +++ b/packages/storage-mixin/lib/backends/util.js @@ -7,6 +7,8 @@ var _ = require('lodash'); * @param {Array} secureResults - The results from secure storage. * @param {Model} model - The model. * @param {Function} done - The done callback. + * + * @returns {Object} the return value of done callback. */ var mergeSpliceResults = function(nonSecureResults, secureResults, model, done) { if (model.isCollection) { @@ -20,6 +22,6 @@ var mergeSpliceResults = function(nonSecureResults, secureResults, model, done) return done(null, merged); } done(null, _.merge(nonSecureResults, secureResults)); -} +}; module.exports.mergeSpliceResults = mergeSpliceResults; diff --git a/packages/storage-mixin/lib/index.js b/packages/storage-mixin/lib/index.js index 5a577d7191b..6d52467be6c 100644 --- a/packages/storage-mixin/lib/index.js +++ b/packages/storage-mixin/lib/index.js @@ -1,5 +1,5 @@ var backends = require('./backends'); -// var debug = require('debug')('storage-mixin'); +var debug = require('debug')('storage-mixin'); /** * storage-mixin @@ -38,7 +38,7 @@ module.exports = { }; options.error = function(resp, err) { - console.error('WTF', {err: err, resp: resp}); + debug('WTF', {err: err, resp: resp}); }; this.fetched = false; this._storageBackend.exec(method, model, options); diff --git a/packages/storage-mixin/package.json b/packages/storage-mixin/package.json index 711d2b201ce..cc36f7e8184 100644 --- a/packages/storage-mixin/package.json +++ b/packages/storage-mixin/package.json @@ -32,6 +32,7 @@ "pretest:node": "node-gyp rebuild --directory node_modules/keytar/ --verbose", "test:node": "mocha", "check": "mongodb-js-precommit", + "ci": "npm run check && npm run test", "test": "npm run test:node && npm run test:electron" }, "dependencies": { @@ -53,6 +54,7 @@ "electron-mocha": "^6.0.4", "electron-rebuild": "^1.8.2", "eslint-config-mongodb-js": "^3.0.1", - "mocha": "^5.2.0" + "mocha": "^5.2.0", + "mongodb-js-precommit": "^2.0.0" } } diff --git a/packages/storage-mixin/test/helpers.js b/packages/storage-mixin/test/helpers.js index 4ca1ab6a230..9b52aef2d01 100644 --- a/packages/storage-mixin/test/helpers.js +++ b/packages/storage-mixin/test/helpers.js @@ -20,7 +20,7 @@ var clearNamespaces = function(backendName, namespaces, done) { }); async.parallel(tasks, function(err, res) { if (err) { - console.error('Error clearing namespaces', err); + debug('Error clearing namespaces', err); return done(err); } debug('Namespaces cleared for backend %s', backendName); diff --git a/packages/storage-mixin/test/util.test.js b/packages/storage-mixin/test/util.test.js index 459585b7afb..d80488ce68a 100644 --- a/packages/storage-mixin/test/util.test.js +++ b/packages/storage-mixin/test/util.test.js @@ -25,7 +25,7 @@ describe('util', function() { ] ); done(); - }) + }); }); }); @@ -42,7 +42,7 @@ describe('util', function() { { name: 'Aphex Twin', password: 'pw' } ); done(); - }) + }); }); }); });