Skip to content

Commit

Permalink
Failing tests if there are any unsilenced logs
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverryan committed May 9, 2020
1 parent 2658151 commit cf340cf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const defaultConfig = {
};

let messages = {};
let unsilencedLogs = [];
let config = {};

const reset = function() {
Expand All @@ -31,6 +32,7 @@ const reset = function() {
messages[messageKey] = [];
}
config = Object.assign({}, defaultConfig);
unsilencedLogs = [];
};
reset();

Expand All @@ -40,6 +42,7 @@ function log(message) {
}

console.log(message);
unsilencedLogs.push(message);
}

module.exports = {
Expand Down Expand Up @@ -73,6 +76,10 @@ module.exports = {
return messages;
},

getUnsilencedLogs() {
return unsilencedLogs;
},

quiet(setQuiet = true) {
config.quiet = setQuiet;
},
Expand Down
20 changes: 20 additions & 0 deletions test/_unsilencedLogsCheck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* This file is part of the Symfony Webpack Encore package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

'use strict';

const logger = require('../lib/logger');

afterEach(function() {
const unsilencedLogs = logger.getUnsilencedLogs();

if (unsilencedLogs.length > 0) {
this.test.error(new Error(`There were ${unsilencedLogs.length} un-silenced logs messages`));
}
});

0 comments on commit cf340cf

Please sign in to comment.