Skip to content

Commit cf340cf

Browse files
committed
Failing tests if there are any unsilenced logs
1 parent 2658151 commit cf340cf

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/logger.js

+7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const defaultConfig = {
2323
};
2424

2525
let messages = {};
26+
let unsilencedLogs = [];
2627
let config = {};
2728

2829
const reset = function() {
@@ -31,6 +32,7 @@ const reset = function() {
3132
messages[messageKey] = [];
3233
}
3334
config = Object.assign({}, defaultConfig);
35+
unsilencedLogs = [];
3436
};
3537
reset();
3638

@@ -40,6 +42,7 @@ function log(message) {
4042
}
4143

4244
console.log(message);
45+
unsilencedLogs.push(message);
4346
}
4447

4548
module.exports = {
@@ -73,6 +76,10 @@ module.exports = {
7376
return messages;
7477
},
7578

79+
getUnsilencedLogs() {
80+
return unsilencedLogs;
81+
},
82+
7683
quiet(setQuiet = true) {
7784
config.quiet = setQuiet;
7885
},

test/_unsilencedLogsCheck.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* This file is part of the Symfony Webpack Encore package.
3+
*
4+
* (c) Fabien Potencier <fabien@symfony.com>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
'use strict';
11+
12+
const logger = require('../lib/logger');
13+
14+
afterEach(function() {
15+
const unsilencedLogs = logger.getUnsilencedLogs();
16+
17+
if (unsilencedLogs.length > 0) {
18+
this.test.error(new Error(`There were ${unsilencedLogs.length} un-silenced logs messages`));
19+
}
20+
});

0 commit comments

Comments
 (0)