-
Notifications
You must be signed in to change notification settings - Fork 83
fix(test): Suppress logs when NODE_ENV=test #147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This is ready for review, please. |
optimizelyFactory.createInstance({ | ||
datafile: {}, | ||
context('a logger was supplied', function() { | ||
it('an error message is submitted to the supplied logger', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I would make the message something like "submits an error message to the supplied logger" so it reads better in combination with the context
.
@@ -78,6 +78,15 @@ Logger.prototype.setLogLevel = function(logLevel) { | |||
* @private | |||
*/ | |||
Logger.prototype.__shouldLog = function(targetLogLevel) { | |||
try { | |||
if (process.env.NODE_ENV === 'test') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Could we not just configure the test to set the logLevel
to enums.LOG_LEVEL.ERROR + 1
(or some other really high value)? Then you wouldn't have to mess with the env in the logger test.
Obsolete |
Summary
console
isn't logged to during unit testscreateInstance
tests.lib/optimizely > constructor
tests. When viewing the diff in GitHub, try the 'Hide whitespace changes' option to make this diff clearer.npm test
definition. The bug here before was a lack of 'single quotes' around the glob pattern, which prevent glob expansion by bash (the interpreter of npm run-scripts).*.swp
(vim temporary files) to gitignoreThe status quo is noise like this. Now,
With the noise removed, deprecation warnings from Sinon are now clearly visible. Hooray!
Initially I wanted to avoid putting the
NODE_ENV
stuff inside the logger module, instead trying to stublogger.createInstance
in the appropriate places in the tests. Down this path, I discovered that one issue was that, though the logger in most (all?) tests is properly stubbed, theoptlyInstance
is often constructed before thecreatedLogger.log
method is stubbed (example), which yields the symptom of lots of log messages likemaking it through before the stub. (See how many of these are in the example build link above.)
I tried moving the
optlyInstance
construction aftercreatedLogger.log
was stubbed, but that caused all of the many assertions like this one to start to fail. This was kind of a bummer and I'm not sure how much value asserting exact text of log messages adds, so at this point I pivoted to theNODE_ENV
approach.Test plan
In the master branch, there are 371 tests. In this branch, 372. That's from the
createInstance
refactor, which net created 1 new test: