File tree Expand file tree Collapse file tree 3 files changed +21
-1
lines changed Expand file tree Collapse file tree 3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,15 @@ Logger.prototype.setLogLevel = function(logLevel) {
78
78
* @private
79
79
*/
80
80
Logger . prototype . __shouldLog = function ( targetLogLevel ) {
81
+ try {
82
+ if ( process . env . NODE_ENV === 'test' ) {
83
+ // Suppress logs during testing.
84
+ return false ;
85
+ }
86
+ } catch ( e ) {
87
+ // `process` is likely a ReferenceError in non-Node.js environments
88
+ }
89
+
81
90
return targetLogLevel >= this . logLevel ;
82
91
} ;
83
92
Original file line number Diff line number Diff line change @@ -33,9 +33,20 @@ describe('lib/plugins/logger', function() {
33
33
} ) ;
34
34
35
35
describe ( 'log' , function ( ) {
36
+ var nodeEnv ;
37
+
36
38
beforeEach ( function ( ) {
37
39
defaultLogger = logger . createLogger ( { logLevel : LOG_LEVEL . INFO } ) ;
38
40
sinon . stub ( defaultLogger , '__consoleLog' ) ;
41
+
42
+ // The usual rules of turning off logging don't apply here,
43
+ // since the code under test _is the logger_.
44
+ nodeEnv = process . env . NODE_ENV ;
45
+ process . env . NODE_ENV = 'production' ;
46
+ } ) ;
47
+
48
+ afterEach ( function ( ) {
49
+ process . env . NODE_ENV = nodeEnv ;
39
50
} ) ;
40
51
41
52
it ( 'should log the given message' , function ( ) {
Original file line number Diff line number Diff line change 5
5
"main" : " lib/index.node.js" ,
6
6
"browser" : " lib/index.browser.js" ,
7
7
"scripts" : {
8
- "test" : " mocha ./lib/*.tests.js ./lib/**/*.tests.js ./lib/**/**/*tests.js --recursive " ,
8
+ "test" : " NODE_ENV=test mocha --reporter dot ' ./lib/**/*.tests.js' " ,
9
9
"test-xbrowser" : " karma start karma.bs.conf.js --single-run" ,
10
10
"lint" : " eslint lib/**" ,
11
11
"cover" : " istanbul cover _mocha ./lib/*.tests.js ./lib/**/*.tests.js ./lib/**/**/*tests.js" ,
You can’t perform that action at this time.
0 commit comments