Skip to content

Commit

Permalink
Update deps and fixup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Nason committed Jan 19, 2017
1 parent e9615ee commit 98cdea5
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 86 deletions.
31 changes: 16 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
"test:ci": "npm run test:browser && npm run test:node:ci",
"test:browser": "NODE_ENV=test karma start test/karma.conf.js",
"test:browser:tdd": "npm run test:browser -- --auto-watch --no-single-run",
"test:node": "NODE_ENV=test nyc mocha test/runner test/specs/common/**/*.js",
"test:node": "NODE_ENV=test nyc mocha test/runner test/specs/*.spec.js test/specs/**/*.spec.js",
"test:node:tdd": "npm run test:node -- --cache --watch",
"test:node:ci": "npm run test:node && nyc report --reporter=text-lcov | coveralls",
"test:leakage": "NODE_ENV=test mocha test/runner test/specs/leakage/**/*.js",
"test:leakage": "NODE_ENV=test mocha test/runner test/leakage/check.js",
"test:bundle:tdd": "npm-run-all -l --parallel 'bundle:* -- --watch'",
"lint": "eslint --format ./node_modules/eslint-friendly-formatter --cache src test",
"clean": "rimraf dist && mkdirp dist",
Expand Down Expand Up @@ -69,13 +69,13 @@
"bunyan"
],
"dependencies": {
"bunyan": "^1.8.2",
"bunyan": "^1.8.5",
"bunyan-format": "^0.2.1",
"hide-secrets": "1.1.0",
"le_js": "git://github.com/nason/le_js.git#7a75be7c1dd2438e3f1183a68bd2162b80bc94d8",
"le_node": "^1.6.7",
"lodash": "^4.17.1",
"rollbar": "^0.6.2",
"le_node": "^1.7.0",
"lodash": "^4.17.4",
"rollbar": "^0.6.3",
"uuid": "3.0.1"
},
"devDependencies": {
Expand All @@ -91,37 +91,38 @@
"benchmark": "2.1.3",
"chai": "3.5.0",
"coveralls": "2.11.15",
"documentation": "4.0.0-beta11",
"eslint": "3.12.2",
"documentation": "4.0.0-beta.18",
"eslint": "3.13.1",
"eslint-friendly-formatter": "2.0.7",
"eslint-plugin-import": "2.2.0",
"eslint-plugin-mocha": "4.8.0",
"ghooks": "2.0.0",
"imports-loader": "0.7.0",
"json-loader": "0.5.4",
"karma": "1.3.0",
"karma": "1.4.0",
"karma-coverage": "1.1.1",
"karma-mocha": "1.3.0",
"karma-mocha-reporter": "2.2.1",
"karma-phantomjs-launcher": "1.0.2",
"karma-sauce-launcher": "1.1.0",
"karma-sinon-chai": "1.2.4",
"karma-sourcemap-loader": "0.3.7",
"karma-webpack": "1.8.1",
"karma-webpack": "2.0.1",
"leakage": "0.2.0",
"mkdirp": "0.5.1",
"mocha": "3.2.0",
"np": "2.12.0",
"npm-run-all": "4.0.0",
"npm-run-all": "4.0.1",
"nsp": "2.6.2",
"nyc": "10.0.0",
"nyc": "10.1.2",
"phantomjs-prebuilt": "2.1.14",
"rimraf": "2.5.4",
"rollup": "0.40.0",
"rollup": "0.41.4",
"rollup-plugin-babel": "2.7.1",
"rollup-plugin-cleanup": "0.1.4",
"rollup-plugin-cleanup": "1.0.0",
"rollup-plugin-conditional": "0.1.4",
"rollup-plugin-filesize": "1.0.1",
"rollup-watch": "3.1.0",
"rollup-watch": "3.2.2",
"semver": "5.3.0",
"sinon": "1.17.7",
"sinon-chai": "2.8.0",
Expand Down
23 changes: 19 additions & 4 deletions test/benchmark/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,37 @@ const WeLogger = require('../..');
var suite = new Benchmark.Suite();

const weLogger = new WeLogger({ stdout: false });
const weLoggerScrub = new WeLogger({ stdout: false, scrubFields: ['foo'] });
const bunyanLogger = bunyan.createLogger({ name: 'bunyan', streams: [] });

const context = {
data: { some: 'stuff' },
foo: 'bar'
};
const msg = 'hello world';
const msgExtra = { pretty: 'print me please' };

suite
.add('we-js-logger', function() {
weLogger.info('hello world')
weLogger.info(context, msg, msgExtra);
})
.add('we-js-logger child', function() {
const log = weLogger.child();
log.info('hello world');
log.info(context, msg, msgExtra);
})
.add('we-js-logger (with scrub fields)', function() {
weLoggerScrub.info(context, msg, msgExtra)
})
.add('we-js-logger child (with scrub fields)', function() {
const log = weLoggerScrub.child();
log.info(context, msg, msgExtra);
})
.add('bunyan', function() {
bunyanLogger.info('hello world');
bunyanLogger.info(context, msg, msgExtra);
})
.add('bunyan child', function() {
const log = bunyanLogger.child();
log.info('hello world');
log.info(context, msg, msgExtra);
})
// add listeners
.on('cycle', function(event) {
Expand Down
4 changes: 2 additions & 2 deletions test/browser.index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ global.Rollbar = {
log: _.noop
};

// require all `/test/specs/**/*.js`
const testsContext = require.context('./specs/common', true, /\.js$/);
// require all `/test/specs/**/*.spec.js`
const testsContext = require.context('./specs', true, /\.spec\.js$/);
testsContext.keys().forEach(testsContext);
2 changes: 1 addition & 1 deletion test/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = function(config) {
basePath: '../',
autoWatch: true,
singleRun: true,
frameworks: ['mocha'],
frameworks: ['mocha', 'sinon-chai'],
sauceLabs: {
testName: 'we-js-logger/client'
},
Expand Down
8 changes: 8 additions & 0 deletions test/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ require('babel-polyfill');
const chai = require('chai');
const sinon = require('sinon');

// NODE only
// TODO better way to guard this
// For browser tests, sinon-chai is loaded in karma config
if (typeof document === 'undefined') {
const sinonChai = require('sinon-chai');
chai.use(sinonChai);
}

global.expect = chai.expect;
global.should = chai.should;
global.assert = chai.assert;
Expand Down
27 changes: 0 additions & 27 deletions test/specs/leakage/logger.spec.js

This file was deleted.

62 changes: 31 additions & 31 deletions test/specs/common/logger.spec.js → test/specs/logger.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Require the package. For client tests, webpack should
// resolve to the browser version automatically.
import Logger from '../../../';
import TestLogger from '../../testLogger';
import Logger from '../..';
import TestLogger from '../testLogger';

// Logentries validates the token it is passed,
// here is a fake one in an acceptable format
Expand All @@ -18,7 +18,7 @@ describe('we-js-logger', () => {
const name = 'WeTest!';
const log = new Logger({ name });

expect(log.fields.name).to.equal(name);
expect(log._logger.fields.name).to.equal(name);
});

it('accepts custom streams', () => {
Expand All @@ -37,11 +37,11 @@ describe('we-js-logger', () => {
]
});

expect(log.streams.filter((config) => {
expect(log._logger.streams.filter((config) => {
return config.stream instanceof TestLogger;
}), 'Adds the custom stream').to.be.ok;

expect(log.streams).to.have.length.gte(1, 'Has more than one stream');
expect(log._logger.streams).to.have.length.gte(1, 'Has more than one stream');

log.debug({ foo: 'bar' }, msg);
expect(cb.lastCall.args[0]).to.include({
Expand All @@ -54,15 +54,15 @@ describe('we-js-logger', () => {
});

it('accepts a stdout flag', () => {
expect(new Logger({ stdout: false }).streams).to.have.length(0);
expect(new Logger({ stdout: false })._logger.streams).to.have.length(0);

// The actual stdout stream differs based on runtime env, just
// asserting is is there.
expect(new Logger({ stdout: true }).streams).to.have.length(1);
expect(new Logger({ stdout: true })._logger.streams).to.have.length(1);
});

it('accepts a logentriesToken', () => {
expect(new Logger().streams.find((config) => {
expect(new Logger()._logger.streams.find((config) => {
return config.name === 'logentries';
})).to.not.be.ok;

Expand All @@ -72,13 +72,13 @@ describe('we-js-logger', () => {

// The actual logentries stream differs based on runtime env, just
// asserting one is there
expect(log.streams.find((config) => {
expect(log._logger.streams.find((config) => {
return config.name === 'logentries';
})).to.be.ok;
});

it('accepts a rollbarToken', () => {
expect(new Logger().streams.find((config) => {
expect(new Logger()._logger.streams.find((config) => {
return config.name === 'rollbar';
})).to.not.be.ok;

Expand All @@ -88,7 +88,7 @@ describe('we-js-logger', () => {

// The actual rollbar stream differs based on runtime env, just
// asserting one is there
expect(log.streams.find((config) => {
expect(log._logger.streams.find((config) => {
return config.name === 'rollbar';
})).to.be.ok;
});
Expand All @@ -108,41 +108,41 @@ describe('we-js-logger', () => {
'scrubMe',
],
});
log._emit = sinon.stub();
log._logger._emit = sinon.stub();
});

it('hides secrets for fields', () => {
log.info({ scrubMe: 'This should be ignored', tlc: 'No Scrubs' });
expect(log._emit).to.have.been.calledOnce;
expect(log._emit.firstCall.args[0].scrubMe).to.equal('[SECRET]');
expect(log._emit.firstCall.args[0].tlc).to.equal('No Scrubs');
expect(log._logger._emit).to.have.been.calledOnce;
expect(log._logger._emit.firstCall.args[0].scrubMe).to.equal('[SECRET]');
expect(log._logger._emit.firstCall.args[0].tlc).to.equal('No Scrubs');
});

it('hides secrets for msg', () => {
log.info('Testing Log', { scrubMe: 'This should be ignored', tlc: 'No Scrubs' });
expect(log._emit).to.have.been.calledOnce;
expect(log._emit.firstCall.args[0].msg).to.equal("Testing Log { scrubMe: '[SECRET]', tlc: 'No Scrubs' }");
expect(log._logger._emit).to.have.been.calledOnce;
expect(log._logger._emit.firstCall.args[0].msg).to.equal("Testing Log { scrubMe: '[SECRET]', tlc: 'No Scrubs' }");
});

describe('child log', () => {
let childLog;

beforeEach(() => {
childLog = log.child({ component: 'child/test' });
childLog._emit = sinon.stub();
childLog._logger._emit = sinon.stub();
});

it('hides secrets for fields', () => {
childLog.info({ scrubMe: 'This should be ignored', tlc: 'No Scrubs' });
expect(childLog._emit).to.have.been.calledOnce;
expect(childLog._emit.firstCall.args[0].scrubMe).to.equal('[SECRET]');
expect(childLog._emit.firstCall.args[0].tlc).to.equal('No Scrubs');
expect(childLog._logger._emit).to.have.been.calledOnce;
expect(childLog._logger._emit.firstCall.args[0].scrubMe).to.equal('[SECRET]');
expect(childLog._logger._emit.firstCall.args[0].tlc).to.equal('No Scrubs');
});

it('hides secrets for msg', () => {
childLog.info('Testing Log', { scrubMe: 'This should be ignored', tlc: 'No Scrubs' });
expect(childLog._emit).to.have.been.calledOnce;
expect(childLog._emit.firstCall.args[0].msg).to.equal("Testing Log { scrubMe: '[SECRET]', tlc: 'No Scrubs' }");
expect(childLog._logger._emit).to.have.been.calledOnce;
expect(childLog._logger._emit.firstCall.args[0].msg).to.equal("Testing Log { scrubMe: '[SECRET]', tlc: 'No Scrubs' }");
});
});
});
Expand All @@ -159,15 +159,15 @@ describe('we-js-logger', () => {

describe('root fields', () => {
it('has extra root fields "release" and "environment" by default', () => {
expect(log.fields).to.have.property('release');
expect(log.fields).to.have.property('environment');
expect(log._logger.fields).to.have.property('release');
expect(log._logger.fields).to.have.property('environment');
});

it('does not have extra root fields, such as "rollbarToken"', () => {
expect(log.fields).not.to.have.property('rollbarToken');
expect(log.fields).not.to.have.property('logentriesToken');
expect(log.fields).not.to.have.property('scrubFields');
expect(log.fields).not.to.have.property('stdout');
expect(log._logger.fields).not.to.have.property('rollbarToken');
expect(log._logger.fields).not.to.have.property('logentriesToken');
expect(log._logger.fields).not.to.have.property('scrubFields');
expect(log._logger.fields).not.to.have.property('stdout');
});

it('can be configured to include any keys', () => {
Expand All @@ -176,8 +176,8 @@ describe('we-js-logger', () => {
badIdea: 'supersecret',
release: { foo: 'not gonna be included unless specified in rootFields' }
})
expect(customLog.fields).to.have.property('badIdea');
expect(customLog.fields).not.to.have.property('release');
expect(customLog._logger.fields).to.have.property('badIdea');
expect(customLog._logger.fields).not.to.have.property('release');
});
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Logger from '../../../';
import TestLogger from '../../testLogger';
import Logger from '../..';
import TestLogger from '../testLogger';

import createRequestLogger from '../../../src/util/server/requestLogger';
import createRequestLogger from '../../src/util/server/requestLogger';

// Only run these tests in node
// FIXME find a better way to do this. Should we use `env-universal`?
Expand Down Expand Up @@ -66,6 +66,7 @@ if (typeof document === 'undefined') {

it('logs a start request item', () => {
middleware(req, res, next);

expect(cb.firstCall.args[0]).to.include({
msg: 'start request'
});
Expand Down Expand Up @@ -124,9 +125,9 @@ if (typeof document === 'undefined') {
res.on = sinon.stub();
middleware(req, res, next);

expect(req.log.fields.component).to.eql('request');
expect(req.log.fields.req).to.eql(req);
expect(req.log.fields.req_id).to.eql(testReqId);
expect(req.log._logger.fields.component).to.eql('request');
expect(req.log._logger.fields.req).to.eql(req);
expect(req.log._logger.fields.req_id).to.eql(testReqId);
});

it('clears `req.log` after the response is finished', () => {
Expand Down

0 comments on commit 98cdea5

Please sign in to comment.