Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
fix(tests): mock outstanding error logs in test suite r=@vladikoff
Browse files Browse the repository at this point in the history
Fixes #334 Mock outstanding error logs in test suite.
Also handles mozlog deprecation warning.
  • Loading branch information
deeptibaghel authored and vladikoff committed Apr 11, 2018
1 parent cb11145 commit 6a5d3ce
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
5 changes: 1 addition & 4 deletions lib/logging/index.js
Expand Up @@ -2,12 +2,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

const mozlog = require('mozlog');

const config = require('../config').get('logging');

mozlog.config(config);

const mozlog = require('mozlog')(config);

var root = mozlog(config.app);
if (root.isEnabledFor('debug')) {
Expand Down
13 changes: 13 additions & 0 deletions test/db/index.js
Expand Up @@ -13,6 +13,7 @@ const db = require('../../lib/db');
const config = require('../../lib/config');
const auth = require('../../lib/auth');
const Promise = require('bluebird');
const mock = require('../lib/mocks');

/*global describe,it,before*/

Expand Down Expand Up @@ -656,6 +657,10 @@ describe('db', function() {
});

it('should throw on empty email', function() {
mock.log('db', rec => {
return rec.levelname === 'ERROR'
&& rec.args[0] === 'getDeveloper';
});
return db.getDeveloper()
.done(
assert.fail,
Expand All @@ -678,6 +683,10 @@ describe('db', function() {
});

it('should not allow duplicates', function() {
mock.log('db', rec => {
return rec.levelname === 'ERROR'
&& rec.args[0] === 'activateDeveloper';
});
var email = 'email' + randomString(10) + '@mozilla.com';

return db.activateDeveloper(email)
Expand All @@ -695,6 +704,10 @@ describe('db', function() {
});

it('should throw on empty email', function() {
mock.log('db', rec => {
return rec.levelname === 'ERROR'
&& rec.args[0] === 'activateDeveloper';
});
return db.activateDeveloper()
.done(
assert.fail,
Expand Down
18 changes: 17 additions & 1 deletion test/lib/mocks.js
Expand Up @@ -5,7 +5,8 @@
const path = require('path');

module.exports = {
require: requireDependencies
require: requireDependencies,
log: mockLog
};

// `mocks.require`
Expand Down Expand Up @@ -52,3 +53,18 @@ function requireDependency(dependency, modulePath, basePath) {
return require(localPath);
}

function mockLog(logger, cb) {
var root = require('../../lib/logging')();
var log = require('../../lib/logging')(logger);
var filter = {
filter: function(record) {
if (cb(record)) {
log.removeFilter(filter);
log.setLevel(root.getEffectiveLevel());
return false;
}
return true;
}
};
log.addFilter(filter);
}

0 comments on commit 6a5d3ce

Please sign in to comment.